Investigation · The influential endpoint
Keep the first four outcomes at 2, 3, 5 and 4. Change the fifth outcome at predictor value five. Compare the slope and in-sample fit with the printed base case, then decide what context you need before excluding a point.
Printed base: intercept 1.3, slope 0.9, R² 0.81. The display below updates; the figure depicts only the printed base.

Investigation · Odds are not probabilities
For an odds ratio of two, compare a baseline probability of ten percent with fifty percent. The new probabilities are about 18.18% and 66.67%; the absolute changes are different.

Reproduce and reason
Download the executed Python calculation and draft exercise solutions. The Python script checks the normal equations, leave-one-out predictions, classical interval arithmetic and odds conversion. Its tests do not establish causal validity.
Inspect the work.
Read the programs, run them in your own environment, and compare the results. The captured output records the chapter’s checked practical run; changing an input may change its answer.
Python regression_lab.py
"""Constructed teaching data. Run: python3 regression_lab.py"""
from pathlib import Path
import math
import numpy as np
ROOT=Path(__file__).resolve().parent
x=np.array([1.,2.,3.,4.,5.])
y=np.array([2.,3.,5.,4.,6.])
xbar=x.mean();ybar=y.mean()
sxx=float(((x-xbar)**2).sum());sxy=float(((x-xbar)*(y-ybar)).sum())
slope=sxy/sxx;intercept=ybar-slope*xbar
fitted=intercept+slope*x;resid=y-fitted
sse=float((resid**2).sum());sst=float(((y-ybar)**2).sum());r2=1-sse/sst
assert sxx==10 and sxy==9
assert abs(slope-.9)<1e-12 and abs(intercept-1.3)<1e-12
assert abs(sse-1.9)<1e-12 and abs(r2-.81)<1e-12
assert abs(sum(resid))<1e-12 and abs(sum(x*resid))<1e-12
def logistic(z):return 1/(1+math.exp(-z))
assert abs(logistic(0)-.5)<1e-12
assert abs(logistic(math.log(4))-.8)<1e-12
def prob_after_odds_ratio(p, ratio):
odds=p/(1-p)
new=odds*ratio
return new/(1+new)
assert abs(prob_after_odds_ratio(.1,2)-2/11)<1e-12
assert abs(prob_after_odds_ratio(.5,2)-2/3)<1e-12
# Independent refits for the five leave-one-out claims printed in the chapter.
loo=[]
for i in range(len(x)):
keep=np.arange(len(x))!=i
m,c=np.polyfit(x[keep],y[keep],1)
loo.append(float(c+m*x[i]))
loo_error=y-np.array(loo)
loo_rmse=float(np.sqrt(np.mean(loo_error**2)))
assert np.allclose(loo,[2.5,22/7,3.75,37/7,5.5])
assert abs(loo_rmse-.8644037699773293)<1e-10
# Classical intervals here are only conditional on the stated teaching model.
s2=sse/(len(x)-2); tcrit=3.182446305284263
slope_se=math.sqrt(s2/sxx)
mean_se=math.sqrt(s2/len(x))
new_se=math.sqrt(s2*(1+1/len(x)))
assert abs(slope_se-.2516611478423583)<1e-12
assert abs(mean_se-.3559026084010437)<1e-12
assert abs(new_se-.8717797887081347)<1e-12
mean_se_at_six=math.sqrt(s2*(1/len(x)+(6-xbar)**2/sxx))
mean_interval_at_six=(intercept+slope*6-tcrit*mean_se_at_six,intercept+slope*6+tcrit*mean_se_at_six)
assert abs(mean_se_at_six-.834665601703261)<1e-12
assert np.allclose(mean_interval_at_six,[4.043721539712,9.356278460288],atol=1e-6)
omitted_bias_example=.2+1.5*.4
assert abs(omitted_bias_example-.8)<1e-12
print('XBAR',xbar,'YBAR',ybar,'SXX',sxx,'SXY',sxy)
print('LINE intercept',round(intercept,4),'slope',round(slope,4))
print('FITTED',np.round(fitted,4).tolist())
print('RESIDUALS',np.round(resid,4).tolist())
print('SSE',round(sse,4),'SST',round(sst,4),'R2',round(r2,4))
print('ODDS RATIO 2, BASELINE 10%',round(prob_after_odds_ratio(.1,2),4))
print('ODDS RATIO 2, BASELINE 50%',round(prob_after_odds_ratio(.5,2),4))
print('LOO PREDICTIONS',np.round(loo,4).tolist(),'RMSE',round(loo_rmse,4))
print('SLOPE 95% MODEL INTERVAL',np.round([slope-tcrit*slope_se,slope+tcrit*slope_se],4).tolist())
print('MEAN 95% MODEL INTERVAL AT X=3',np.round([4-tcrit*mean_se,4+tcrit*mean_se],4).tolist())
print('INDIVIDUAL 95% MODEL INTERVAL AT X=3',np.round([4-tcrit*new_se,4+tcrit*new_se],4).tolist())
print('MEAN 95% MODEL INTERVAL AT X=6',np.round(mean_interval_at_six,4).tolist())
print('OMITTED-VARIABLE ILLUSTRATION SIMPLE SLOPE',round(omitted_bias_example,4))
print('REGRESSION CHECKS PASS')
Output Checked chapter run
XBAR 3.0 YBAR 4.0 SXX 10.0 SXY 9.0 LINE intercept 1.3 slope 0.9 FITTED [2.2, 3.1, 4.0, 4.9, 5.8] RESIDUALS [-0.2, -0.1, 1.0, -0.9, 0.2] SSE 1.9 SST 10.0 R2 0.81 ODDS RATIO 2, BASELINE 10% 0.1818 ODDS RATIO 2, BASELINE 50% 0.6667 LOO PREDICTIONS [2.5, 3.1429, 3.75, 5.2857, 5.5] RMSE 0.8644 SLOPE 95% MODEL INTERVAL [0.0991, 1.7009] MEAN 95% MODEL INTERVAL AT X=3 [2.8674, 5.1326] INDIVIDUAL 95% MODEL INTERVAL AT X=3 [1.2256, 6.7744] MEAN 95% MODEL INTERVAL AT X=6 [4.0437, 9.3563] OMITTED-VARIABLE ILLUSTRATION SIMPLE SLOPE 0.8 REGRESSION CHECKS PASS