One-sample t-test

Analytika TeamLast reviewed 6 min read

The one-sample t-test answers “is the average in my sample different from a particular value?”. It’s the simplest of the t-tests, and it’s useful whenever there’s a benchmark to compare against.

When to use it

  • Do students at one school score differently from the national average of 500?
  • Does the mean fill weight of a product meet the 250 g on the label?
  • Is average satisfaction above the scale midpoint of 3?
  • Is mean blood pressure in a sample different from a clinical reference value?

The test value must be fixed in advance: a known population value, a specification or a theoretical point. It can’t be another sample’s mean. Comparing with another group needs an independent or paired t-test.

Hypotheses and formula

  • H₀: μ = μ₀ (the population mean equals the test value).
  • H₁: μ ≠ μ₀.
t = (x̄ − μ₀) / (s / √n), with df = n − 1

Cohen’s d for a one-sample test is (x̄ − μ₀) / s: the distance from the test value in SD units.

Assumptions

  1. Independent observations.
  2. A continuous outcome.
  3. Approximately normal data. This matters most in small samples. With clear skew or outliers, use the one-sample Wilcoxon signed-rank test, which tests the median instead.

Worked example: is average fuel economy 20 mpg?

The 32 cars in R’s mtcars dataset have a mean fuel economy of 20.09 mpg (SD 6.03). Is that different from 20 mpg? Fuel economy passes Analytika’s normality check, so it chooses the one-sample t-test.

Analytika engine output
Sample (mpg): mean=20.0906, n=32, sd=6.0269
Test value: 20
Mean difference: 0.0906
Difference CI (95%): [-2.0823, 2.2636]
T-statistic: 0.0851
P-value: 0.9328
Cohen's d: 0.0150
df: 31
95% CI: [-0.3316, 0.3614]
Rows excluded for missing values: 0 of 32
R 4.6 output
> t.test(mtcars$mpg, mu = 20)

	One Sample t-test

data:  mtcars$mpg
t = 0.08506, df = 31, p-value = 0.9328
alternative hypothesis: true mean is not equal to 20
95 percent confidence interval:
 17.91768 22.26357
sample estimates:
mean of x
 20.09062

The results match. R gives the confidence interval for the mean (17.92 to 22.26), and Analytika gives it for the difference from 20 (−2.08 to 2.26), which is the same interval shifted by 20. Analytika’s test suite checks this case against R on every change.

Interpretation

  • t(31) = 0.09, p = .933: no evidence that the average fuel economy differs from 20 mpg.
  • d = 0.02: the observed mean is essentially on the test value.
  • 95% CI for the mean: 17.92 to 22.26 mpg. True averages anywhere in that range are consistent with the data, so we can’t claim the mean is 20, only that the data don’t contradict it.

APA write-up

A one-sample t-test found no evidence that mean fuel economy (M = 20.09, SD = 6.03) differed from 20 mpg, t(31) = 0.09, p = .933, d = 0.02, 95% CI for the mean [17.92, 22.26].

Common mistakes

  • Picking the test value after seeing the data, or using the sample’s own median.
  • Concluding the mean “equals” the test value from p > .05.
  • Testing a single Likert item against the midpoint with a t-test without considering that it’s ordinal. A Wilcoxon test is often more appropriate.

How to run it

  • SPSS: Analyze → Compare Means → One-Sample T Test, then enter the test value.
  • R: t.test(x, mu = 20)
  • Python: scipy.stats.ttest_1samp(x, 20)
  • Analytika: ask “is the average mpg different from 20?”. It checks normality and picks the one-sample t-test or the Wilcoxon test.

More in Comparing groups

Try it with the free tools

Run this on your own data

Upload a dataset and ask your question in plain English. Analytika checks the assumptions, picks the test, runs it, and writes the results up in APA format.

Try it free