14  One-Sample t-Test

NoteWhat you’ll be able to do

By the end of this chapter you will be able to:

  1. Identify when a one-sample t-test is the appropriate choice.
  2. Run the test in R and read the output, including the 95% confidence interval.
  3. Compute and report Cohen’s d — regardless of whether the result is significant.
  4. Avoid inferring equivalence (“no effect”) from a non-significant result.

The coffee shop by campus claims its lattes contain 150 mg of caffeine on average. You buy 20 and measure them, and your sample mean comes out about 14 mg above the claim. Is the shop’s label wrong — or is that gap just the wobble you’d expect from 20 cups even if the claim were exactly true? Answering that question — one sample, one benchmark — is the job of the one-sample t-test.

A one-sample t-test compares the mean of a single sample to a known or hypothesized value. The “known value” is typically a benchmark — a national average, a manufacturer’s claim, a value predicted by theory.

This is the simplest of the three t-tests. The logic generalizes to the others.

14.1 When to use it

Use a one-sample t-test when you have:

  • One continuous outcome variable.
  • A specific value you want to test the mean against.
  • An interest in whether your sample’s mean differs from that value.

Examples:

  • Is the average IQ in this sample different from the population mean of 100?
  • Does the average reaction time in your study differ from the published benchmark of 250 ms?
  • Does the mean caffeine content of a coffee shop’s lattes match their claim of 150 mg?

If you want to compare two groups against each other, or the same people at two times, you need a different t-test (see Chapter 15 and Chapter 16).

14.2 Hypotheses

  • \(H_0\): The population mean equals the hypothesized value (\(\mu = \mu_0\)).
  • \(H_1\): The population mean differs from the hypothesized value (\(\mu \neq \mu_0\)).

The hypotheses are about the population. Your sample mean will almost never equal \(\mu_0\) exactly; the test asks whether the gap is bigger than sampling variability would produce if \(H_0\) were true.

For a one-tailed test, replace \(\neq\) with \(<\) or \(>\) as appropriate. Default to a two-tailed test unless you have a strong directional hypothesis specified in advance.

14.3 The test statistic

\[ t = \frac{\bar{x} - \mu_0}{s / \sqrt{n}} \]

where \(\bar{x}\) is the sample mean, \(\mu_0\) is the hypothesized value, \(s\) is the sample standard deviation, and \(n\) is the sample size. Degrees of freedom are \(n - 1\).

R does this calculation; you supply the data and the hypothesized value.

14.4 Assumptions

  1. Continuous outcome. The variable should be interval or ratio scale.
  2. Independence. Observations are independent of each other.
  3. Approximate normality. The variable should be roughly normally distributed in the population. With \(n > 30\) the Central Limit Theorem provides robustness; with smaller samples, normality matters more.

For the assumption check workflow, see Chapter 11.

TipTry It: Simulation First

Before running the formula, build intuition with the Rossman/Chance one-sample mean applet.

Predict first: if the null hypothesis is true and the population mean really equals the reference value, how often would you expect a sample mean as far from the null as yours? Run the simulation and compare your prediction to the p-value R produces.

14.5 R syntax

The core command is:

t.test(data$variable, mu = test_value)

mu is the hypothesized population mean. By default R runs a two-tailed test; for one-tailed, add alternative = "greater" or alternative = "less".

14.5.1 Worked example

A coffee shop claims their lattes contain 150 mg of caffeine on average. You measure 20 lattes and want to test whether the actual mean differs from 150.

# Step 0: Load the data
latte_data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/ch14_lattes.csv")

# Step 1: Inspect the data
str(latte_data)
summary(latte_data$caffeine_mg)

# Step 2: Check normality
hist(latte_data$caffeine_mg)
qqnorm(latte_data$caffeine_mg); qqline(latte_data$caffeine_mg, col = "red")
shapiro.test(latte_data$caffeine_mg)

# Step 3: Run the test
t.test(latte_data$caffeine_mg, mu = 150)

14.5.2 Reading the output

R prints:


    One Sample t-test

data:  latte_data$caffeine_mg
t = 2.5344, df = 19, p-value = 0.02022
alternative hypothesis: true mean is not equal to 150
95 percent confidence interval:
 152.4119 175.2881
sample estimates:
mean of x 
   163.85 

The pieces:

  • t = 2.5344 — the test statistic.
  • df = 19 — degrees of freedom (\(n - 1\)).
  • p-value = 0.02022 — probability of seeing a statistic at least this extreme if \(H_0\) were true. Less than 0.05, so we reject \(H_0\).
  • 95 percent confidence interval: 152.41 to 175.29 — plausible range for the true mean. Does not include 150, consistent with the rejection.
  • mean of x: 163.85 — your observed sample mean.
ImportantCommon Misconception: significant p means large difference

p < .05 tells you the data would be unusual if the population mean were exactly the hypothesized value — not how far the true mean is from that value in meaningful terms. Two studies can both produce p < .05 with very different effect sizes. Statistical significance is not a measure of magnitude; that is what Cohen’s d is for.

NoteInterpret the Output

Read this output carefully. The R code that produced it is not shown.


    One Sample t-test

data:  commute_time
t = -2.7144, df = 34, p-value = 0.01035
alternative hypothesis: true mean is not equal to 45
95 percent confidence interval:
 36.50638 43.77934
sample estimates:
mean of x 
 40.14286 
  1. What is the name of the test that was run?
  2. What hypothesized value is the sample mean being compared to?
  3. What is the sample mean? Is it above or below the hypothesized value?
  4. Is the result statistically significant at α = .05? How do you know from the output?
  5. Interpret the 95% confidence interval [36.51, 43.78] in plain language.
  6. Write one APA 7 sentence reporting this result. Cohen’s d = −0.46.
  7. Name one limitation of this result that is not visible in the output.

