Confidence intervals
Assignment 2 asked for intervals in four flavours: a t interval for one mean, the sample size for a given precision, a pooled interval for a difference of means with an F interval for the variance ratio, and a two-proportion test. This chapter rebuilds each one and starts with the idea that makes them all meaningful — coverage.
§3.1Coursework A2 Q2(a), Q4
Ninety-five out of a hundred
With σ unknown, the interval for a normal mean replaces σ by the sample standard deviation and pays for it with a heavier-tailed critical value:
It works because whatever the values of μ and σ — the pivot identified in Q4. Draw many samples and the intervals scatter around the truth; about 95% of them catch it.
Interval
Each sample is rnorm(10, 15, 3). With seed 1, n = 10 and 100 t intervals, R’s own loop over t.test() also gives 99 hits.
Intervals covering μ
99 / 100
Intervals missing μ
1
Observed coverage
99.0%
Wilson 95% 94.6% to 99.8%
Nominal coverage
95%
expect ≈ 5 misses
- Interval covers μ = 15
- Interval misses μ (marked ×)
- True mean μ
Show the numbers as a table
| # | x̄ | lower | upper | covers μ |
|---|---|---|---|---|
| 1 | 15.397 | 13.721 | 17.072 | yes |
| 2 | 15.747 | 13.451 | 18.042 | yes |
| 3 | 14.599 | 12.548 | 16.650 | yes |
| 4 | 15.362 | 13.627 | 17.097 | yes |
| 5 | 15.402 | 14.124 | 16.681 | yes |
| 6 | 15.430 | 13.253 | 17.608 | yes |
| 7 | 16.354 | 13.588 | 19.119 | yes |
| 8 | 14.257 | 12.906 | 15.608 | yes |
| 9 | 15.382 | 13.662 | 17.102 | yes |
| 10 | 15.337 | 13.078 | 17.596 | yes |
| 11 | 16.042 | 14.031 | 18.054 | yes |
| 12 | 14.641 | 13.283 | 15.998 | yes |
| 13 | 14.981 | 13.695 | 16.268 | yes |
| 14 | 13.715 | 12.222 | 15.208 | yes |
| 15 | 13.333 | 10.521 | 16.146 | yes |
| 16 | 14.246 | 11.905 | 16.586 | yes |
| 17 | 15.631 | 13.471 | 17.790 | yes |
| 18 | 17.257 | 15.305 | 19.209 | no |
| 19 | 14.463 | 12.385 | 16.541 | yes |
| 20 | 14.557 | 12.640 | 16.474 | yes |
| 21 | 16.581 | 13.781 | 19.382 | yes |
| 22 | 15.009 | 13.036 | 16.982 | yes |
| 23 | 13.940 | 11.718 | 16.163 | yes |
| 24 | 13.909 | 11.465 | 16.353 | yes |
| 25 | 15.091 | 12.925 | 17.257 | yes |
| 26 | 15.056 | 12.974 | 17.138 | yes |
| 27 | 15.073 | 13.116 | 17.029 | yes |
| 28 | 15.382 | 12.392 | 18.373 | yes |
| 29 | 15.224 | 13.416 | 17.033 | yes |
| 30 | 15.624 | 13.769 | 17.480 | yes |
| 31 | 16.365 | 14.062 | 18.668 | yes |
| 32 | 14.898 | 13.293 | 16.504 | yes |
| 33 | 15.696 | 13.506 | 17.886 | yes |
| 34 | 14.870 | 13.047 | 16.694 | yes |
| 35 | 14.812 | 12.138 | 17.487 | yes |
| 36 | 15.321 | 12.985 | 17.657 | yes |
| 37 | 14.223 | 11.772 | 16.674 | yes |
| 38 | 14.821 | 13.157 | 16.486 | yes |
| 39 | 14.314 | 11.790 | 16.838 | yes |
| 40 | 16.227 | 14.416 | 18.039 | yes |
| 41 | 15.380 | 13.331 | 17.429 | yes |
| 42 | 15.503 | 13.387 | 17.620 | yes |
| 43 | 14.203 | 11.720 | 16.686 | yes |
| 44 | 14.451 | 12.375 | 16.527 | yes |
| 45 | 13.642 | 10.550 | 16.735 | yes |
| 46 | 13.378 | 11.182 | 15.575 | yes |
| 47 | 16.897 | 14.986 | 18.808 | yes |
| 48 | 14.909 | 12.804 | 17.013 | yes |
| 49 | 14.923 | 11.837 | 18.010 | yes |
| 50 | 15.539 | 11.974 | 19.104 | yes |
| 51 | 14.885 | 12.676 | 17.094 | yes |
| 52 | 13.866 | 11.736 | 15.996 | yes |
| 53 | 14.701 | 12.936 | 16.467 | yes |
| 54 | 15.707 | 13.693 | 17.721 | yes |
| 55 | 14.925 | 12.891 | 16.958 | yes |
| 56 | 14.110 | 11.805 | 16.416 | yes |
| 57 | 14.770 | 13.152 | 16.388 | yes |
| 58 | 15.450 | 12.804 | 18.097 | yes |
| 59 | 16.008 | 13.973 | 18.043 | yes |
| 60 | 14.242 | 12.002 | 16.481 | yes |
| 61 | 15.439 | 13.133 | 17.744 | yes |
| 62 | 14.514 | 11.960 | 17.067 | yes |
| 63 | 15.782 | 13.193 | 18.370 | yes |
| 64 | 13.812 | 12.105 | 15.519 | yes |
| 65 | 13.221 | 10.924 | 15.518 | yes |
| 66 | 14.125 | 11.276 | 16.974 | yes |
| 67 | 14.703 | 12.131 | 17.275 | yes |
| 68 | 13.381 | 11.448 | 15.314 | yes |
| 69 | 14.869 | 12.744 | 16.994 | yes |
| 70 | 14.168 | 11.732 | 16.605 | yes |
| 71 | 14.959 | 12.198 | 17.719 | yes |
| 72 | 15.371 | 12.551 | 18.191 | yes |
| 73 | 14.989 | 12.931 | 17.047 | yes |
| 74 | 15.237 | 13.470 | 17.004 | yes |
| 75 | 14.963 | 11.779 | 18.146 | yes |
| 76 | 14.091 | 11.236 | 16.947 | yes |
| 77 | 15.607 | 13.604 | 17.610 | yes |
| 78 | 15.378 | 13.211 | 17.545 | yes |
| 79 | 14.900 | 13.066 | 16.735 | yes |
| 80 | 14.512 | 11.925 | 17.099 | yes |
| 81 | 14.059 | 11.843 | 16.276 | yes |
| 82 | 14.695 | 11.710 | 17.680 | yes |
| 83 | 15.349 | 13.075 | 17.622 | yes |
| 84 | 16.076 | 13.584 | 18.568 | yes |
| 85 | 15.620 | 12.232 | 19.008 | yes |
| 86 | 13.203 | 11.381 | 15.024 | yes |
| 87 | 15.239 | 13.304 | 17.174 | yes |
| 88 | 15.534 | 13.947 | 17.121 | yes |
| 89 | 15.828 | 13.648 | 18.008 | yes |
| 90 | 14.699 | 12.457 | 16.941 | yes |
| 91 | 14.427 | 12.569 | 16.285 | yes |
| 92 | 15.573 | 13.323 | 17.824 | yes |
| 93 | 15.555 | 13.285 | 17.825 | yes |
| 94 | 14.857 | 12.043 | 17.670 | yes |
| 95 | 16.559 | 14.605 | 18.512 | yes |
| 96 | 15.155 | 13.118 | 17.193 | yes |
| 97 | 13.768 | 10.466 | 17.071 | yes |
| 98 | 14.607 | 11.688 | 17.525 | yes |
| 99 | 15.599 | 14.448 | 16.750 | yes |
| 100 | 14.021 | 12.466 | 15.577 | yes |
With 100 intervals the observed coverage is itself an estimate. The Wilson interval above shows how far it could plausibly sit from the true coverage. Appendix B runs this experiment 5,000 times per setting, for skewed data too.
Explain this resultoptional · your own key
Add your own Anthropic or OpenAI key in AI settings to enable. Nothing is sent without one.
§3.2Coursework A2 Q2(b)
How many walks are enough?
When σ is known the half-width of a z interval is . Solving for n gives the planning formula
With σ = 3 minutes and a target of ±1 minute, (1.96 × 3)² ≈ 34.57, so 35 walks are needed.
Critical value z
1.960
(zσ / E)²
34.57
Walks needed
35
round up to a whole sample
§3.3Coursework A2 Q2(c)–(e)
Two routes, two samples
For independent normal samples with a common variance, pool the two sample variances,
and the interval for the difference in means is
The equal-variance assumption can itself be examined: , which inverts to an interval for — what var.test() reports.
10 values
8 values
Defaults are simulated (X ~ N(15, 3²), Y ~ N(20.3, 0.8²)) to mimic the shape of the assignment data. Paste your own values to analyse them.
95% CI for μX − μY
(-6.84, -1.85)
pooled sp = 2.486, df = 16
F = s²X / s²Y
9.881
df = (9, 7)
95% CI for σ²X / σ²Y
(2.049, 41.47)
F test p-value
0.00638
variances differ
- Sample X
- Sample Y
- Mean with its t interval
Show the numbers as a table
| sample | n | mean | sd | t interval |
|---|---|---|---|---|
| X (route A) | 10 | 16.280 | 3.191 | (13.997, 18.563) |
| Y (route B) | 8 | 20.625 | 1.015 | (19.776, 21.474) |
§3.4Coursework A2 Q1
Do two councils differ?
For large samples the difference of sample proportions is approximately normal. The test of uses the pooled proportion in its standard error, and its square is the chi-squared statistic that prop.test() prints; the interval uses each group’s own proportion:
Defaults are the survey counts from the assignment (support for more bicycle lanes in two inner-Melbourne councils). Equivalent to prop.test(…, correct = FALSE).
p̂₁ − p̂₂
0.0500
0.650 vs 0.600
X² (= z²)
4.7269
z = 2.174
p-value
0.02969
reject H₀ at α = 0.05
95% CI for p₁ − p₂
(0.0051, 0.0949)
- Estimate and interval for p₁ − p₂
- No difference (H₀)