How Do Confidence Intervals Work?
Prepared by Ian McLeod
 This Demonstration shows the confidence interval, x̄ +/- m, for μ based on random samples of size n from a normal population with mean μ and standard deviation σ, where x̄ is the sample mean and m is the margin of error for a level C interval. There are two cases, corresponding to when σ is assumed known, or is not known and is estimated by the standard deviation in the sample. For the known σ case, m = z*σ/√n, where the critical value z* is determined so that the area to the right of z* is (1-C)/2. Similarly in the unknown σ case, m = t*s/√n, where s is the sample standard deviation and t* is the critical value determined from a t-distribution with n-1 degrees of freedom. Five things to see in this Demonstration: 1. The width of the confidence interval increases as C increases. 2. The width of the confidence interval decreases as n increases. 3. For fixed C and n, the width of the confidence interval in the known σ case is fixed, but it is stochastic when σ is unknown due to the variation in the sample standard deviation, σ. The stochastic property can be seen by varying the random seed when σ unknown is selected. 4. The width of the confidence interval tends to be larger in the unknown σ case but the difference decreases as n increases. 5. Running an animation varying the random seed, we can obtain an empirical estimate Ĉ of the coverage probability. Try slowing the animation down to get a large number of repetitions. The intervals are color coded: black when the interval covers μ and red when it misses. The animation demonstrates the stochastic coverage probability of the interval.