Data Analysis for Psychology in R 1 (2026/27)
Psychology, PPLS
University of Edinburgh
What is the basic logic behind Null Hypothesis Significance Testing (NHST)?
What are the five steps of doing NHST?
What kinds of errors is it possible to make when doing NHST?
Standard IQ tests assume that in the general population,
So, the distribution of IQ scores in the population looks like this:
You get data from one bilingual person, and their IQ is 105.
Imagine you’re drawing samples from the population distribution.
Vote by show of thumbs: How likely do you think it would be to sample IQ = 105 from this distribution?
= very likely
= very unlikely
Now you get data from another bilingual person, and their IQ is 120.
Vote by show of thumbs: How likely do you think it would be to sample IQ = 120 from this distribution?
= very likely
= very unlikely
Now you get data from a third bilingual person, and their IQ is 155.
Vote by show of thumbs: How likely do you think it would be to sample IQ = 155 from this distribution?
= very likely
= very unlikely
If our observations from bilingual people are likely to come from the population distribution, then we might hypothesise that it’s likely for bilingual people to have the same IQ as the general population.
If our observations from bilingual people are unlikely to come from the population distribution, then we might hypothesise that it’s unlikely for bilingual people to have the same IQ as the general population.
These hypotheses are so important that statisticians have given them specific names.
The null hypothesis (H0) is always that any difference or effect we’re interested in does not exist.
\[ H_0 : \mu = 100 \]
H0: mu = 100
The alternative hypothesis (H1) is that the difference or effect we’re interested in does exist.
\[ H_1 : \mu > 100 \]
H1: mu > 100
In NHST, our goal is to find out how likely it is that we are in a world where the null hypothesis is true.
To do that, we must work out what samples like ours WOULD look like IF the null hypothesis were true.
So first: What does our sample actually look like?
For this test, the most useful information about our sample is its mean.
We want to see what sample means would be likely if bilingual people have the same IQ as the population.
To do this, we can either:
do simulation, if we have access to the population:
OR
do math (useful for the future when we don’t have access to the population!):
Why do we want to find the distribution of the sample means we would expect if H0 were true?
So that we can compare our observed sample mean to it and see how different our observation is from what we would get if H0 were true.
There is a name for the distribution that sample means would have if the null hypothesis were true. It is called the “null distribution”, and sometimes also called the “comparison distribution”.
For this kind of analysis, the null distribution has the following properties:
mean = the population mean = the mean in our H0 = 100
SD = the standard error of the mean = the standard deviation of the sampling distribution of means = \(\frac{\sigma}{\sqrt{n}}\)
We know the population SD \(\sigma\) is 15, and we know we have a sample size \(n\) of 100. So:
\[ \begin{align} \text{SD} &= \frac{15}{\sqrt{100}} \\[.5em] &= \frac{15}{10} \\[.5em] &= 1.5 \end{align} \]
Because it shows us how sample means would be distributed if the H0 were true.
And we can compare our observed sample mean to this distribution.
If our sample is unlikely enough to have come from the null distribution, then we say we are unlikely enough to be in a world where the H0 is true, and we can reject the H0.
So what’s “unlikely enough”?
In Psychology, we usually want data like ours to have a less than 5% chance of coming from the null distribution.
What sample means have a less than 5% chance of coming from the null distribution?
For our one-tailed, directional H1:
For a two-tailed, non-directional H1:
This means that one time out of twenty, we’ll be rejecting the H0 when actually we shouldn’t.
One in twenty is the level of risk we’re willing to accept.
This is another idea that’s so important that it has a specific name:
A 5% probability of incorrectly rejecting H0 = our significance level or alpha level, also written \(\alpha\) = .05.
Our sample mean is sufficiently unlikely, assuming the H0 is true!
We can tell because it’s in the most extreme 5% (where “extreme” is in the direction of our H1).
But how unlikely exactly?
To figure this out, we’ll do what’s called a z-test. In a z-test, we compare our sample mean’s z-score to the standard normal distribution using pnorm(). This test tells us the specific probability of seeing a sample mean like ours or one more extreme, assuming H0 is true.
The formula for a z-score in general:
\[ Z = \frac{x - M}{SD} \]
The formula when we’re getting the z-score of a sample mean:
\[ Z = \frac{\bar{x} - \mu}{\sigma / \sqrt{n}} \]
We know that \(\bar{x}\) = 102.83, \(\mu\) = 100, \(\sigma\) = 15, and \(n\) = 100, so:
\[ \begin{align} &= \frac{102.83 - 100}{15 / \sqrt{100}} \\[.5em] &= \frac{2.83}{1.5} \\[.5em] &= 1.89 \end{align} \]
Our p-value is .029, which means there’s a 3% chance of observing data like ours or more extreme, assuming the H0 is true. How cool is it that we can figure this out!
This p-value is below \(\alpha\) = .05, so:
If the p-value were NOT below \(\alpha\) = .05, then
With fancy formatting:
Let \(\mu\) denote the mean IQ score of bilingual people in the UK. At the 5% significance level, we performed a one-sample z-test of \(H_0 : \mu\) = 100 against \(H_1 : \mu\) > 100.
The sample mean IQ score of bilingual people (\(M\) = 102.83, \(SD\) = 18.67) was significantly higher than the national average (\(z\) = 1.89, \(p\) = .029, one-sided).
In plain text, like you might write in your R script:
Let mu denote the mean IQ score of bilingual people in the UK. At the 5% significance level, we performed a one-sample z-test of H0: mu = 100 against H1: mu > 100.
The sample mean IQ score of bilingual people (M = 102.83, SD = 18.67) was significantly higher than the national average (z = 1.89, p = .029, one-sided).
There are two possible states that the real world could be in:
Ideally, our decision about H0 would match this perfectly. But remember that there’s some risk involved in our statistical testing: 5% of the time, we will incorrectly reject H0 when we should actually fail to reject it.
Scenario: A court case
Scenario: Testing for COVID
What is the basic logic behind Null Hypothesis Significance Testing (NHST)?
What are the five steps of doing NHST?
What kinds of errors is it possible to make when doing NHST?
I think these are possibly the least useful names for any statistical concept that I know of.
Here’s how I remember which is which: using the story of the boy who cried wolf.
Part 1 of the story:
Type I error:
Part 2 of the story:
Type II error: