Psychological Science & Statistics – Chapter 9
The One-Sample t-Test and Confidence Intervals
In Chapter 8 you learned the logic of hypothesis testing using a simulation- based one-sample t-test. You saw how to:
state a null hypothesis,
compute a sample t-statistic,
build a null distribution of t-values under \(H_0\), and
approximate a p-value by checking how extreme \(t_\text{obs}\) is.
In this chapter we take the next step: the analytic (formula-based) one-sample t-test, and the closely related 95% confidence interval (CI) for a population mean.
This chapter connects the simulation-based intuition from Chapter 8 to the classical t-test formulas used throughout psychological science.
When to Use a One-Sample t-Test
Use a one-sample t-test when you want to compare a sample mean to a known or hypothesized population mean:
Does the population of students represented by this class have a mean stress score of 20?
Mathematically, the hypotheses are:
Why We Use t (Instead of z)
When the population standard deviation \(\sigma\) is unknown—as is almost always the case in psychology—we use the sample standard deviation \(s\). Substituting \(s\) introduces extra uncertainty, leading to a t distribution instead of a normal distribution.
The estimated standard error is:
The t-statistic is:
Confidence Intervals
A 95% confidence interval around a mean provides a range of plausible population values:
where \(t^*\) is the critical value from the t distribution with \(n-1\) degrees of freedom.
Interpretation:
If we repeated the study many times, 95% of the resulting CIs would contain the true population mean.
Connecting Confidence Intervals and Hypothesis Tests
A powerful insight:
If the 95% CI **does not include* \(\mu_0\), the two-sided t-test will reject \(H_0\) at \(\alpha = 0.05\).*
If the CI **includes* \(\mu_0\), the t-test will fail to reject \(H_0\).*
PyStatsV1 Lab: A One-Sample t-Test With Confidence Intervals
In this lab, you will:
Load a synthetic population of stress scores (same population used in Ch. 7–8).
Draw a random sample of size \(n\).
Compute:
sample mean \(\bar{x}\),
sample SD \(s\),
standard error \(SE\),
t-statistic,
degrees of freedom \(df = n-1\),
p-value (analytic),
95% confidence interval.
Compare:
the analytic t-test,
the 95% CI,
and (optionally) the simulation results from Chapter 8.
All code for this chapter lives in:
scripts/psych_ch9_one_sample_ci.py
Running the Lab Script
From the project root:
python -m scripts.psych_ch9_one_sample_ci
If you have a Makefile target:
make psych-ch09
Expected Console Output
Your numbers will vary due to randomness, but output will look similar to:
Loaded synthetic population with 50000 individuals
Population mean stress_score = 19.98
Population SD stress_score = 9.94
Drawn sample size n = 25
Sample mean = 22.10
Sample SD = 10.44
SE = 2.09
t statistic = 1.01
df = 24
Analytic two-sided p-value = 0.323
95% CI = [17.80, 26.40]
Interpreting Your Output
Focus on:
the t-statistic: How many standard errors your mean is from the null;
the p-value: Is the result “rare” under \(H_0\)?
the CI: Does the interval contain the hypothesized value \(\mu_0\)?
Your Turn: Practice
Change the null value \(\mu_0\) and observe how the t-statistic changes.
Change the sample size \(n\) and see how the CI narrows or widens.
Run the analysis multiple times to see sampling variability.
Summary
In this chapter you learned:
the formula-based one-sample t-test,
how to compute a 95% confidence interval,
the connection between CIs and hypothesis tests.
In the next chapter (Chapter 10) we extend this logic to comparing two independent groups using the independent-samples t-test.