Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

In 2.2 Least squares from first principles we fit a line to the Toluca Company’s 25 production runs and got a slope of b1=3.5702b_1 = 3.5702 hours per unit of lot size. The engineers were pleased, and then they asked the questions any careful person asks about a number: how sure are you? A different 25 runs would have given a slightly different slope. Could the true slope really be zero, meaning lot size does not affect hours at all and we are fooling ourselves? And the practical one, the reason they collected the data: if we schedule a new run of 100 units next week, how many hours should we budget, and how far off might that be?

Chapter 2 gave point estimates: single best guesses for the intercept, slope, and error variance. A point estimate with no measure of its uncertainty is half an answer. This chapter supplies the other half. We attach margins of error to the slope and intercept, test whether the slope is really different from zero, and, most importantly for planning, build two very different intervals around a prediction. One says where the average run of a given size lands. The other says where a single new run lands. Figure 1 shows both drawn around the Toluca line, and the gap between them is the single most useful idea in the chapter.

The Toluca scatterplot with the fitted line and two shaded bands. A narrow inner blue band hugs the line closely; a much wider outer yellow band surrounds it. Both are narrowest near the middle lot sizes and flare out toward the ends. Nearly all 25 data points fall inside the outer band, and the points scatter well outside the inner band.

Figure 1:The inner (blue) band is a 95% confidence band for the mean hours at each lot size; the outer (yellow) band is a 95% prediction band for a single new run. The prediction band must cover one run’s own random scatter, so it is far wider. Confusing the two is the most common and most expensive mistake in applied regression.

Everything here rests on one added assumption that Chapter 2 introduced but did not yet use for inference: the errors are normally distributed (2.6 Maximum likelihood under normal errors). With that assumption the sampling distributions sketched in 2.5 Sampling behavior and the Gauss-Markov theorem become exact tt and FF distributions, and honest intervals and tests follow.

3.1 The sampling distributions of b0b_0 and b1b_1

Intuition

We already know from 2.5 Sampling behavior and the Gauss-Markov theorem that the slope estimate b1b_1 is unbiased, with variance σ2/Sxx\sigma^2/S_{xx}, where Sxx=i(XiXˉ)2S_{xx} = \sum_i (X_i - \bar{X})^2 is the spread of the predictor values about their mean Xˉ\bar{X}. That tells us where b1b_1 centers and how much it spreads, but not the shape of its distribution. To build an interval we need the shape. The trick is that b1b_1 is a weighted sum of the responses, and a weighted sum of independent normal random variables is itself normal. So the moment we assume normal errors, b1b_1 is exactly normal, and we can standardize it the way intro statistics standardizes a sample mean.

There is one wrinkle. Standardizing needs the true error standard deviation σ\sigma, which we do not know. We replace it with the estimate s=MSEs = \sqrt{\mathrm{MSE}}. Swapping a known constant for a noisy estimate adds a little extra uncertainty, and that extra uncertainty is exactly what turns the normal distribution into a tt distribution. Figure 2 confirms this: standardize 5000 simulated slopes by their own estimated standard errors, and the pile matches a tt curve, with slightly heavier tails than the normal.

A histogram of 5000 standardized slope estimates, bell-shaped and centered at zero. A red t-distribution curve with 23 degrees of freedom traces the histogram closely, while a dashed orange standard-normal curve sits slightly too low in the tails and slightly too high in the middle.

Figure 2:Five thousand slope estimates, each standardized by its own estimated standard error. The pile follows a t distribution with 23 degrees of freedom (red), whose tails are a touch heavier than the standard normal (dashed). Using s in place of sigma is what makes the reference distribution t rather than normal.

Formula

Under the normal error model Yi=β0+β1Xi+εiY_i = \beta_0 + \beta_1 X_i + \varepsilon_i with εiiidN(0,σ2)\varepsilon_i \overset{\text{iid}}{\sim} N(0, \sigma^2), the estimators are exactly normal:

b1N ⁣(β1, σ2Sxx),b0N ⁣(β0, σ2(1n+Xˉ2Sxx)).b_1 \sim N\!\left(\beta_1, \ \frac{\sigma^2}{S_{xx}}\right), \qquad b_0 \sim N\!\left(\beta_0, \ \sigma^2\Big(\tfrac{1}{n} + \tfrac{\bar{X}^2}{S_{xx}}\Big)\right).

In words: each estimator is centered on the parameter it estimates, with the variance we derived in Chapter 2, and now with a normal shape. To standardize either one we need the spread of the estimate. The estimated standard error of the slope (Definition 3.1) supplies it.

The estimated standard error s{b1}s\{b_1\} is our best guess at how much b1b_1 bounces from one sample to the next. Standardizing b1b_1 with it gives a tt statistic, the result stated next.

In words: subtract the true value and divide by the estimated standard error, and the result follows a tt distribution with n2n-2 degrees of freedom. The degrees of freedom are n2n-2 because that is the divisor in MSE\mathrm{MSE}, the two lost degrees paying for b0b_0 and b1b_1 (2.4 Estimating the error variance). This single tt result powers every interval and test in the rest of the chapter.

That last sentence is worth a picture. Almost everything ahead is one idea, the tt statistic above, pointed at a different estimate each time. Figure 3 is the map of the chapter on one page: keep it in mind and each new section becomes “the same move, new target.”

A flowchart. A top box reads normal errors from Chapter 2 and estimate sigma by s equals the square root of MSE. An arrow leads down to a central box labeled one t statistic, estimate minus target over its estimated standard error, distributed as t with n minus 2 degrees of freedom. Five arrows fan out from that box to five smaller boxes: slope beta-one CI and test in section 3.2, intercept beta-zero CI and test in 3.3, mean response CI in 3.4, new-case prediction interval in 3.5, and the F test with F equals t squared in 3.6 to 3.7. A caption line reads that every interval and test below is the same t idea applied to a different estimate.

Figure 3:The whole chapter on one page. Take one estimate, subtract what it is trying to hit, divide by its estimated standard error, and read the answer off a t distribution. Every section ahead is that single move aimed at a new target.

Derivation

Derivation (the tt statistic for the slope). We assemble the result from three facts.

Normality. From 2.5 Sampling behavior and the Gauss-Markov theorem, b1=ikiYib_1 = \sum_i k_i Y_i with ki=(XiXˉ)/Sxxk_i = (X_i - \bar{X})/S_{xx}. Under the normal error model the YiY_i are independent normal variables, and any linear combination of independent normals is normal. With the mean and variance already derived, b1N(β1,σ2/Sxx)b_1 \sim N(\beta_1, \sigma^2/S_{xx}). Dividing by the true standard deviation gives a standard normal:

Z=b1β1σ/SxxN(0,1).Z = \frac{b_1 - \beta_1}{\sigma/\sqrt{S_{xx}}} \sim N(0,1).

A chi-square, independent of the slope. It can be shown that

SSEσ2=(n2)MSEσ2χn22,\frac{\mathrm{SSE}}{\sigma^2} = \frac{(n-2)\,\mathrm{MSE}}{\sigma^2} \sim \chi^2_{n-2},

and that this quantity is statistically independent of b1b_1 (indeed of the whole vector (b0,b1)(b_0, b_1)). The clean proof uses the hat matrix and a theorem on quadratic forms in normal vectors; we give it in full in 7.3 The hat matrix, once we have the matrix tools. For now we take these two facts on faith, and note that the simulation in Figure 2 is a direct check that the end result is right.

