A margin of error is the amount added to and subtracted from a point estimate to create an interval estimate. For a sample mean x̄, the interval is x̄ ± E: the estimate plus or minus its uncertainty. Instead of reporting only 7.5 hours of average screen time, report a 95% confidence interval of 7.01 to 7.99 hours. section 5.4
The margin depends on the chosen confidence level and the estimate's standard error. For a mean, calculate E by multiplying the critical Z-value by s divided by the square root of n. Higher confidence produces a wider interval; a larger sample produces a narrower one in the demonstrated calculations. section 5.4
Use the margin of error to read an interval carefully:
- Interpret a 95% interval as a procedure in which 95% of such intervals would contain the true population parameter, rather than as a 95% chance that this particular interval contains it. section 5.8
- For a population proportion, replace the mean's standard error with the square root of p̂(1 − p̂) divided by n, then multiply by the critical Z-value. section 5.8
- Use intervals to communicate study uncertainty, inform decisions, and compare estimates by considering how much their intervals overlap. section 5.4
Screen time and video games
A random sample of 100 people has mean screen time 7.5 hours and standard deviation 2.5 hours. The calculated 95% interval is (7.01, 7.99) hours. For a separate survey, 55 of 100 people play video games, giving a 95% population-proportion interval of 45.2% to 64.8%. section 5.4 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
Run the Python calculation to vary the mean, standard deviation, sample size, or confidence level and inspect the resulting interval. section 5.4
import math
from scipy.stats import norm
n = 100 #1
x = 55 #2
p_hat = x / n #3
confidence = .95 #4
z = norm.ppf(1 - (1 - confidence) / 2) #5
margin = z * math.sqrt(p_hat * (1 - p_hat) / n) #6
lower = p_hat - margin #7
upper = p_hat + margin #8
print(f"{confidence*100:.0f}% Confidence Interval: ({lower:.3f}, {upper:.3f})") #9
Adapt the proportion calculation to see how a sample count and confidence level change the interval. section 5.8

