Chapter 69 · Solutions
Point vs. Interval — Worked Solutions ✅
Five challenges, each verified in code.
⚙️ Setup¶
In [1]:
import numpy as np, pandas as pd
from scipy import stats
rng = np.random.default_rng(690)
BASE="https://raw.githubusercontent.com/johnfisher-ai/Statistics-Data-Science-AI-Visual-Book/main/data/"
CHALLENGE 1
A point estimate
Draw one sample of 50 from Normal(75, 12) and report the point estimate of the mean.
In [2]:
samp = rng.normal(75, 12, 50)
print(f"point estimate x-bar = {samp.mean():.2f} (true mean 75)")
point estimate x-bar = 74.86 (true mean 75)
CHALLENGE 2
The standard error
Estimate the standard error of the mean for that sample two ways: the formula s/sqrt(n) and by simulating many samples.
In [3]:
pop = rng.normal(75,12,500_000)
formula = 12/np.sqrt(50)
sim = np.array([rng.choice(pop,50,replace=False).mean() for _ in range(3000)]).std()
print(f"SE formula sigma/sqrt(n) = {formula:.3f}")
print(f"SE simulated = {sim:.3f}")
SE formula sigma/sqrt(n) = 1.697 SE simulated = 1.684
CHALLENGE 3
Build a 95% interval
From a single sample of 50 (sigma known = 12), build a 95% interval estimate point +/- z*SE.
In [4]:
s = rng.normal(75,12,50); xb=s.mean(); se=12/np.sqrt(50); z=stats.norm.ppf(0.975)
print(f"95% interval: [{xb-z*se:.2f}, {xb+z*se:.2f}] = {xb:.2f} +/- {z*se:.2f}")
95% interval: [70.58, 77.23] = 73.91 +/- 3.33
CHALLENGE 4
Coverage of the procedure
Build 2,000 such 95% intervals and confirm about 95% contain the true mean.
In [5]:
pop=rng.normal(75,12,500_000); MU=pop.mean(); z=stats.norm.ppf(0.975); se=12/np.sqrt(50)
cov=np.mean([(lambda xb: xb-z*se<=MU<=xb+z*se)(rng.choice(pop,50,replace=False).mean()) for _ in range(2000)])
print(f"coverage of 2000 intervals = {cov*100:.1f}% (target 95%)")
coverage of 2000 intervals = 96.1% (target 95%)
CHALLENGE 5
Real data: mean home price
Load point-vs-interval-estimation--home_sales.xlsx and report the point estimate and 95% interval for the mean sale price.
In [6]:
try: homes = pd.read_excel("../../data/point-vs-interval-estimation--home_sales.xlsx", sheet_name="Sales")
except FileNotFoundError: homes = pd.read_excel(BASE+"point-vs-interval-estimation--home_sales.xlsx", sheet_name="Sales")
p=homes.sale_price; n=len(p); xb=p.mean(); se=p.std(ddof=1)/np.sqrt(n); z=stats.norm.ppf(0.975)
print(f"n={n}: point ${xb:,.0f}, 95% interval [${xb-z*se:,.0f}, ${xb+z*se:,.0f}]")
print(f"median ${p.median():,.0f} (mean>median: right-skewed)")
n=220: point $338,159, 95% interval [$328,986, $347,331] median $335,550 (mean>median: right-skewed)
Statistics, Data Science and AI: A Visual Handbook · © 2026 John Fisher