Combine into a tt. A standard normal divided by the square root of an independent chi-square over its degrees of freedom is, by definition, a tt random variable:

b1β1s{b1}=(b1β1)/(σ/Sxx)MSE/σ2=Zχn22/(n2)tn2.\frac{b_1 - \beta_1}{s\{b_1\}} = \frac{(b_1 - \beta_1)\big/\big(\sigma/\sqrt{S_{xx}}\big)}{\sqrt{\mathrm{MSE}/\sigma^2}} = \frac{Z}{\sqrt{\chi^2_{n-2}/(n-2)}} \sim t_{n-2}.

The middle step just multiplies top and bottom out: the numerator is ZZ, and s{b1}/(σ/Sxx)=MSE/σ2=χn22/(n2)s\{b_1\}/(\sigma/\sqrt{S_{xx}}) = \sqrt{\mathrm{MSE}/\sigma^2} = \sqrt{\chi^2_{n-2}/(n-2)}. The identical argument with the weights mim_i from 2.5 Sampling behavior and the Gauss-Markov theorem gives the tt statistic for b0b_0. \blacksquare

The setup code below refits the Toluca model and recovers the standard errors we will use throughout.

toluca <- read.csv("data/toluca.csv")
fit <- lm(hours ~ lotsize, data = toluca)
n <- nrow(toluca)
x <- toluca$lotsize
y <- toluca$hours
Sxx <- sum((x - mean(x))^2)
MSE <- sum(residuals(fit)^2) / (n - 2)
round(c(n = n, Sxx = Sxx, MSE = MSE, s = sqrt(MSE),
        se_b1 = sqrt(MSE / Sxx)), 4)
         n        Sxx        MSE          s      se_b1 
   25.0000 19800.0000  2383.7156    48.8233     0.3470 
import numpy as np
import pandas as pd
import statsmodels.formula.api as smf

toluca = pd.read_csv("data/toluca.csv")
fit = smf.ols("hours ~ lotsize", data=toluca).fit()
n = len(toluca)
x = toluca["lotsize"].to_numpy()
y = toluca["hours"].to_numpy()
Sxx = np.sum((x - x.mean()) ** 2)
MSE = np.sum(fit.resid ** 2) / (n - 2)
print(round(MSE, 4), round(np.sqrt(MSE), 4), round(np.sqrt(MSE / Sxx), 4))
2383.7156 48.8233 0.347

The estimated standard error of the slope is s{b1}=0.347s\{b_1\} = 0.347 hours per unit, the same number Chapter 2 computed from the variance formula. It is the yardstick for everything that follows.

3.2 Inference for the slope

Intuition

The slope is usually the number a study is about: does lot size affect hours, and by how much? Two questions come in a pair. A confidence interval (Definition 3.3) answers “how much?” by giving a range of plausible values for β1\beta_1. A hypothesis test answers “is there any effect at all?” by asking whether zero is a plausible value. Both are built from the one tt statistic of 3.1 The sampling distributions of b0b_0 and b1b_1, so they always agree: a 95% interval excludes zero exactly when the two-sided test rejects at the 5% level.

Formula

In words: take the estimate and reach out a multiplier’s worth of standard errors on each side. To test H0:β1=0H_0: \beta_1 = 0 against Ha:β10H_a: \beta_1 \ne 0, form the test statistic

t=b10s{b1},t^{\ast} = \frac{b_1 - 0}{s\{b_1\}},

and reject H0H_0 when t>t1α/2,n2|t^{\ast}| > t_{1-\alpha/2,\,n-2}, or equivalently when the two-sided p-value 2P(tn2>t)2\,P(t_{n-2} > |t^{\ast}|) is below α\alpha. In words: if the estimate sits many standard errors away from zero, zero is not credible. Nothing here is special to zero; to test H0:β1=cH_0: \beta_1 = c for any value cc, put cc in place of the 0.

The 95% in “95% confident” is a promise about repeated samples, not about the one interval sitting in front of you, and that is a hard thing to take on faith. The widget below draws the samples so you can watch the promise being kept, and occasionally broken.

What to notice. Each bar is one sample’s standardized slope, and a bar out in the amber tail is a 95% interval that missed β1\beta_1 entirely. Try this. Draw a hundred at a time until the caught percentage settles near 95, then reread the interval in 3.2 Inference for the slope knowing what that number is counting.

3.3 Inference for the intercept

The intercept is where the fitted line crosses the vertical axis: the model’s predicted hours for a lot of zero units. It is the same kind of estimate as the slope, so it gets the exact same machinery. Follow the roadmap in Figure 3 one box over, and only the standard error changes.

The intercept gets the same treatment, with its own standard error s{b0}=MSE(1/n+Xˉ2/Sxx)s\{b_0\} = \sqrt{\mathrm{MSE}\,(1/n + \bar{X}^2/S_{xx})}. The confidence interval is b0±t1α/2,n2s{b0}b_0 \pm t_{1-\alpha/2,\,n-2}\, s\{b_0\}, and the test of H0:β0=0H_0: \beta_0 = 0 uses t=b0/s{b0}t^{\ast} = b_0/s\{b_0\}.

The reason the intercept comes second is that it is usually less interesting and often not interpretable. For Toluca, β0\beta_0 is the mean hours at a lot size of zero, an extrapolation far outside the data (2.2 Least squares from first principles), so a test of β0=0\beta_0 = 0 answers a question nobody asked. The interval is still worth computing, if only to see how loosely the intercept is pinned down.

confint(fit, "(Intercept)", level = 0.95)
               2.5 %  97.5 %
(Intercept) 8.213711 116.518
print(fit.conf_int(alpha=0.05).loc["Intercept"])
0      8.213711
1    116.518006
Name: Intercept, dtype: float64

The 95% interval for the intercept runs from about 8 to 117 hours, a span of over 100 hours. That enormous width is the price of extrapolating to X=0X = 0, which sits 70 units below the smallest observed lot. Compare it with the slope’s tight interval: the slope is anchored by data on both sides, the intercept is not.

3.4 Confidence interval for a mean response

Intuition

Now we move from the coefficients to a prediction. Ask: across all runs of lot size Xh=65X_h = 65, what is the average number of hours? That average is the point on the true line, E{Yh}=β0+β1XhE\{Y_h\} = \beta_0 + \beta_1 X_h, and our estimate of it is the fitted value Y^h=b0+b1Xh\hat{Y}_h = b_0 + b_1 X_h. Because b0b_0 and b1b_1 wobble from sample to sample, so does Y^h\hat{Y}_h, and we want an interval for the true mean.

The key feature is that the interval’s width depends on where XhX_h sits. Near the center Xˉ\bar{X} the fitted line is pinned down tightly, so the interval is narrow. Far from Xˉ\bar{X} a small tilt in the slope swings the line up or down a lot, so the interval widens. This is the pinch we saw in the bundle of fitted lines in Figure 15, now made into a formula.

Formula

The estimated variance of the fitted mean at XhX_h is

s2{Y^h}=MSE(1n+(XhXˉ)2Sxx),s^2\{\hat{Y}_h\} = \mathrm{MSE}\left(\frac{1}{n} + \frac{(X_h - \bar{X})^2}{S_{xx}}\right),

and the confidence interval for the mean response follows.

