library(tidyverse)
sdata <- read_csv('https://uoepsy.github.io/data/dapr1_2627_survey.csv')W11: One-Sample T-Test
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)!
Last week, you tested whether the average optimism score among DAPR1 students is greater than the general population average. You conducted a z-test to show that, yes, DAPR1 students are significantly more optimistic than the general population!
However, we don’t know the true population values for every variable, so we can’t always run z-tests. In real research settings, where we don’t know any of this information about the population, the kind of test we run is t-tests.
This week, you’re going to run some t-tests using t.test()! The cool thing about t-tests is that (unlike z-tests) you don’t need to know any information about the population at all.
This week, we’re going to look at the ampm variable, which ranges from 0 (total evening person) to 10 (total morning person). Here’s what that question in the survey looked like.

Our RQ is going to be: Do first year undergraduate students identify more as morning people or as evening people?
Read in the DAPR1 survey data from https://uoepsy.github.io/data/dapr1_2627_survey.csv.
- In a one-sample t-test, we compare our sample to a specific value. Based on the RQ and the information above, identify the value that we want to compare our sample to.
- Based on the RQ, decide whether your alternative hypothesis \(H_1\) will be one-sided or two-sided.
- Then, using the value you identified above, specify the null and alternative hypotheses to address the research question.
What value between 0 and 10 distinguishes evening people from morning people?
In other words, what value is the halfway point between someone being an evening person and someone being a morning person?
🗂️ See the One-sample t-test > Define hypotheses flash card.
Suppose that we have this research question because the University wants to know when is best to timetable lectures, workshops, tutorials etc.
Write down:
- What would be a Type I error in this scenario? What consequences might it have?
- What would be a Type II error? What consequences might it have?
Create a visualisation that presents the data in a way that is relevant to the research question.
There are lots of different ways you could do this—the choice is yours! Have some fun with it. Change colours, tidy up axis labels, etc.
🗂️ See the Plot a variable flash card.
Using a 5% significance level, perform a t.test() to test the hypotheses you specified above.
🗂️ See the One-sample t-test > Run the test flash card.
Write it up!
To help, here’s the example write-up from the lecture:
To investigate whether \(\mu\), the mean body temperature of healthy humans, differs from the commonly thought value of 37°C, we performed a one-sample t-test of \(H_0 : \mu = 37\) against \(H_1 : \mu \neq 37\) at the 5% significance level.
The sample results (M = 36.81, SD = 0.43) provide evidence against the null hypothesis (\(t\)(49) = –3.14, \(p\) = .003, two-sided). We therefore conclude that the mean body temperature of healthy humans differs from 37°C and, with 95% confidence, is between 36.69°C and 36.93°C.
Here’s how this same report might be written up in plain text in your R script:
# To investigate whether mu, the mean body temperature of healthy humans,
# differs from the commonly thought value of 37C, we performed a one-sample
# t-test of H0: mu = 37 against H1: mu != 37 at the 5% significance level.
# The sample results (M = 36.81, SD = 0.43) provide evidence against the null
# hypothesis (t(49) = –3.14, p = .003, two-sided). We therefore conclude that
# the mean body temperature of healthy humans differs from 37C and, with 95%
# confidence, is between 36.69C and 36.93C.
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)

