Unit 9, lesson 63

Inference for a Regression Slope

How the simple linear regression model separates errors from residuals, and how the residual standard deviation and the standard error of the slope give a t test and a confidence interval for the slope.

  • Video 63
  • Simple Linear Regression

Six constructed observations give a least-squares slope of exactly 2. Another sample from the same process would give a different slope, so how far from 2 could the slope of the process itself plausibly be, and is there evidence that it differs from zero? The least-squares calculation alone cannot say. An answer needs a model for how responses vary around their mean. This lesson states that model, estimates its error variance, and builds the standard error, the t test and the confidence interval for the slope, together with the conditions each one relies on.

Key terms

Simple linear regression model

Definition The simple linear regression model says that the responses at predictor values x1,…,xnx_1, \dots, x_n satisfy

Yi=β0+β1xi+εiY_i = \beta_0 + \beta_1 x_i + \varepsilon_i

for i=1,…,ni = 1, \dots, n, where β0\beta_0 and β1\beta_1 are unknown parameters and the εi\varepsilon_i are random errors. Exact classical inference adds four conditions, all given the predictor values. The errors have mean zero, so that the mean response is the line E(Y∣x)=β0+β1xE(Y \mid x) = \beta_0 + \beta_1 x. They are independent. They share one variance σ2\sigma^2. And they are normally distributed. Together these say that the εi\varepsilon_i are independent with distribution N(0,σ2)N(0, \sigma^2). The predictor values are treated as fixed, or the analysis is carried out conditional on them, and at least two of them must differ. The slope β1\beta_1 is the change in the mean response per unit increase in xx.

In plain words The model splits each response into a systematic part on an unknown straight line and a random part. The least-squares line estimates the unknown line, and inference asks how far the estimate could be from it. The conditions concern the errors and the design. The predictor values themselves need not follow a normal distribution or any other. The slope β1\beta_1 describes how the mean response differs across predictor values, and it is a causal effect only when the design supports that reading.

Example Suppose a process followed the model with β0=1\beta_0 = 1, β1=2\beta_1 = 2 and σ=1\sigma = 1 at the predictor values 0,1,2,3,4,50, 1, 2, 3, 4, 5. The response at x=3x = 3 would then be normal with mean 7 and standard deviation 1. Each run of the process would give six new responses and a new least-squares slope, and over many runs those slopes would center on 2 with standard deviation 1/17.5≈0.2391/\sqrt{17.5} \approx 0.239. In practice β0\beta_0, β1\beta_1 and σ\sigma are unknown, and the analysis has to work from one sample.

Error term

Definition In the simple linear regression model, the error term of observation ii is

εi=Yi−(β0+β1xi),\varepsilon_i = Y_i - (\beta_0 + \beta_1 x_i),

the deviation of the response from the unknown population mean line. It cannot be observed, because β0\beta_0 and β1\beta_1 are unknown. The residual ei=yi−(b0+b1xi)e_i = y_i - (b_0 + b_1 x_i) is the deviation from the fitted line and serves as an estimate of the error. The two differ. The residuals of a fit with an intercept satisfy ∑ei=0\sum e_i = 0 and ∑xiei=0\sum x_i e_i = 0, while the errors need not sum to zero. Under the model each residual has variance σ2(1−hi)\sigma^2(1 - h_i), where hih_i is its hat value, and this is smaller than the error variance σ2\sigma^2.

In plain words The error is the miss relative to the true line, and the residual is the miss relative to the line fitted to the same data. The fitted line is chosen to be as close as possible to these particular points, so the sum of squared residuals is never larger than the sum of squared errors.

Example The constructed sample has x=0,1,2,3,4,5x = 0, 1, 2, 3, 4, 5 and y=2,2,5,7,8,12y = 2, 2, 5, 7, 8, 12. Its least-squares line is y^=1+2x\hat{y} = 1 + 2x, with residuals 1,−1,0,0,−1,11, -1, 0, 0, -1, 1, which add to zero and have squared sum 4. Suppose, only for illustration, that the population line were 0.5+2.1x0.5 + 2.1x, something nobody could learn from the data. The errors would then be 1.5,−0.6,0.3,0.2,−0.9,1.01.5, -0.6, 0.3, 0.2, -0.9, 1.0. They add to 1.5, not zero, and their squares add to 4.55, more than 4.

Residual standard deviation

Definition For a least-squares line fitted to n≥3n \ge 3 observations, the residual standard deviation is

s=SSEn−2,s = \sqrt{\frac{\text{SSE}}{n - 2}} ,

where SSE is the residual sum of squares. The divisor n−2n - 2 is the number of residual degrees of freedom. The nn residuals must satisfy the two equations ∑ei=0\sum e_i = 0 and ∑xiei=0\sum x_i e_i = 0, one for each estimated coefficient. When the conditional mean is linear and the errors are independent with common variance σ2\sigma^2, the residual variance s2s^2 is an unbiased estimator of σ2\sigma^2, whether or not the errors are normal. The value ss is in response units and estimates σ\sigma. It is not the sample standard deviation sys_y of the responses.

In plain words The residual standard deviation estimates how far responses typically fall from the mean line. Dividing by n−2n - 2 instead of nn makes up for the fact that the fitted line was chosen to be close to these very points. The sample standard deviation of the responses measures spread around the overall mean yˉ\bar{y} and ignores the predictor, so the two answer different questions.

Example For the six observations, SSE=4\text{SSE} = 4 with n−2=4n - 2 = 4 degrees of freedom, so s2=4/4=1s^2 = 4/4 = 1 and s=1s = 1 response unit. The sample standard deviation of the responses is sy=74/5≈3.85s_y = \sqrt{74/5} \approx 3.85. Most of the variation in the responses follows the line, and R2=1−4/74≈0.946R^2 = 1 - 4/74 \approx 0.946.

Standard error of the slope

Definition Under the simple linear regression model with independent errors of common variance σ2\sigma^2, the least-squares slope b1b_1 has mean β1\beta_1 and standard deviation σ/Sxx\sigma/\sqrt{S_{xx}} over repeated samples at the same predictor values, where Sxx=∑(xi−xˉ)2S_{xx} = \sum (x_i - \bar{x})^2. Replacing σ\sigma by the residual standard deviation ss gives the standard error of the slope,

SE⁡(b1)=sSxx.\operatorname{SE}(b_1) = \frac{s}{\sqrt{S_{xx}}} .

It has the units of the slope, response units per predictor unit.

In plain words The slope is pinned down better when the points scatter less around the line and when the predictor values are more spread out. Doubling ss doubles the standard error. Quadrupling SxxS_{xx} halves it, for example by placing the same number of predictor values twice as far from their mean, as long as the straight-line model still holds over the wider range. Changing the unit of xx rescales the slope and its standard error by the same factor and adds no information. The standard error describes how much the fitted slope would vary between samples, not how much individual responses vary.

Example For the six observations, Sxx=17.5S_{xx} = 17.5 and s=1s = 1, so

SE⁡(b1)=117.5≈0.239\operatorname{SE}(b_1) = \frac{1}{\sqrt{17.5}} \approx 0.239

response units per predictor unit. Spreading the six predictor values to 0,2,4,6,8,100, 2, 4, 6, 8, 10 would give Sxx=70S_{xx} = 70 and, with the same ss, a standard error of 1/70≈0.1201/\sqrt{70} \approx 0.120, half as large. Crowding them into 2,2.5,3,3.5,4,4.52, 2.5, 3, 3.5, 4, 4.5 would give Sxx=4.375S_{xx} = 4.375 and a standard error of about 0.4780.478, twice as large.

t test for a slope

Definition To test H0 ⁣:β1=β1,0H_0\colon \beta_1 = \beta_{1,0}, most often with β1,0=0\beta_{1,0} = 0, compute

t=b1−β1,0SE⁡(b1).t = \frac{b_1 - \beta_{1,0}}{\operatorname{SE}(b_1)} .

If H0H_0 and the conditions of the simple linear regression model hold, the statistic has the t distribution with n−2n - 2 degrees of freedom, written tn−2t_{n-2}. For the two-sided alternative H1 ⁣:β1≠β1,0H_1\colon \beta_1 \ne \beta_{1,0} the p-value is 2P(T≥∣t∣)2P(T \ge \lvert t \rvert) with T∼tn−2T \sim t_{n-2}. It is the probability, computed assuming H0H_0 and the model, of a t statistic at least as far from zero as the one observed. For β1,0=0\beta_{1,0} = 0 the statistic equals rn−2/1−r2r\sqrt{n - 2}/\sqrt{1 - r^2} when ∣r∣<1\lvert r \rvert < 1, so for pairs sampled at random from a bivariate normal population the same statistic tests whether the population correlation is zero.

In plain words The t statistic counts how many standard errors the fitted slope lies from the hypothesized value. A small p-value says that data like these would be unusual if the model held with that slope. It is not the probability that H0H_0 is true, and it does not show that the predictor causes the response, since confounding, selection or a wrong form of the model can produce a nonzero slope. A large p-value does not show that the slope is zero, only that these data do not rule zero out. A zero slope means no linear trend in the mean, not no relationship, since a symmetric curve can have a least-squares slope of zero.

Example For the six observations, test H0 ⁣:β1=0H_0\colon \beta_1 = 0 against H1 ⁣:β1≠0H_1\colon \beta_1 \ne 0. The statistic is

t=2−01/17.5=70≈8.367\begin{aligned} t &= \frac{2 - 0}{1/\sqrt{17.5}} \\[0.4em] &= \sqrt{70} \approx 8.367 \end{aligned}

with 4 degrees of freedom, and the two-sided p-value is about 0.0011. If the model held with a zero slope, a t statistic at least this far from zero would occur in about 0.11 percent of samples. That is strong evidence against a zero slope within this model, and it says nothing about why the responses rise with xx.

Confidence interval for a slope

Definition Under the same conditions, the confidence interval for β1\beta_1 with level 1−α1 - \alpha is

b1±t1−α/2, n−2SE⁡(b1),b_1 \pm t_{1-\alpha/2,\, n-2} \operatorname{SE}(b_1) ,

where t1−α/2, n−2t_{1-\alpha/2,\, n-2} is the 1−α/21 - \alpha/2 quantile of tn−2t_{n-2}. Over repeated samples at the same predictor values, the procedure captures β1\beta_1 in a proportion 1−α1 - \alpha of the samples. The interval leaves out a value β1,0\beta_{1,0} exactly when the two-sided t test of H0 ⁣:β1=β1,0H_0\colon \beta_1 = \beta_{1,0} gives p<αp < \alpha. Its endpoints are in response units per predictor unit.

In plain words The interval lists the model slopes that are compatible with the data at the chosen level. The 95 percent describes how often the method succeeds over repeated samples. It is not a 95 percent probability that this particular interval contains β1\beta_1, and the interval does not mark where 95 percent of the responses or of the fitted slopes fall. Whether the slopes in it matter in practice depends on the units and the application.

Example For the six observations, t0.975,4≈2.776t_{0.975, 4} \approx 2.776, so the margin is

2.776⋅117.5≈0.664,2.776 \cdot \frac{1}{\sqrt{17.5}} \approx 0.664 ,

and the 95 percent interval is 2±0.6642 \pm 0.664, about [1.336,2.664][1.336, 2.664] response units per predictor unit. Every slope in it is positive, which matches the small p-value of the test.

Check yourself

  1. Another fitted slope is b1=1.2b_1 = 1.2 with SE⁡(b1)=0.5\operatorname{SE}(b_1) = 0.5 and 4 residual degrees of freedom. Find the t statistic for H0 ⁣:β1=0H_0\colon \beta_1 = 0 and the 95 percent interval, using t0.975,4≈2.776t_{0.975, 4} \approx 2.776. Does the interval exclude zero, and what does the result say about the association?
Show the answer

The statistic is t=1.2/0.5=2.4t = 1.2/0.5 = 2.4. It is smaller than 2.7762.776, so the two-sided test at the 5 percent level does not reject, and the p-value is about 0.0740.074.

The margin is 2.776⋅0.5≈1.3882.776 \cdot 0.5 \approx 1.388, so the interval is about [−0.188,2.588][-0.188, 2.588]. Zero lies inside it.

The estimate is positive, but the data do not pin β1\beta_1 down well enough to rule out a zero or slightly negative slope, and they also allow slopes as large as about 2.62.6. This is uncertainty, not evidence that the association is absent. A report should give the estimate with its units, the interval, the design and the conditions behind the t reference.

  1. An observational study of constructed data reports the 95 percent interval [0.4,1.6][0.4, 1.6] for β1\beta_1 and the p-value 0.0020.002 for H0 ⁣:β1=0H_0\colon \beta_1 = 0. Which of these readings are correct? First, there is a 95 percent probability that β1\beta_1 lies between 0.4 and 1.6. Second, the probability that the slope is zero is 0.002. Third, raising xx by one unit for any individual would raise yy by between 0.4 and 1.6 units. Fourth, if the model holds, the procedure that produced the interval captures β1\beta_1 in 95 percent of repeated samples.
Show the answer

Only the fourth reading is correct.

The first treats β1\beta_1 as random. Here β1\beta_1 is a fixed unknown number, and the 95 percent belongs to the procedure. A probability statement about β1\beta_1 itself needs a Bayesian analysis with a prior, which gives a credible interval instead.

The second confuses the p-value with the probability of the null. The value 0.0020.002 is the probability, computed assuming a zero slope and the model, of a t statistic at least as far from zero as the observed one.

The third reads an association as a causal effect. In an observational study other factors that vary with xx can produce the slope, and the slope compares individuals with different values of xx rather than describing a change made to one individual.

  1. A constructed sample of 12 days gives a least-squares slope of 0.8 kilowatt hours per degree Celsius for a building’s daily electricity use against the outdoor temperature, with residual standard deviation s=2s = 2 kilowatt hours and Sxx=100S_{xx} = 100 squared degrees. Find the standard error, the t statistic for a zero slope and the 95 percent interval, using t0.975,10≈2.228t_{0.975, 10} \approx 2.228. How would the interval change if the 12 days had temperatures spread twice as far from their mean, with the same residual standard deviation? Would a narrower interval show that warmer days cause higher use?
Show the answer

The standard error is 2/100=0.22/\sqrt{100} = 0.2 kilowatt hours per degree, and t=0.8/0.2=4t = 0.8/0.2 = 4 with 12−2=1012 - 2 = 10 degrees of freedom, a two-sided p-value of about 0.00250.0025. The margin is 2.228⋅0.2≈0.4462.228 \cdot 0.2 \approx 0.446, so the interval is about [0.354,1.246][0.354, 1.246] kilowatt hours per degree.

Spreading the temperatures twice as far from their mean doubles every deviation xi−xˉx_i - \bar{x}, so SxxS_{xx} becomes 400 and the standard error becomes 2/400=0.12/\sqrt{400} = 0.1. The margin halves to about 0.2230.223, so if the new sample again gave the estimate 0.8, the interval would be about [0.577,1.023][0.577, 1.023]. This assumes that the straight line with the same error spread still holds over the wider range of temperatures, which needs checking, since use may rise again on cold days.

A narrower interval estimates the association more precisely, but it is still an association in observational data. Season, daylight and occupancy also change with temperature, so the regression alone does not show how much warming by itself changes electricity use.

How this lesson connects