In words: the further XhX_h is from the average predictor value Xˉ\bar{X}, the larger the second term inside the parentheses, and the wider the interval. At Xh=XˉX_h = \bar{X} the second term vanishes and the interval is at its narrowest, width set only by 1/n1/n.

Derivation

Derivation (variance of the fitted mean). Write the fitted value in its pivoted form, using b0=Yˉb1Xˉb_0 = \bar{Y} - b_1 \bar{X}:

Y^h=b0+b1Xh=Yˉ+b1(XhXˉ).\hat{Y}_h = b_0 + b_1 X_h = \bar{Y} + b_1 (X_h - \bar{X}).

The two pieces Yˉ\bar{Y} and b1b_1 are uncorrelated. To see it, recall b1=kiYib_1 = \sum k_i Y_i and Yˉ=1nYi\bar{Y} = \sum \tfrac{1}{n} Y_i, so, using independence of the YiY_i and ki=0\sum k_i = 0,

Cov{Yˉ,b1}=i1nkiVar{Yi}=σ2niki=0.\operatorname{Cov}\{\bar{Y}, b_1\} = \sum_i \frac{1}{n}\, k_i \operatorname{Var}\{Y_i\} = \frac{\sigma^2}{n} \sum_i k_i = 0.

Because the two pieces are uncorrelated, their variances add:

Var{Y^h}=Var{Yˉ}+(XhXˉ)2Var{b1}=σ2n+(XhXˉ)2σ2Sxx=σ2 ⁣(1n+(XhXˉ)2Sxx).\operatorname{Var}\{\hat{Y}_h\} = \operatorname{Var}\{\bar{Y}\} + (X_h - \bar{X})^2 \operatorname{Var}\{b_1\} = \frac{\sigma^2}{n} + (X_h - \bar{X})^2 \frac{\sigma^2}{S_{xx}} = \sigma^2\!\left(\frac{1}{n} + \frac{(X_h - \bar{X})^2}{S_{xx}}\right).

Replacing σ2\sigma^2 by MSE\mathrm{MSE} gives s2{Y^h}s^2\{\hat{Y}_h\}. The tt interval then follows from the same standardize-and-divide argument as in 3.1 The sampling distributions of b0b_0 and b1b_1, since (Y^hE{Yh})/s{Y^h}tn2(\hat{Y}_h - E\{Y_h\})/s\{\hat{Y}_h\} \sim t_{n-2}. \blacksquare

Figure 5 plots s{Y^h}s\{\hat{Y}_h\} against XhX_h: a curve that dips to its minimum at Xˉ=70\bar{X} = 70 and rises symmetrically on both sides. That curve is what gives the confidence band in Figure 1 its gentle bow-tie shape.

Two curves of estimated standard error against lot size. The lower blue curve, for the mean response, is U-shaped, dipping to about 10 at the mean lot size 70 and rising toward the ends. The upper yellow curve, for a new observation, is nearly flat near 49 to 51 across the whole range, always far above the blue curve.

Figure 5:The mean-response standard error (blue) is smallest at the mean lot size and grows toward the extremes. The prediction standard error (yellow) stays near 49 hours everywhere, because it is dominated by a single run’s own scatter, which does not shrink no matter where you predict.

3.5 Prediction interval for a new observation

Intuition

Here is the distinction that trips up more practitioners than any other. The confidence interval of 3.4 Confidence interval for a mean response is about the average run of size XhX_h. But the engineers do not schedule an average run; they schedule one specific run next week, and they want to know where its hours will land. A single run scatters around the mean by its own random error ε\varepsilon, and no amount of data removes that scatter. So predicting a single new observation carries two sources of uncertainty: our uncertainty about where the line is (the same s2{Y^h}s^2\{\hat{Y}_h\} as before), plus the new run’s own irreducible variance σ2\sigma^2. The interval that accounts for both is the prediction interval (Definition 3.6), and it is always wider than the confidence interval.

The whole choice comes down to one question, and Figure 6 lays it out. Ask what you are bounding: the average outcome over many cases at XhX_h, or the outcome of one specific new case. The left answer is a confidence interval; the right answer is a prediction interval. Decide the question first, and the formula follows.

A decision flowchart. A top box reads you have a fitted line and a predictor value X-h, what do you want to bound. Two arrows split downward. The left branch reads the average outcome over many cases at X-h, leading to a confidence interval for the mean, Y-hat-h plus or minus t times s of Y-hat-h, and then to a note that it is narrower and shrinks toward zero as n grows. The right branch reads one specific new case at X-h, leading to a prediction interval for a new case, Y-hat-h plus or minus t times s of pred, and then to a note that it is wider, keeps the case's own scatter sigma squared, and never shrinks to zero.

Figure 6:Pick the interval by naming the question, not by taste. Averaging over many cases at X_h calls for the confidence interval (left, narrow); planning for one new case calls for the prediction interval (right, wide). The only difference in the formula is the extra sigma-squared the new case brings.

Formula

For a new observation Yh(new)Y_{h(\text{new})} at XhX_h, the estimated variance of the prediction error is s2{pred}=MSE(1+1/n+(XhXˉ)2/Sxx)s^2\{\text{pred}\} = \mathrm{MSE}(1 + 1/n + (X_h - \bar{X})^2/S_{xx}), and the prediction interval follows.

In words: this is the mean-response variance with an extra MSE\mathrm{MSE} (the leading 1) added for the new run’s own scatter. That extra term is usually the dominant one, which is why the prediction interval is much wider and why, unlike the confidence interval, it never shrinks to zero even with infinite data.

Derivation

Derivation (variance of a prediction). The quantity we bound is the prediction error Yh(new)Y^hY_{h(\text{new})} - \hat{Y}_h, the gap between the actual new run and our forecast. The new run is Yh(new)=β0+β1Xh+εnewY_{h(\text{new})} = \beta_0 + \beta_1 X_h + \varepsilon_{\text{new}}, and its error εnew\varepsilon_{\text{new}} is independent of the past data that produced Y^h\hat{Y}_h. Two independent pieces, so their variances add:

Var{Yh(new)Y^h}=Var{εnew}σ2+Var{Y^h}σ2(1/n+(XhXˉ)2/Sxx)=σ2 ⁣(1+1n+(XhXˉ)2Sxx).\operatorname{Var}\{Y_{h(\text{new})} - \hat{Y}_h\} = \underbrace{\operatorname{Var}\{\varepsilon_{\text{new}}\}}_{\sigma^2} + \underbrace{\operatorname{Var}\{\hat{Y}_h\}}_{\sigma^2(1/n + (X_h - \bar X)^2/S_{xx})} = \sigma^2\!\left(1 + \frac{1}{n} + \frac{(X_h - \bar{X})^2}{S_{xx}}\right).

Replacing σ2\sigma^2 by MSE\mathrm{MSE} gives s2{pred}s^2\{\text{pred}\}, and standardizing the prediction error by s{pred}s\{\text{pred}\} again yields a tn2t_{n-2} distribution. The tt interval follows. \blacksquare

The gap between the two intervals is not a modeling choice; it is a fact about the two questions, and each interval keeps its own 95% promise. We can check this by simulation, which is the surest way to see that a prediction interval really does trap a new observation 95% of the time. Figure 7 runs the experiment.

