One-Sample t-test

One-Sample t-test

Definition

Core Statement

The One-Sample t-test determines whether the sample mean is statistically different from a known or hypothesized population mean (μ0). It is used when the population standard deviation is unknown.

t=x¯μ0s/n

Purpose

  1. Quality Control: Does the average weight of bags produced equal the target (e.g., 500g)?
  2. Benchmarking: Does our school's average score differ from the national average?
  3. Difference Scores: Testing if the average difference (Pre - Post) is non-zero (Paired t-test is technically a one-sample test on differences).

When to Use

Use When...

  • You have one group of continuous data.
  • You want to compare the mean to a specific value (μ0).
  • Population Deviation (σ) is Unknown (use s from sample).
  • n<30 (if n>30, t converges to z, but t-test is still safe).


Assumptions


Worked Example: Potato Chips

Problem

Bags of chips claim to hold 200g (μ0=200).
You sample 10 bags: Mean = 195g, StDev = 5g.

  1. Calculate SE: s/n=5/101.58.
  2. Calculate t:t=1952001.58=51.583.16
  3. Decision:
    • Degrees of freedom = 101=9.
    • Critical t (α=0.05, two-tailed) ±2.26.
    • |3.16|>2.26. Reject Null.

Conclusion: The bags are significantly underfilled.


Python Implementation

import scipy.stats as stats

data = [198, 195, 202, 190, 194, 199, 195, 192, 196, 189]
mu_0 = 200

t_stat, p_val = stats.ttest_1samp(data, popmean=mu_0)

print(f"T-statistic: {t_stat:.3f}")
print(f"P-value: {p_val:.4f}")

if p_val < 0.05:
    print("Reject Null: Mean is different from 200.")