Comparing two groups asks whether a category changes an outcome. When the predictor is itself a number, an air temperature, a dose, a distance, grouping throws away most of the information in it. Fitting a line uses all of it, and it is the most heavily used and most heavily overinterpreted procedure in the subject.
The model, and what is random in it
Write the model as
where and are unknown constants, the are treated as fixed and known, and the errors are independent with mean zero and common variance . The only random thing is the error, which is why is capitalised and is not.
The assumptions packed into that line are worth naming because each can fail. The relationship is linear in the parameters. The errors have the same variance at every , called homoscedasticity. They are independent of each other. And the values are measured without error, which is often false and is the assumption people are least aware of making.
The estimates of and are written and , and they are statistics with sampling distributions like any others.
Least squares, derived
Choose the line that minimises the total squared vertical distance from the points to it:
Differentiate with respect to each and set both to zero. For the intercept,
which says the residuals sum to zero, so : the fitted line passes through the point of means, whatever the slope is. For the slope,
Substituting into that and collecting terms gives
So the slope is the sample covariance divided by the variance of . Since the correlation is , an equivalent and more revealing form is
the correlation scaled by the ratio of the two spreads. Vertical distances are minimised, not perpendicular ones, which is why regressing on and on give different lines: the second has slope , and the two agree only when .
Example. In Pearson and Lee's 1903 data on 1078 father and son pairs, fathers have mean height 67.7 inches with standard deviation 2.7, sons have mean 68.7 with the same standard deviation, and the correlation is 0.51. Find the line predicting a son's height from his father's.
The slope is , and the intercept is inches. So a father 6 inches above the mean has a son predicted only inches above the mean. Francis Galton noticed exactly this in the 1880s and called it regression towards mediocrity, which is where the word "regression" comes from, and it is a consequence of rather than a biological force.
Now you. What line predicts the father's height from the son's?
Answer
The slope is again , with intercept . The prediction runs backwards in time and still shrinks towards the mean, which shows that regression to the mean is a statement about correlation and not about inheritance or causation.
How much the line explains
Split the total variation in into what the line accounts for and what it does not. With , the identity
holds exactly, because the cross term vanishes by the two normal equations above. The three pieces are the total, regression and error sums of squares, and the ratio
is the fraction of the variance of accounted for by the line. It is the square of the correlation, which is where the notation comes from.
The phrase "explained variance" is standard and misleading. A high says the points lie close to some line; it says nothing about whether the line is the right shape, whether causes , or whether the model would predict a new observation well. Anscombe's second dataset from the second lesson is an exact parabola and has , the same as the honest linear one. A low is likewise not a failure: in a field with large individual variation, a real and important effect can account for a few per cent of the variance and still matter.
Inference on the slope
The slope is a weighted sum of the , so if the errors are independent with variance its variance follows from adding variances:
Two design consequences drop out immediately. Precision improves as the values are spread further apart, since grows, so an experiment that can choose its doses should use the extremes rather than crowding the middle. And it improves with through the same sum.
The error variance is estimated from the residuals, dividing by because two parameters were estimated before the residuals were formed:
Then follows a distribution on degrees of freedom, and intervals and tests follow exactly as before.
Example. Take Anscombe's first dataset, eleven points with = 10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5 and = 8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68. Fit the line and test whether the slope differs from zero.
Here and , so and . The residual sum of squares is 13.763, so and . Then , giving
on 9 degrees of freedom, with . The 95 per cent interval for the slope is .
Now you. What is for this fit, given that the total sum of squares is 41.273?
Answer
, so , and . The line accounts for two thirds of the variation in .
Residuals are the check
Every number in the previous section is also produced, identically, by Anscombe's other three datasets, and in three of the four cases it is worthless. The check that distinguishes them is the residuals, , and what to look for is specific.
Plotted against the fitted values, residuals should show no pattern. A curve means the relationship is not linear and the model is wrong in shape, which is Anscombe's second dataset. A funnel, widening as the fitted values grow, means the error variance is not constant, which often signals that the response should be modelled on a log scale. A single point far from the rest, which is Anscombe's third, means the fit is being determined by one observation.
Influence is worth separating from being an outlier. A point with an unusual but ordinary inflates the residual variance and moves the line little. A point with unusual has high leverage, because weights observations by , and if it also has an unusual it can set the slope almost by itself. That is Anscombe's fourth dataset, where ten points share one value: delete the eleventh and the slope is not merely different, it is undefined. The usual diagnostic is to refit without each point and see how much the estimates move.
Example. In the Anscombe I fit above, the residual at is and the residual standard deviation is 1.237. Is this point unusual?
The standardised residual is , well inside the range a normal error would produce in eleven observations. It is not an outlier, and with against a mean of 9 it has moderate leverage, so it is worth noting rather than acting on.
Now you. The fitted value at is 8.00 and the observed is 8.04. What is the standardised residual?
Answer
, essentially on the line.
Prediction, and the edge of the data
A fitted line supports two different intervals at a new , and confusing them is common. The interval for the mean response at has width driven by the uncertainty in and alone. The interval for a single new observation at must additionally include the error term , so its variance is larger by and it is much wider. A regression with can still predict an individual case poorly.
Both intervals widen as moves away from , because a small error in the slope is amplified by the lever arm. Beyond the range of the data, the widening is the least of the problems: there the model itself is an untested guess, and no interval accounts for the possibility that the relationship bends.
Edwin Hubble's 1929 paper fitted a line to the velocities and distances of 24 galaxies and obtained a slope of about 500 kilometres per second per megaparsec. The modern value is near 70. The regression arithmetic was not wrong: the distances fed into it were wrong, by a factor of about seven, because the calibration of the distance indicators was. This is the assumption that is measured without error, failing in the most consequential way, and it is not visible anywhere in the residual plots.
What a slope is not
A fitted slope says that, in this sample, is on average higher by for each unit of . It does not say that changing would change , and the gap between those two sentences is where most misuse of regression happens.
Three things can produce a slope with no causal content. The relationship may run the other way, since least squares is symmetric about which variable is called the response. A third variable may drive both, which the fitted line has no way to detect. Or the sample may have been assembled so as to create the association, as when only cases meeting some combined criterion are recorded.
Nothing in this lesson distinguishes those from a genuine causal effect, because nothing in the data can. What does distinguish them is how the data was produced, which is the next lesson.