Two side-by-side panels, each showing 100 horizontal interval bars for 100 simulated samples at lot size 100. Left panel: narrow confidence intervals for the mean, with a dashed vertical line at the true mean; a few bars in red miss the line. Right panel: much wider prediction intervals, each with a dark dot for an independently drawn new observation; a few bars in red miss their dot. Both panels have only a handful of red misses.

Figure 7:For 100 simulated datasets, the left panel builds a confidence interval for the mean and checks it against the fixed true mean; the right panel builds a prediction interval and checks it against a freshly drawn new run. Both catch their target about 95 times in 100, but the prediction intervals (right) are far wider because they must cover one run’s own scatter.

set.seed(4210)
b0_true <- 62.366; b1_true <- 3.5702; sigma <- 48.82
xh <- 100
mu_h <- b0_true + b1_true * xh
tcrit <- qt(0.975, n - 2)
ci_hits <- 0; pi_hits <- 0; N <- 5000
for (i in 1:N) {
  ysim <- b0_true + b1_true * x + rnorm(n, 0, sigma)
  f <- lm(ysim ~ x)
  pr <- predict(f, data.frame(x = xh), se.fit = TRUE)
  s_mean <- pr$se.fit
  s_pred <- sqrt(pr$se.fit^2 + sum(residuals(f)^2) / (n - 2))
  if (abs(pr$fit - mu_h) <= tcrit * s_mean) ci_hits <- ci_hits + 1
  ynew <- mu_h + rnorm(1, 0, sigma)
  if (abs(pr$fit - ynew) <= tcrit * s_pred) pi_hits <- pi_hits + 1
}
round(c(CI_covers_mean = ci_hits / N, PI_covers_new = pi_hits / N), 4)
CI_covers_mean  PI_covers_new 
        0.9496         0.9458 
from scipy import stats

rng = np.random.default_rng(4210)
b0_true, b1_true, sigma = 62.366, 3.5702, 48.82
xh = 100.0
mu_h = b0_true + b1_true * xh
tcrit = stats.t.ppf(0.975, n - 2)
ci_hits = pi_hits = 0
N = 5000
for _ in range(N):
    ysim = b0_true + b1_true * x + rng.normal(0, sigma, size=n)
    b1s = np.sum((x - x.mean()) * (ysim - ysim.mean())) / Sxx
    b0s = ysim.mean() - b1s * x.mean()
    yhat = b0s + b1s * xh
    mse = np.sum((ysim - (b0s + b1s * x)) ** 2) / (n - 2)
    s_mean = np.sqrt(mse * (1 / n + (xh - x.mean()) ** 2 / Sxx))
    s_pred = np.sqrt(mse * (1 + 1 / n + (xh - x.mean()) ** 2 / Sxx))
    if abs(yhat - mu_h) <= tcrit * s_mean:
        ci_hits += 1
    ynew = mu_h + rng.normal(0, sigma)
    if abs(yhat - ynew) <= tcrit * s_pred:
        pi_hits += 1
print(round(ci_hits / N, 4), round(pi_hits / N, 4))
0.9492 0.9544

Across 5000 simulated datasets, the confidence interval covers the true mean about 95% of the time and the prediction interval covers a fresh new run about 95% of the time. Each interval is honest about its own question. The prediction interval earns its extra width; it is not being cautious for the sake of caution.

The gap between the two intervals is easier to believe once you can open and close it yourself. The widget below puts the sample size and the prediction location under your finger, so you can find out which band answers to more data and which one does not.

What to notice. More data collapses the blue confidence band onto the line, while the amber prediction band barely flinches. Try this. Push nn to 200 with XhX_h at 100, then walk XhX_h back out to 120 and see which band cares where you stand. The formulas behind both are in 3.5 Prediction interval for a new observation.

3.6 The analysis of variance approach

Intuition

There is a second, equivalent way to see the same inference, and it scales up beautifully to the multiple regression of later chapters. The idea is bookkeeping for variation. The response values YiY_i vary; some of that variation the line explains, and some it leaves as residual scatter. If we can split the total variation cleanly into an “explained” part and a “leftover” part, we can compare them, and a big explained part relative to leftover is evidence that the slope is real.

Figure 9 shows the split for a single run: the total deviation from the mean, YiYˉY_i - \bar{Y}, breaks into the part the line accounts for, Y^iYˉ\hat{Y}_i - \bar{Y}, plus the residual, YiY^iY_i - \hat{Y}_i. Remarkably, when you square these and sum over all runs, the cross term vanishes and the totals split just as cleanly.

The Toluca scatterplot with the fitted line and a horizontal dashed line at the mean of Y. One run at the largest lot size is highlighted in red. Three double-headed arrows next to it show the total deviation from the mean split into an explained part, from the mean line up to the fitted line, and a residual part, from the fitted line to the point.

Figure 9:For one highlighted run, the total deviation from the mean (violet) equals the part the line explains (orange, mean up to the fitted line) plus the residual (red, fitted line to the point). Squaring and summing over all runs gives SSTO = SSR + SSE, because the cross term is zero.

Formula

Define the three sums of squares:

i=1n(YiYˉ)2SSTO  =  i=1n(Y^iYˉ)2SSR  +  i=1n(YiY^i)2SSE.\underbrace{\sum_{i=1}^n (Y_i - \bar{Y})^2}_{\mathrm{SSTO}} \;=\; \underbrace{\sum_{i=1}^n (\hat{Y}_i - \bar{Y})^2}_{\mathrm{SSR}} \;+\; \underbrace{\sum_{i=1}^n (Y_i - \hat{Y}_i)^2}_{\mathrm{SSE}} .

In words: the total variation of YY about its mean (SSTO) equals the variation the regression explains (SSR, the spread of the fitted values about the mean) plus the variation it does not (SSE, the error sum of squares from 2.4 Estimating the error variance). Each sum has degrees of freedom: n1n-1 for SSTO, 1 for SSR (one predictor), and n2n-2 for SSE. The degrees of freedom add the same way, n1=1+(n2)n-1 = 1 + (n-2). Dividing each sum of squares by its degrees of freedom gives a mean square (Definition 3.8).

In words: a mean square is a sum of squares averaged over its degrees of freedom, so it is a variance-like number. MSR and MSE are the two we will put in a ratio to test the slope.

Derivation

Derivation (SSTO=SSR+SSE\mathrm{SSTO} = \mathrm{SSR} + \mathrm{SSE}). Split each total deviation by routing it through the fitted value:

YiYˉ=(Y^iYˉ)+(YiY^i).Y_i - \bar{Y} = (\hat{Y}_i - \bar{Y}) + (Y_i - \hat{Y}_i).

Square both sides and sum over ii:

(YiYˉ)2=(Y^iYˉ)2+(YiY^i)2+2(Y^iYˉ)(YiY^i).\sum (Y_i - \bar{Y})^2 = \sum (\hat{Y}_i - \bar{Y})^2 + \sum (Y_i - \hat{Y}_i)^2 + 2\sum (\hat{Y}_i - \bar{Y})(Y_i - \hat{Y}_i).

The cross term is zero. Write YiY^i=eiY_i - \hat{Y}_i = e_i and expand:

(Y^iYˉ)ei=Y^ieiYˉei.\sum (\hat{Y}_i - \bar{Y}) e_i = \sum \hat{Y}_i e_i - \bar{Y} \sum e_i.

