liveBook · Manning

Confidence interval

As explained in Grokking Statistics

A confidence interval is an interval estimation procedure that expresses uncertainty about an unknown population parameter under a specified confidence level.

A confidence interval (CI) is a range used to estimate an unknown population value from a sample. Instead of reporting only a sample mean, such as 7.5 hours of daily screen time, report a range that makes the estimate’s uncertainty visible: a 95% CI of 7.01 to 7.99 hours. section 5.0 section 5.4

For a population mean, the interval is a point estimate plus or minus a margin of error: x̄ ± E. The margin combines a chosen confidence level, its critical Z-value, and the standard error. Higher confidence produces a wider interval; a larger sample produces a narrower one. section 5.4 section 5.9

A practical workflow for a mean CI is:

  • Start with a sample intended to represent the population, then calculate its mean, standard deviation, and size. section 5.0 section 5.4
  • Choose a confidence level, commonly 95% or 99%, and obtain the corresponding critical Z-value. section 5.4
  • Compute standard error as s / √n, multiply it by Z to get the margin, and subtract or add that margin to the mean. section 5.4
  • For a proportion, replace the mean’s standard-error component with √[p̂(1 − p̂) / n]. section 5.8

Screen time: same estimate, different certainty

A random sample of 100 people has mean screen time 7.5 hours and standard deviation 2.5 hours. Its 95% CI is (7.010, 7.990). Raising confidence to 99% widens it to (6.856, 8.144); increasing the sample to 1,000 narrows the 95% interval to (7.345, 7.655). section 5.4

A proportion of video-game players

If 55 of 100 randomly surveyed Americans play video games, the sample proportion is 55%. A 95% CI runs from 45.2% to 64.8%. This does not mean this particular interval has a 95% chance of containing the true proportion; it means 95% of intervals made this way would contain it. section 5.8

import scipy.stats as stats #1
import numpy as np #2

mean = 7.5 #3
std = 2.5 #4
n = 100 #5
confidence = 0.95 #6

z = stats.norm.ppf(1 - (1 - confidence) / 2) #7

se = std / np.sqrt(n) #8

margin = z * se #9

lower = mean - margin #10
upper = mean + margin #10

print(f"95% Confidence Interval: ({lower:.3f}, {upper:.3f})") #11

This Python calculation exposes the moving parts of a mean CI: confidence level, critical Z-value, standard error, margin of error, and lower and upper bounds. section 5.4

CIs support transparent decisions in areas such as medicine, manufacturing control, polling, and business comparisons. They estimate means or proportions from samples rather than turn a sample result into an absolute claim. For smaller samples estimating a mean, the t-distribution provides an alternative. section 5.4 section 5.9

How Grokking Statistics covers it

How deep it goes
Works through mean and proportion calculations, including margins of error, Z-values, sample size, and t-distribution use for smaller means.
Examples
Uses walking speed, daily screen time, golden retriever weights, and video-game survey proportions.
What it assumes
Builds on sampling and the central limit theorem while recapping the CLT as the foundation for interval estimation.
What you can do after
Apply it via SciPy to calculate and correctly interpret confidence intervals for means and proportions.
How it connects
Connects confidence intervals to sampling, population parameters, the central limit theorem, sampling distributions, critical Z-values, and the t-distribution.

Also explained in

Compare how 10 books explain confidence interval →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Statistics. The section links point to the parts of the book it draws on.