CookbookTeaching and coursesNo. 19
An open textbookchapters drafted in the open and released under a Creative Commons licence
See it in know.sh
Counting on ItChapter 5
3of 9
Confidence interval for a mean
Evidence, key section, 1 highlight, 1 note, 3 sources, 610 words
A city transport survey publishes the one-way commuting times of people who answered it. We take a random sample of 24 and estimate the mean commute for everyone who answered.
| Sample | n | Mean (minutes) | Standard deviation |
|---|---|---|---|
| Transport survey, random sample | 24 | 27.5 | 9.8 |
Look at the sample before estimating anything from it. The median is 25.5 minutes; a few long commutes pull the mean above it.
One-way commute, random sample of 24 survey answers
| Commute | People |
|---|---|
| 10–15 min | 1 |
| 15–20 min | 5 |
| 20–25 min | 4 |
| 25–30 min | 6 |
| 30–35 min | 4 |
| 35–40 min | 2 |
| 40–45 min | 0 |
| 45–50 min | 1 |
| 50–55 min | 1 |
The 24 values in commute_sample.csv, drawn at random from the city transport survey.
One-way commute, random sample of 24 survey answers
| Commute | People |
|---|---|
| 10–15 min | 1 |
| 15–20 min | 5 |
| 20–25 min | 4 |
| 25–30 min | 6 |
| 30–35 min | 4 |
| 35–40 min | 2 |
| 40–45 min | 0 |
| 45–50 min | 1 |
| 50–55 min | 1 |
24 people from 14 min to 55 min; median 25.5 min, mean 27.5 min.
Rules mark the median and the mean.
Source: The 24 values in commute_sample.csv, drawn at random from the city transport survey.
```element histogram
{
"caption": "One-way commute, random sample of 24 survey answers",
"values": "29, 29, 34, 26, 21, 29, 32, 36, 24, 18, 30, 25, 39, 18, 47, 14, 21, 19, 16, 31, 24, 55, 18, 25",
"binWidth": 5,
"xLabel": "Commute",
"units": "min",
"countLabel": "people",
"stat": "both",
"source": "The 24 values in *commute_sample.csv*, drawn at random from the city transport survey."
}
```A 95% confidence interval for a mean is mean ± t* × s / sqrt(n), where t* is the critical value of the t distribution with n − 1 = 23 degrees of freedom, about 2.07.
commute <- read.csv("commute_sample.csv")
t.test(commute$minutes, conf.level = 0.95)$conf.int
# 23.4 to 31.6 minutes
We are 95% confident that the mean commute lies between about 23.4 and 31.6 minutes. That is a statement about the method, not about any one commuter.
Adapted from Statistics for Everyone, chapter 6, by J. Ferris, CC BY 4.0; example data replaced.
How it works
Write Counting on It a chapter at a time, in the open. Your assistant lays out each chapter from your lecture notes; you write the explanations, run the R and give every section its sources. Each worked example shows its sample as a histogram, mean and median marked, and every chapter goes out on a public link under CC BY.