Both pieces vanish by the residual identities of 2.3 Fitted values and the properties of residuals: Y^iei=0\sum \hat{Y}_i e_i = 0 (fitted values orthogonal to residuals) and ei=0\sum e_i = 0. So the cross term is zero and SSTO=SSR+SSE\mathrm{SSTO} = \mathrm{SSR} + \mathrm{SSE}. The residual identities we proved in Chapter 2 are doing the work again. \blacksquare

Derivation (expected mean squares). From 2.4 Estimating the error variance we already have E{MSE}=σ2E\{\mathrm{MSE}\} = \sigma^2. A similar expectation calculation, using SSR=b12Sxx\mathrm{SSR} = b_1^2 S_{xx} and E{b12}=Var{b1}+β12=σ2/Sxx+β12E\{b_1^2\} = \operatorname{Var}\{b_1\} + \beta_1^2 = \sigma^2/S_{xx} + \beta_1^2, gives

E{MSR}=E{b12Sxx}=σ2+β12Sxx.E\{\mathrm{MSR}\} = E\{b_1^2 S_{xx}\} = \sigma^2 + \beta_1^2 S_{xx}.

In words: MSE always estimates σ2\sigma^2, while MSR estimates σ2\sigma^2 plus a term that is positive exactly when β10\beta_1 \ne 0. So if the slope is zero, MSR and MSE estimate the same thing and their ratio should be near 1; if the slope is nonzero, MSR is inflated and the ratio is large. That ratio is the FF test. \blacksquare

The ANOVA table collects these quantities in a standard layout. This is the anchor later chapters extend to extra sums of squares (8.3 Extra sums of squares).

3.7 The F test and its equivalence to the t test

Intuition

The ANOVA table hands us a test almost for free. Under H0:β1=0H_0: \beta_1 = 0, both MSR and MSE estimate the same σ2\sigma^2, so their ratio F=MSR/MSEF^{\ast} = \mathrm{MSR}/\mathrm{MSE} hovers near 1. Under Ha:β10H_a: \beta_1 \ne 0, MSR is inflated by β12Sxx\beta_1^2 S_{xx} and the ratio grows. A large FF^{\ast} is evidence against the null.

But we already tested β1=0\beta_1 = 0 with a tt test in 3.2 Inference for the slope and got t=10.29t^{\ast} = 10.29. Do the two tests agree? They do, exactly and always: in simple linear regression the FF statistic is the square of the tt statistic. This is worth proving, because it shows the ANOVA FF test is not a new test, just the tt test wearing different clothes.

Formula

The FF test of H0:β1=0H_0: \beta_1 = 0 uses

F=MSRMSEF1,n2 under H0,F^{\ast} = \frac{\mathrm{MSR}}{\mathrm{MSE}} \sim F_{1,\,n-2} \text{ under } H_0,

and rejects H0H_0 when F>F1α;1,n2F^{\ast} > F_{1-\alpha;\,1,\,n-2}. The claimed identity is

F=(t)2,F^{\ast} = (t^{\ast})^2,

where t=b1/s{b1}t^{\ast} = b_1/s\{b_1\} is the slope tt statistic. In words: the FF statistic and the squared tt statistic are the same number, and the tests give identical p-values.

Derivation

Derivation (F=(t)2F^{\ast} = (t^{\ast})^2). Start from the regression sum of squares. Since Y^iYˉ=b1(XiXˉ)\hat{Y}_i - \bar{Y} = b_1 (X_i - \bar{X}),

SSR=(Y^iYˉ)2=b12(XiXˉ)2=b12Sxx.\mathrm{SSR} = \sum (\hat{Y}_i - \bar{Y})^2 = b_1^2 \sum (X_i - \bar{X})^2 = b_1^2 S_{xx}.

With one regression degree of freedom, MSR=SSR=b12Sxx\mathrm{MSR} = \mathrm{SSR} = b_1^2 S_{xx}. Therefore

F=MSRMSE=b12SxxMSE.F^{\ast} = \frac{\mathrm{MSR}}{\mathrm{MSE}} = \frac{b_1^2 S_{xx}}{\mathrm{MSE}}.

Now write the tt statistic and square it, using s2{b1}=MSE/Sxxs^2\{b_1\} = \mathrm{MSE}/S_{xx}:

(t)2=(b1s{b1})2=b12MSE/Sxx=b12SxxMSE=F.(t^{\ast})^2 = \left(\frac{b_1}{s\{b_1\}}\right)^2 = \frac{b_1^2}{\mathrm{MSE}/S_{xx}} = \frac{b_1^2 S_{xx}}{\mathrm{MSE}} = F^{\ast}.

The two expressions are literally the same. Distributionally this matches a standard fact: the square of a tn2t_{n-2} random variable is an F1,n2F_{1,\,n-2} random variable, so squaring the slope tt statistic lands on the ANOVA FF statistic, and the critical values match too, F1α;1,n2=(t1α/2,n2)2F_{1-\alpha;\,1,n-2} = (t_{1-\alpha/2,\,n-2})^2. \blacksquare

Figure 10 confirms the distributional half: square 200,000 draws from a t23t_{23} and the histogram lands on the F1,23F_{1,23} density, with the 5% critical value 4.28 equal to 2.0692.

A histogram of squared t values with 23 degrees of freedom, piled up near zero and decaying to the right. A red F-distribution density with 1 and 23 degrees of freedom traces the histogram exactly. A dotted vertical line marks the 5% critical value at 4.28, labeled as 2.069 squared.

Figure 10:Squaring a t with 23 degrees of freedom produces exactly an F with 1 and 23 degrees of freedom. The 5% critical value 4.28 is the square of the t critical value 2.069, so the F test and the two-sided t test reject in identical situations.

The algebra above is three lines long, but the identity is far more convincing when you get to break the data yourself and the two numbers still refuse to disagree.

What to notice. FF^{\ast} and (t)2(t^{\ast})^2 come off two different tables of the printout and agree to every digit shown, no matter where the points sit. Try this. Drag a point until the line flattens, then keep going until b1b_1 turns negative, and watch what squaring throws away. The proof is in 3.7 The F test and its equivalence to the t test.

3.8 R-squared and its interpretation

Intuition

The ANOVA split invites a natural summary: what fraction of the total variation did the line explain? That fraction is R2R^2, the coefficient of determination (Definition 3.12). It runs from 0 (the line explains nothing beyond the mean) to 1 (the line passes through every point). It is the single most reported and most misread number in regression, so we will state plainly what it does and does not mean.

Formula

In words: R2R^2 is the proportion of the total variation in YY that the regression on XX accounts for. In simple linear regression it also equals r2r^2, the square of the Pearson correlation between XX and YY, a link Chapter 4 develops (4.2 Correlation and the regression slope).

Figure 12 shows the two ingredients: the total scatter of hours about their mean (SSTO, left) shrinks to the much smaller residual scatter about the line (SSE, right). R2R^2 is how much of the vertical spread the line removed.

Two side-by-side scatterplots of the Toluca data. Left: points with a horizontal line at the mean of Y and long vertical red segments from each point to the mean, labeled total variation SSTO = 307,203. Right: the same points with the fitted line and much shorter orange vertical segments from each point to the line, labeled leftover SSE = 54,825.

Figure 12:Left: the hours vary widely about their own mean (SSTO). Right: once lot size is in the model, the leftover scatter about the line (SSE) is much smaller. R-squared = 1 minus SSE/SSTO = 0.82 is the fraction of the vertical spread the line removed.

3.9 A confidence band for the whole line

