Pick someone new to be the driver this week. If everyone in the group has already had a week as the driver, start going round again!
The driver will type the code. The rest of you are navigators, you need to tell the driver where to go (i.e., what to type!).
Driver instructions:
Log in to the bigger screen at your table
Open RStudio Server. See the first drop-down in the FAQs page for instructions
Open a new .R script, and load the tidyverse package.
Listen to your navigators
Navigator instructions:
Tell your driver where to go (i.e., what to type)!
Question 1
This week, we’re going to bring together many of the ideas we covered over the last few weeks and go step-by-step through the process of performing a null hypothesis significance test (NHST).
We start with a research question:
Research Question: Are first year undergraduate students more optimistic than adults in general? Operationalisation: We surveyed students on a first year undergraduate statistics course (that’s you!), and asked them to indicate their level of pessimism/optimism on a sliding scale from -100 (pessimist) to +100 (optimist). Previous research using this measure suggests that the overall adult population has an average score of 15 and standard deviation of 25. Data:https://uoepsy.github.io/data/dapr1_2627_survey.csv
Define the null and alternative hypotheses. (Check the lecture slides for guidance!)
The symbol \(\mu\) will denote the mean optimism score of all adults (i.e. the population mean).
We are testing the two competing hypotheses:
\[H_0: \mu = 15\]
\[H_1: \mu > 15\]
Question 2
In future, we’re going to learn and use functions in R that do all the steps of NHST for us. But for this week we’re going to break down the process, so you can see every step. That means we’re going to need a few pieces of information.
We’re going to need:
the size of our sample (that is, how many observations we have in our dataset), \(n\)
the mean outlook score that we observe in our sample, \(M\)
the hypothesised value that we are comparing our sample mean to, \(\mu\)
how much we expect samples of the same size as ours to vary
Figure out each of these values.
TipHints
You’ll need to read in the data using read_csv() first.
“How much we expect samples of the same size as ours to vary” is the standard error, as you saw last week. The formula is \(\frac{\sigma}{\sqrt{n}}\) (or \(\frac{s}{\sqrt{n}}\) if the population standard deviation is unknown). In this case, we are told that the population standard deviation is 25, so \(\sigma = 25\). And \(n\) is the quantity you work out in (a).
library(tidyverse)sdata <-read_csv("https://uoepsy.github.io/data/dapr1_2627_survey.csv")# the size of our sample (that is, how many observations we have in our dataset)n <-nrow(sdata)n
[1] 134
# the mean outlook score that we observe in our samplexbar <-mean(sdata$outlook)xbar
[1] 21.828
# the hypothesised value that we are comparing our sample mean tomu <-15# how much we expect samples of the same size as ours to vary (i.e., the standard error)sigma <-25SE <- sigma /sqrt(n)SE
[1] 2.1597
Question 3
We use all the information from the previous question allow us to build up a picture of “what would sample means be like if the null hypothesis \(H_0\) were true”.
Based on that picture, we can calculate the probability of seeing a sample mean at least as extreme as the one we have seen, if the null hypothesis were true.
Here’s a visual way of thinking about the key parts of NHST:
Figure 1: Null hypothesis significance testing in a nutshell. SE stands for ‘standard error’.
Our goal for the next two questions is to figure out exactly how much area is in those shaded red regions in the tails of our distribution.
To do this, first we’ll need to convert our mean into a “test statistic”, which measures the distance between our sample mean and the hypothesised population mean in terms of how much we expect sample means to vary.
In this case, the test statistic is the z-score or z-statistic, because we’re comparing our observed mean to the distribution of means from all the possible samples we could have taken.
Using the formula below and the values you figured out above, calculate Z.
\[
Z = \frac{M - \mu}{SE}
\]
zstat <- (xbar - mu) / SEzstat
[1] 3.1618
Question 4
Now that we have our test statistic, we can calculate the corresponding “p-value”.
A p-value is the probability of seeing a sample mean at least as extreme as the one we have seen, if the null hypothesis were true. It corresponds to one, or both, of the shaded red areas in Figure 1, depending on how we phrased \(H_1\). (See the Hint below for more detail on this!)
Z-statistics are follow a normal distribution with a mean of 0 and standard deviation of 1, which is called the “standard normal distribution”. To work out the area of the standard normal distribution that’s on the appropriate side of our z-statistic, we can use our old friend pnorm().
Using pnorm(), figure out how much of the area under the standard normal distribution is beyond your z-statistic, in the direction corresponding to your \(H_1\).
TipHint
The direction of the area you’ll need to find is always the same as the direction of \(H_1\):
If \(H_1\) includes the > (“greater than”) symbol, then you need to find the area to the right of your z-statistic.
If \(H_1\) includes the < (“less than”) symbol, then you need to find the area to the left of your z-statistic.
If \(H_1\) is two-sided, then you need to find the area on the side that the z-statistic is closest to (e.g., if your z-statistic is positive, find the area to the right), and then double that value to account for both tails of the distribution.
As our \(H_1\) states that \(\mu > 15\), we need to find the area to the right of our z-statistic.
By default, pnorm() will give us the area to the left. So to get the opposite of that, we subtract the outcome of pnorm() from 1.
1-pnorm(zstat)
[1] 0.0007841
The probability of observing a z-statistic like ours or even more positive, assuming the true population mean were 15, is .000784, or 0.07841%. Very unlikely!
Question 5
Do your best to fill in the blanks in the APA-style report below:
Let \(\mu\) denote the (1)__________. At the 5% significance level, we performed a one sample z-test of (2)____ against (3)____. The sample mean (4)__________ (M = (5)____, SD = (6)____) was (7)__________ (z = (8)____, p (9)____, (10)____).
Check the lecture slides for guidance, and ask a tutor if you’re unsure!
mean optimism score of all adults
\(H_0: \mu = 15\) (in your R script, you can write H0: mu = 15)
\(H_1: \mu > 15\) (in your R script, you can write H1: mu > 15)
optimism score of first year undergraduate students
21.83
45.86
significantly higher than the mean optimism score of all adults
3.16
< .001
one-sided
Here’s the whole thing:
Let \(\mu\) denote the mean optimism score of all adults. At the 5% significance level, we performed a one sample z-test of \(H_0: \mu = 15\) against \(H_1: \mu > 15\). The sample mean optimism score of first year undergraduate students (M = 21.83, SD = 45.86) was significantly higher than the mean optimism score of all adults (z = 3.16, p < .001, one-sided).
Finishing up
Once you’ve finished, don’t forget to:
Save your R script
Post the R script to the group discussion space on Learn, to ensure that everyone has access to it! (For step-by-step instructions on how to do this, click here)