14.6 Effect size: Cohen’s d

A significant t-test tells you the data are hard to reconcile with the hypothesized value. It doesn’t tell you how different the mean is in practically meaningful terms. For that, compute Cohen’s d:

\[ d = \frac{\bar{x} - \mu_0}{s} \]

R syntax:

# One-sample Cohen's d = (mean - reference value) / SD.
# (effsize::cohen.d has no one-sample mode, so compute it directly.)
d <- (mean(latte_data$caffeine_mg, na.rm = TRUE) - 150) /
      sd(latte_data$caffeine_mg, na.rm = TRUE)
d

Interpretation:

Cohen’s d Effect size
0.2 Small
0.5 Medium
0.8 Large

These are rough conventions, not hard rules. A “small” effect in clinical research can be meaningful; a “large” effect in a high-noise behavioral context can still be unstable.

14.7 Reporting

APA-style write-ups include the test statistic with df, the p-value, sample mean and SD, and the effect size.

A one-sample t-test was conducted to compare the mean caffeine content of the shop’s lattes (M = 163.85 mg, SD = 24.44 mg) to the claimed value of 150 mg; the caffeine values showed no evidence of non-normality (Shapiro-Wilk p = .842). There was a significant difference, t(19) = 2.53, p = .020, Cohen’s d = 0.57 (medium effect), 95% CI [152.41, 175.29]. The lattes contained significantly more caffeine than claimed.

Conventions: italicize t, M, SD, p, d. Report p to three decimals; everything else to two. If \(p < .001\), write “\(p < .001\)” rather than the exact value.

14.7.1 If the result isn’t significant

Suppose the shop had claimed 160 mg instead. The same data give:

t.test(latte_data$caffeine_mg, mu = 160)
    One Sample t-test

data:  latte_data$caffeine_mg
t = 0.7045, df = 19, p-value = 0.4897
alternative hypothesis: true mean is not equal to 160
95 percent confidence interval:
 152.4119 175.2881
sample estimates:
mean of x 
   163.85 

The report keeps the same parts. The effect size goes in even though the result isn’t significant:

The mean caffeine content (M = 163.85 mg, SD = 24.44 mg) did not differ significantly from the claimed 160 mg, t(19) = 0.70, p = .490, Cohen’s d = 0.16, 95% CI [152.41, 175.29].

What this does not say is that the lattes contain 160 mg. A non-significant result means the data are compatible with the claim, not that the claim is true. The confidence interval shows how much is still compatible: anything from about 152 to 175 mg. With only 20 cups, the test had little power to detect a small difference (Chapter 5). “We found no evidence of a difference” is the honest sentence; “the claim is accurate” is not.

14.8 Common mistakes

Wrong Right
t.test(data$variable, data$mu) — passing two columns t.test(data$variable, mu = 150) — mu is a value, not a column
Comparing to a sample mean from another group Use a two-sample test instead
Skipping the normality check on small samples (\(n < 30\)) Look at the histogram and Q-Q plot; add shapiro.test() as a supplement (it has little power at small n)
Reporting just the p-value Report effect size and group descriptives too

14.9 Quick reference

Element R code
Run the test t.test(x, mu = value)
One-tailed (greater) t.test(x, mu = value, alternative = "greater")
Cohen’s d (mean(x) - mu) / sd(x)
Confidence interval Reported automatically in t.test() output
Descriptives mean(x); sd(x); length(x)
TipReporting checklist for a one-sample t-test

14.10 The same test, different disciplines

The one-sample t-test applies whenever you want to compare a sample mean to a known or theoretically motivated reference value.

Discipline Typical comparison Reference value
Psychology Sample mean on a standardized measure vs. published norm IQ = 100; standardized depression score at clinical threshold
Biology Sample organism trait vs. published species average or lab standard Mean enzyme activity vs. published reference; body mass vs. historical baseline
Sociology Survey sample mean vs. census benchmark or national average Mean reported income vs. census figure; attitude score vs. national poll baseline

Next up: comparing two independent groups.


TipChapter Summary

Core idea: The one-sample t-test asks whether your sample mean differs from a specific known value. It is the simplest hypothesis test, but it demonstrates the full inferential logic: observed result vs. what chance would produce.

You should understand:

  • When to use a one-sample t-test (you have a single group and a meaningful reference value)
  • What the null hypothesis is: H₀: μ = the reference value
  • Why you need a reference value from outside your data (not another group in your study)

You should be able to do in R:

  • Run the test: t.test(data$variable, mu = reference_value)
  • Compute Cohen’s d: (mean(x) - mu) / sd(x)
  • Check normality: shapiro.test(data$variable), hist(data$variable)

Plain-language check: A caffeine study compares 25 participants’ reaction times to a published norm of 250 ms and finds M = 262 ms, SD = 26 ms, t(24) = 2.31, p = .030, Cohen’s d = 0.46. Write one sentence reporting this result as you would in the results section of a paper.

The one mistake to avoid: Passing a column name as the mu argument: t.test(data$score, data$norm) — this runs a two-sample test, not a one-sample test. The reference value is a single number: t.test(data$score, mu = 250).

Practice: IQ is standardized to a population mean of 100. A sample of 30 psychology students has a mean IQ of 108 (SD = 12). Without running R: is this likely to be significant? Then check: compute \(t = (\bar{x} - \mu_0) / (s / \sqrt{n})\) by hand and compare it with the critical value from qt(0.975, df = 29). (t.test() needs the raw scores, which you don’t have here.)

Key terms from this chapter are defined in the Glossary.

Notet-Test Practice: In-Class Worksheet & Homework

Practice all three t-test types together: In-Class Worksheet — Dataset A and Homework — Dataset B.