Intuition

The confidence interval of 3.4 Confidence interval for a mean response is honest about one lot size you name in advance. But often you want to draw a band around the entire fitted line and claim, with 95% confidence, that the true line lies inside it everywhere at once. If you simply string together the pointwise intervals, the simultaneous confidence is less than 95%, because you are making many claims and some will fail by chance. The Working-Hotelling band (Definition 3.13) fixes this by using a slightly larger multiplier, so the whole-line claim holds at the stated level.

Formula

In words: the band has the same center and the same standard error s{Y^h}s\{\hat{Y}_h\} as the pointwise interval, but the multiplier WW replaces t1α/2,n2t_{1-\alpha/2,\,n-2}. Because W>tW > t, the band is a little wider everywhere, and that extra width buys simultaneous coverage of the true line at all XhX_h at once. The multiplier uses FF with 2 numerator degrees of freedom because the line has two parameters, β0\beta_0 and β1\beta_1, that can both vary.

W <- sqrt(2 * qf(0.95, 2, n - 2))
round(c(W = W, t = qt(0.975, n - 2)), 4)
     W      t 
2.6162 2.0687 
W = np.sqrt(2 * stats.f.ppf(0.95, 2, n - 2))
print(round(W, 4), round(stats.t.ppf(0.975, n - 2), 4))
2.6162 2.0687

For Toluca the whole-line multiplier is W=2.62W = 2.62 against the pointwise t=2.07t = 2.07, so the simultaneous band is about 26% wider than a single-point interval. Figure 13 draws both.

The Toluca scatterplot with the fitted line, a pair of dashed blue curves for the pointwise 95% confidence interval, and a wider shaded orange band for the Working-Hotelling simultaneous band. Both are narrowest at the mean lot size and flare toward the ends, with the orange band always outside the dashed curves.

Figure 13:The pointwise confidence interval (dashed) is honest about a single chosen lot size. The Working-Hotelling band (shaded) is wider by the factor W/t = 2.62/2.07 and is honest about the entire line at once. Use the wider band when you will read the fitted line at several places.

3.10 A prediction-focused example: advertising and sales

To see the machinery on a fresh dataset, turn to the advertising data: 200 markets’ TV advertising budgets and the resulting product sales (thousands of units). A manager wants to predict sales for a new market that will receive a TV budget of 150 thousand dollars, and to understand the average effect of the budget.

Figure 14 draws both bands. Notice the prediction band comfortably contains almost all 200 markets, while the confidence band, being about the mean, does not.

A scatterplot of 200 markets, sales on the vertical axis against TV advertising budget on the horizontal axis, with an upward-sloping fitted line. A narrow inner blue band hugs the line; a wide outer yellow prediction band contains almost every point. The scatter of points widens somewhat at larger TV budgets.

Figure 14:The advertising data with the fitted line, a narrow confidence band for mean sales (inner blue), and a wide prediction band for a single new market (outer yellow). The prediction band contains nearly all 200 markets; the confidence band is only about the average and contains few of them.

3.11 Chapter summary

You can now do inference for a simple linear regression, not just fit it. You saw why the standardized slope and intercept follow a tt distribution with n2n-2 degrees of freedom, and used it to build confidence intervals and hypothesis tests for both coefficients (the Toluca slope, t=10.29t^{\ast} = 10.29, 95% CI (2.85,4.29)(2.85, 4.29)). You learned to tell a confidence interval for a mean response from a prediction interval for a single new observation, to derive both variance formulas, and, above all, to say which one a question needs: for a 100-unit run the mean interval is (390,449)(390, 449) but the single-run prediction interval is (314,525)(314, 525). You derived the ANOVA decomposition, built the table, ran the FF test (F=105.9F^{\ast} = 105.9), and proved it is the slope tt test squared. You can read R2=0.82R^2 = 0.82 correctly and widen a pointwise interval into a Working-Hotelling band (W=2.62W = 2.62) when you need the whole line.

Key results at a glance.

ResultStatement or formulaValid when
Sampling distributions of b0,b1b_0, b_1 (Theorem 3.2)(b1β1)/s{b1}tn2(b_1 - \beta_1)/s\{b_1\} \sim t_{n-2}, (b0β0)/s{b0}tn2(b_0 - \beta_0)/s\{b_0\} \sim t_{n-2}SLR model with normal errors
Confidence interval for the slope (Def. 3.3)b1±t1α/2,n2s{b1}b_1 \pm t_{1-\alpha/2,\,n-2}\, s\{b_1\}same; test H0:β1=0H_0:\beta_1=0 via t=b1/s{b1}t^{\ast}=b_1/s\{b_1\}
Variance of the fitted mean (Theorem 3.5)s2{Y^h}=MSE(1/n+(XhXˉ)2/Sxx)s^2\{\hat{Y}_h\} = \mathrm{MSE}(1/n + (X_h-\bar{X})^2/S_{xx})mean response E{Yh}E\{Y_h\} at fixed XhX_h
Confidence interval for a mean response (Def. 3.4)Y^h±t1α/2,n2s{Y^h}\hat{Y}_h \pm t_{1-\alpha/2,\,n-2}\, s\{\hat{Y}_h\}averaging over many cases at XhX_h
Variance of a prediction (Theorem 3.7)s2{pred}=MSE(1+1/n+(XhXˉ)2/Sxx)s^2\{\text{pred}\} = \mathrm{MSE}(1 + 1/n + (X_h-\bar{X})^2/S_{xx})new case’s error independent of the fit
Prediction interval (Def. 3.6)Y^h±t1α/2,n2s{pred}\hat{Y}_h \pm t_{1-\alpha/2,\,n-2}\, s\{\text{pred}\}one single new observation at XhX_h
ANOVA decomposition (Theorem 3.9)SSTO=SSR+SSE\mathrm{SSTO} = \mathrm{SSR} + \mathrm{SSE}, df n1=1+(n2)n-1 = 1 + (n-2)least-squares fit with an intercept
Expected mean squares (Theorem 3.10)E{MSE}=σ2E\{\mathrm{MSE}\}=\sigma^2, E{MSR}=σ2+β12SxxE\{\mathrm{MSR}\}=\sigma^2+\beta_1^2 S_{xx}SLR model
FF test and F=t2F = t^2 (Theorem 3.11)F=MSR/MSEF1,n2F^{\ast}=\mathrm{MSR}/\mathrm{MSE}\sim F_{1,\,n-2}, F=(t)2F^{\ast}=(t^{\ast})^2normal errors; testing H0:β1=0H_0:\beta_1=0
Coefficient of determination (Def. 3.12)R2=SSR/SSTO=1SSE/SSTO=r2R^2 = \mathrm{SSR}/\mathrm{SSTO} = 1 - \mathrm{SSE}/\mathrm{SSTO} = r^2describes variation explained, not fit correctness
Working-Hotelling band (Def. 3.13)Y^h±Ws{Y^h}\hat{Y}_h \pm W\, s\{\hat{Y}_h\}, W2=2F1α;2,n2W^2 = 2 F_{1-\alpha;\,2,\,n-2}simultaneous coverage of the whole line

Key terms. Estimated standard error, confidence interval for the slope, hypothesis test for the slope, confidence interval for a mean response, prediction interval, analysis of variance, total sum of squares, regression sum of squares, mean square, FF test, coefficient of determination, Working-Hotelling confidence band, degrees of freedom.

