In the simple linear model Yi = β0 + β1xi + εi the x values are fixed and only the errors are random. Choose where to put the twelve (or n) x values and how noisy the data are, and draw thousands of data sets (here β0 = 2 and β1 = 1). The top panel is the histogram of the least squares slope, with the normal curve of Theorem 11.3.2; the middle panel is the pivot (β̂1 − β1)/(S/√Sxx) against the Student t curve with n − 2 degrees of freedom; the bottom panel plots the estimated intercept against the estimated slope. The table compares the theory with the simulation and reports how often the 95% intervals for the slope, for the mean response at x0 and for a new observation at x0 contain their targets.
Every draw uses a seeded generator, so a preset always shows the same values; 20 000 data sets give a coverage to about ±0.003. The histograms clip values beyond the plotted range (the count is shown). β0 = 2, β1 = 1 throughout.
code/ch11_regression.py (simulate_model, var_beta1, var_beta0, cov_b0_b1, ci_slope, ci_mean, pred_int; Figure x11.3).