You should now be able to:

Where this fits. In the workflow spine of The modeling workflow (ASK, EXPLORE, FIT, CHECK, USE), this chapter is the heart of the USE stage: it turns a fitted line into decisions and honest forecasts with stated uncertainty. Chapter 2 gave the point estimates; here we attached intervals and tests. The prediction interval (3.5 Prediction interval for a new observation) returns in Chapter 12 when we validate models on held-out data and in Chapter 15 when we forecast, where we will confront why time-ordered data makes prediction intervals harder. The ANOVA table (3.6 The analysis of variance approach) and the FF test (3.7 The F test and its equivalence to the t test) generalize in Chapter 8 into the extra-sums-of-squares machinery (8.3 Extra sums of squares) and the general linear test (8.4 The general linear test), which can compare whole models at once. And the tiny slope p-value here is the benchmark Chapter 5 checks against a permutation test that assumes no normality at all (5.2 The permutation test for the slope), asking whether our tt-based conclusion survives without the normal error model.

3.12 Frequently asked questions

Q1. What is the one-sentence difference between a confidence interval and a prediction interval? A confidence interval is for the mean response at XhX_h, averaged over all cases at that predictor value; a prediction interval is for a single new case, and is wider because it must also cover that case’s own random scatter σ2\sigma^2.

Q2. Why does the interval widen as XhX_h moves away from Xˉ\bar{X}? Because the variance of the fitted mean carries a (XhXˉ)2/Sxx(X_h - \bar{X})^2/S_{xx} term. Away from the center, a small change in the estimated slope pivots the line a large vertical distance, so the fitted value there is less certain. Every fitted line passes through (Xˉ,Yˉ)(\bar{X}, \bar{Y}), so the uncertainty is smallest there.

Q3. Why use tt and not the normal distribution? Because we estimate σ\sigma with s=MSEs = \sqrt{\mathrm{MSE}} rather than knowing it. That extra estimation makes the reference distribution tn2t_{n-2}, with heavier tails than the normal. For large nn the two nearly coincide, but for n=25n = 25 the difference matters.

Q4. The FF test and the tt test gave the same p-value. Do I need both? In simple linear regression, no: F=(t)2F^{\ast} = (t^{\ast})^2, so they are one test. Report the tt test for a single slope because it keeps the direction (sign) of the effect. The FF test earns its keep in multiple regression, where it can test several coefficients simultaneously.

Q5. My R2R^2 is high. Does that mean my model is good? Not by itself. A high R2R^2 can accompany a curved relationship, non-constant variance, or influential outliers, all of which a residual plot would reveal. R2R^2 measures variation explained, not correctness, not prediction accuracy, and not causation. Read it alongside ss and diagnostic plots (Chapter 9).

Q6. Can I use these intervals to predict hours for a lot of 500 units? No. That is extrapolation far beyond the data range (20 to 120 units). The formulas will happily produce an interval, but its stated confidence assumes the straight-line model holds out there, which the data cannot support. Trust intervals only inside, or just barely outside, the observed range of XX.

Q7. What exactly does “95% confident” mean for the slope interval? It means the procedure traps the true slope in 95% of repeated samples, as Figure 15 shows with 100 simulated intervals. For your one interval (2.85,4.29)(2.85, 4.29), the true slope is either in it or not; the 95% describes the long-run reliability of the method, not a probability about this particular interval.

One hundred horizontal confidence-interval bars stacked vertically, one per simulated sample, each a 95% interval for the slope. A dashed vertical line marks the true slope 3.57. Almost all bars cross the line; a small number that miss it are drawn in red.

Figure 15:The meaning of 95% confidence: across 100 simulated samples, about 95 of the 95% intervals cover the true slope (blue) and a few miss (red). Any one interval either covers the truth or does not; the 95% is a property of the procedure over repeated sampling.

3.13 Practice problems

  1. (A) In one sentence each, state what a confidence interval for the mean response and a prediction interval for a new observation are about, and say which is wider and why.

  2. (A) The slope’s 95% confidence interval is (2.85,4.29)(2.85, 4.29). Explain what “95% confident” means here, and what it does not mean.

  3. (A) Explain why the confidence interval for a mean response is narrowest at Xh=XˉX_h = \bar{X} and widens on both sides.

  4. (A) Why does inference for the slope use a tt distribution with n2n-2 degrees of freedom rather than a standard normal? Where do the n2n-2 degrees of freedom come from?

  5. (A) A report states “R2=0.82R^2 = 0.82, so the model is correct.” Give two distinct reasons this conclusion does not follow.

  6. (A) The intercept’s 95% interval (8.21,116.52)(8.21, 116.52) is enormously wide compared with the slope’s. Explain why, referring to where X=0X = 0 sits relative to the data.

  7. (A) In simple linear regression the ANOVA FF test and the slope tt test always agree. State the exact relationship between the two statistics and one reason to still report the tt test.

  8. (A) A colleague uses a 95% confidence interval for the mean response to budget a single upcoming production run. Explain why this understates the risk, and which interval they should use.

  9. (B) Derive the tt statistic (b1β1)/s{b1}tn2(b_1 - \beta_1)/s\{b_1\} \sim t_{n-2} (Theorem 3.2), stating clearly which facts you take from Chapter 2, which you take on faith until Chapter 7, and why the combination is a tt.

  10. (B) Derive Var{Y^h}=σ2(1/n+(XhXˉ)2/Sxx)\operatorname{Var}\{\hat{Y}_h\} = \sigma^2(1/n + (X_h - \bar{X})^2/S_{xx}) (Theorem 3.5), including the step that Yˉ\bar{Y} and b1b_1 are uncorrelated.

  11. (B) Derive the prediction-error variance σ2(1+1/n+(XhXˉ)2/Sxx)\sigma^2(1 + 1/n + (X_h - \bar{X})^2/S_{xx}) (Theorem 3.7), explaining where the leading 1 comes from and why the new error is independent of Y^h\hat{Y}_h.

  12. (B) Prove the ANOVA identity SSTO=SSR+SSE\mathrm{SSTO} = \mathrm{SSR} + \mathrm{SSE} (Theorem 3.9) by showing the cross term vanishes, naming the residual identities you use.

  13. (B) Prove that F=(t)2F^{\ast} = (t^{\ast})^2 in simple linear regression (Theorem 3.11), starting from SSR=b12Sxx\mathrm{SSR} = b_1^2 S_{xx}.

  14. (B) Show that E{MSR}=σ2+β12SxxE\{\mathrm{MSR}\} = \sigma^2 + \beta_1^2 S_{xx} (Theorem 3.10), and explain why this makes MSR/MSE\mathrm{MSR}/\mathrm{MSE} a sensible test statistic for H0:β1=0H_0: \beta_1 = 0.

  15. (B) Show that a 100(1α)%100(1-\alpha)\% confidence interval for β1\beta_1 excludes 0 exactly when the two-sided tt test of H0:β1=0H_0: \beta_1 = 0 rejects at level α\alpha.

  16. (B) Starting from R2=1SSE/SSTOR^2 = 1 - \mathrm{SSE}/\mathrm{SSTO} and SSE=Syyb12Sxx\mathrm{SSE} = S_{yy} - b_1^2 S_{xx}, show that R2=b12Sxx/SyyR^2 = b_1^2 S_{xx}/S_{yy}, and hence that R2=r2R^2 = r^2 where r=Sxy/SxxSyyr = S_{xy}/\sqrt{S_{xx}S_{yy}}.

  17. (B) The Working-Hotelling multiplier is W=2F1α;2,n2W = \sqrt{2 F_{1-\alpha;2,n-2}} and the pointwise multiplier is t1α/2,n2t_{1-\alpha/2,n-2}. Explain, without a full proof, why WW must exceed tt and what the extra width buys.

  18. (B) Show that the prediction interval half-width never shrinks below tst\, s even as nn \to \infty, while the confidence-interval half-width shrinks to 0. What does this say about the limits of prediction?

  19. (C) Fit the Toluca model in R or Python. Reproduce the slope’s tt statistic, its p-value, and its 95% confidence interval, and confirm they match the values in this chapter.

  20. (C) Compute a 95% confidence interval for the mean hours at Xh=40X_h = 40 units and at Xh=90X_h = 90 units. Which is wider, and does the difference match the (XhXˉ)2(X_h - \bar{X})^2 rule?

  21. (C) Compute both the 95% confidence interval for the mean and the 95% prediction interval for a new run at Xh=50X_h = 50 units. Report the ratio of their widths and explain it.

  22. (C) Build the ANOVA table for Toluca in software. From it, extract SSR\mathrm{SSR}, SSE\mathrm{SSE}, MSR\mathrm{MSR}, MSE\mathrm{MSE}, and FF^{\ast}, and verify F=(t)2F^{\ast} = (t^{\ast})^2 using the slope tt from problem 19.

  23. (C) Using the advertising data, fit sales ~ TV, test the slope, and give a 95% prediction interval for a new market with a TV budget of 200. Interpret the interval for a manager.

  24. (C) Write a seeded simulation (seed 4210, 2000 datasets from the fitted Toluca model at the observed lot sizes) that checks the empirical coverage of the 95% confidence interval for the mean at Xh=60X_h = 60. Report the coverage and compare it with 0.95.

  25. (C) Reproduce the Working-Hotelling multiplier WW and the pointwise tt multiplier for Toluca. Then compute both the pointwise 95% interval and the Working-Hotelling band half-width at Xh=120X_h = 120, and report the ratio.

  26. (C) Regress hours ~ lotsize and make a plot of the fitted line with the 95% confidence band and the 95% prediction band (as in Figure 1). Describe how the two bands differ in width and shape.

  27. (B) A student claims that because F=105.9F^{\ast} = 105.9 is “huge,” the model must predict individual runs accurately. Explain the confusion between the FF test (about the slope) and prediction accuracy (about ss and the prediction interval), using the Toluca numbers.

  28. (C) Using the advertising data, compute R2R^2 two ways: from the ANOVA sums of squares and as the square of the correlation cor(adv$TV, adv$sales). Confirm they match, and interpret the value.

3.14 Exam practice

The problems above build skills one at a time. Exams ask you to combine them and, above all, to explain in full sentences: to read software output in context, to judge a claim, and to say what would change under a new condition. The five problems below are written in that exam voice. Work each one as if for full marks, in complete sentences, before opening the model answer. A bare number or a one-word verdict earns little credit on the real thing; the reasoning is the answer.

EP 3.1 (interpret output in context). A production scheduler has one specific new run of 80 units on next week’s calendar. Software fits the Toluca model and returns two intervals at a lot size of 80.

predict(fit, data.frame(lotsize = 80), interval = "confidence")
predict(fit, data.frame(lotsize = 80), interval = "prediction")
      fit      lwr      upr
1 347.982 326.5449 369.4191
      fit      lwr      upr
1 347.982 244.7333 451.2307
pr = fit.get_prediction(pd.DataFrame({"lotsize": [80]}))
print("mean CI ", pr.conf_int(alpha=0.05))
print("pred PI ", pr.conf_int(obs=True, alpha=0.05))
mean CI  [[326.54493825 369.41910215]]
pred PI  [[244.73334785 451.23069256]]

Interpret each interval in one sentence, with units and in the context of this problem. Then the scheduler proposes to budget next week’s single run at “between 327 and 369 hours, 95% sure,” using the first interval. Explain in full sentences whether that is the right interval to use, which one the scheduler should use instead, and why the two intervals differ by so much.

EP 3.2 (a student claims X, evaluate). A classmate writes: “Under the normal-error model the slope estimate b1b_1 is exactly normal, so a 95% confidence interval for the slope should use the standard normal multiplier 1.96.” The chapter instead uses t0.975,23=2.069t_{0.975,\,23} = 2.069. Explain in full sentences what is right and what is wrong in the classmate’s reasoning, what specific step forces the switch from 1.96 to 2.069, and what happens to the gap between the two multipliers as the sample size grows.

EP 3.3 (interpret output in context, evaluate a claim). The advertising data record TV budgets and sales for n=200n = 200 markets. Fitting sales ~ TV gives the output below.

summary(fit_adv)$coefficients
anova(fit_adv)
c(R2 = summary(fit_adv)$r.squared, s = summary(fit_adv)$sigma)
             Estimate Std. Error  t value Pr(>|t|)
(Intercept)  7.032594 0.45784294 15.36028        0
TV           0.047537 0.00269061 17.66763        0
           Df Sum Sq Mean Sq F value    Pr(>F)
TV          1 3314.6  3314.6  312.14 < 2.2e-16
Residuals 198 2102.5    10.6
        R2          s 
    0.6119     3.2587 
print(sm.stats.anova_lm(fit_adv))
print(round(fit_adv.rsquared, 4), round(np.sqrt(fit_adv.scale), 4))
             df       sum_sq      mean_sq           F        PR(>F)
TV          1.0  3314.618167  3314.618167  312.144994  1.467390e-42
Residual  198.0  2102.530583    10.618841           NaN           NaN
0.6119 3.2587

First, verify from the numbers that the FF statistic equals the square of the TV slope’s tt statistic, and explain in one sentence why that identity must hold here. Then a manager reads F=312F = 312 and R2=0.61R^2 = 0.61 and concludes, “the model is so significant that it will predict any one market’s sales to within a unit or two.” Explain in full sentences what the large FF actually establishes, what R2=0.61R^2 = 0.61 means, and which number in the output governs how far a single new market can fall from the line.

EP 3.4 (what would change if). Suppose the Toluca engineers gathered far more production data at the same spread of lot sizes, so that the sample size nn grows very large while SxxS_{xx} grows in proportion and MSE\mathrm{MSE} stays near 2384. Explain in full sentences what happens, as nn \to \infty, to (a) the width of the 95% confidence interval for the mean hours at Xh=100X_h = 100, and (b) the width of the 95% prediction interval for a single new 100-unit run. Say why the two behave differently, and what that difference reveals about the limits of prediction.

EP 3.5 (interpret a figure, explain why). Figure 5 plots two estimated-standard-error curves against lot size: the mean-response standard error s{Y^h}s\{\hat{Y}_h\} (blue) dips to a minimum near the mean lot size of 70 and rises toward both ends, while the prediction standard error s{pred}s\{\text{pred}\} (yellow) stays nearly flat near 49 hours across the whole range and sits above the blue curve everywhere. Explain in full sentences (a) why the blue curve is U-shaped with its lowest point at Xˉ\bar{X}, and (b) why the yellow curve barely bends even though it lies above the blue one at every lot size.

3.15 Chapter game