The assumptions
Lesson 5.10.2 fitted by least squares, which needs no assumptions at all. To say how far may be from , you need a model of the errors. These are the usual assumptions, with the values treated as fixed numbers, as lesson 5.10.1's simulation kept the same 20 values of .
- Linear mean. : the columns of capture how the mean of depends on the regressors.
- Independent columns. has rank , so exists (lesson 5.10.2).
- Errors unrelated to the regressors. Each has mean 0, whatever the regressors are. This fails when a regressor that matters is left out and moves with one that is in: lesson 5.10.2's omitted-variable bias.
- Constant variance. , the same for every observation.
- Uncorrelated errors. for : one error says nothing about another.
- Normal errors. Each is normal. This one is needed only for the exact t and F distributions below.
Rule: What the assumptions buy
Assumptions 1 to 3 make unbiased (lesson 5.8.1): centred on the truth. Adding 4 and 5 gives its covariance matrix, whose diagonal holds the variances of the coefficients. Adding 6 makes jointly normal.
The covariance of the estimates
Three steps give the rule, each using a lesson you have met. Write , a fixed matrix, so that .
- 1
- 2
- 3
For lesson 3.5.3's 20 values of , with :
The square roots of the diagonal are 0.4645 for the intercept and 0.0388 for the slope: lesson 5.10.1's . Lesson 5.10.1's 10,000 simulated samples give the sample covariance matrix , close to it.
The off-diagonal entry is negative: the correlation of and is . Every fitted line passes through the mean point , here with . A line that comes out steeper must cross lower, so a high slope comes with a low intercept.
Try it
The first lines compute for the 20 values of , which is when , and the correlation it implies.
Then lesson 5.10.1's simulation, with its seed: the sample covariance matrix and correlation of the 10,000 pairs .
Standard errors and t statistics
The rule needs , which is unknown. Estimate it from the residuals, as lesson 5.10.1 did with ; with coefficients, divide by . The square root of each diagonal entry then becomes a standard error.
Maximum likelihood divides RSS by instead (lesson 5.9.2), which makes the estimate too small on average. Dividing by removes that bias, as does for a sample variance (lesson 5.8.1).
Rule: Standard errors and the t statistic
is the diagonal entry for coefficient , and is the number of degrees of freedom. Under all six assumptions, if the true is the number , then has the t distribution with degrees of freedom (lesson 5.4.4).
That gives the two tools of module 5.8, which read as follows for a coefficient. Lesson 5.8.2 built a 95% interval as the estimate plus or minus a t quantile times its standard error. Lesson 5.8.3 tested a value by its t statistic and p-value.
Here is the 0.975-quantile of the t distribution, t.ppf(0.975, n - k), and a variable with that distribution.
How far the fit may be from the truth
Lesson 3.5.3's 20 points gave . With degrees of freedom, , so the slope's standard error is and the intercept's is 0.5375. The quantile is .
| estimate | standard error | 95% interval | t for the truth | p | |
|---|---|---|---|---|---|
| intercept | 2.4162 | 0.5375 | 1.2869 to 3.5454 | 0.7742 | 0.4488 |
| slope | 0.4571 | 0.0449 | 0.3628 to 0.5513 | 0.3512 |
Both intervals cover the true values, 2 and 0.5. The t statistics test those true values: a p-value of 0.3512 says a miss as large as is common. This is how far the fit may be from the truth, from one sample alone.
The test that matters most in practice is whether the slope is 0 at all. Here , and the p-value is about : does depend on .
Try it
The cell fits lesson 3.5.3's points, computes , the standard errors and the t quantile with scipy.stats.t.
Then the intervals, the t statistics and p-values for the true values , and the t statistics for 0 with the slope's p-value and .
Why the t quantile, not 1.96
Lesson 5.10.1's 10,000 samples can check the interval. With each sample's own , the interval covers 0.5 in 95.01% of them. With 1.96 in place of 2.1009 it covers only 93.54%.
The standard error uses , which varies from sample to sample, and that widens the spread of : lesson 5.4.4's fatter tails. Across the samples, averages 0.9982, close to , which is why is the divisor. With many degrees of freedom the t quantile comes close to 1.96.
Try it
The cell repeats lesson 5.10.1's 10,000 samples, computes each one's residuals, and standard error, and counts how often each interval covers 0.5.
The last line is the average of over the samples.
Two regressors
Lesson 5.10.2's eight points have and , so . The diagonal of is , so .
| estimate | standard error | t for 0 | p | |
|---|---|---|---|---|
| intercept | 3 | 0.6614 | 4.5356 | 0.0062 |
| 1 | 0.2236 | 4.4721 | 0.0066 | |
| group | 0.6708 | 0.0007 |
With 5 degrees of freedom the quantile is 2.5706, so the 95% interval for runs from 0.4252 to 1.5748.
The F test
A t test asks about one coefficient. The F test asks whether any regressor matters: its null hypothesis is that every slope is 0, , so that only the intercept is left.
Under that null the best fit is the flat line at , which leaves TSS. The full model leaves RSS. The F statistic compares the drop, per slope, with what is left, per degree of freedom.
Rule: The F test that all slopes are 0
Under the null and the six assumptions, has the F distribution with and degrees of freedom. That is a ratio of two independent variables (lesson 5.4.4), each divided by its degrees of freedom. Large is evidence against the null; the p-value is f.sf(F, k - 1, n - k).
For the eight points, and :
With 2 and 5 degrees of freedom, the p-value is 0.0019; the 5% critical value is 5.7861. With a single slope, : lesson 3.5.3's points give , with the same p-value as the t test.
When t and F disagree
Take 30 invented points with two regressors that are almost the same: is plus a little noise, and their correlation is 0.9993. The true model is .
The fit gives and , far from the truth, with standard errors 3.5078 and 3.4812. Neither t test finds anything: their p-values are 0.353 and 0.492. Yet , with p-value : together the two regressors matter a great deal.
The data cannot tell from , so it cannot split their effect, but it pins down the total. The sum has standard error 0.1376, close to the true 1.
This is collinearity, and large standard errors beside a significant F are its mark. Keep one of the two regressors, or test their combined effect.
Try it
The first block repeats the eight points: the diagonal of , standard errors, t statistics and p-values, and the interval for . Then , its p-value and the 5% critical value from scipy.stats.f.
The second block makes the 30 nearly collinear points with a fixed seed. It prints the estimates, their standard errors and p-values, and its p-value, and the sum with its standard error for (lesson 5.5.3).
When the assumptions fail
Least squares still fits a line when the assumptions fail. What goes wrong is the statistics: the standard errors, and so every interval and p-value. Plot the residuals to see which assumption is in doubt.
Residuals from three invented samples: in the first the assumptions hold, in the second the spread grows with . In the third each error is close to its neighbour, so the residuals run in long stretches above or below 0.
Changing variance. Suppose the errors' standard deviation grows in proportion to , scaled so that their average variance is still 1. Lesson 5.10.1's experiment then gives slopes whose true spread is 0.0431, but the usual standard error averages 0.0379. The nominal 95% intervals cover 0.5 only 92.26% of the time.
Correlated errors. Data in time order often has errors close to their neighbours: make each error correlated 0.5 with the one before (a lag-one correlation). The slopes' true spread becomes 0.0606, while the usual standard error averages 0.0344. The intervals cover only 75.28% of the time, and 50.93% at a lag-one correlation of 0.8.
With the errors as assumed, the same experiment gives a true spread of 0.0391, an average standard error of 0.0381 and coverage of 94.92%. In both failures is still unbiased, but is the wrong covariance matrix. Here it was too small, so t statistics came out too large and slopes looked significant too often.
Rule: What each failure does
Changing variance is called heteroscedasticity, and correlated errors autocorrelation. Robust standard errors (White's for changing variance, Newey and West's for correlation too) estimate the spread without those assumptions. No standard error repairs bias from a left-out regressor.
Non-normal errors matter less. With many observations the central limit theorem (lesson 5.7.3) makes close to normal anyway, so t and F are close to right. Fat tails and outliers are the exception: a single wild point with high leverage (lesson 5.10.2) can move the fit.
Try it
The cell reruns lesson 5.10.1's experiment three ways, 10,000 samples each with a fixed seed. coverage prints the slopes' true spread, the average usual standard error, and how often the 95% interval covers 0.5.
The errors are first as assumed, then with a standard deviation in proportion to , then with each error correlated with the one before.
Case study 5.10.5 applies these tests to a stock's beta and alpha.
Common mistakes
- Divide RSS by , the number of observations minus the number of coefficients, intercept included.
- Use the t quantile with degrees of freedom, not 1.96, for a small sample: with 18 degrees of freedom, 1.96 covers 93.54%, not 95%.
- A large p-value does not prove the null. Lesson 3.5.3's test of a slope of 0.5 gave . Every value inside the interval, 0.3628 to 0.5513, would also pass.
- Insignificant t statistics do not mean no regressor matters. Collinear regressors can each look useless while the F test is overwhelming.
- Standard errors rest on assumptions 4 and 5. With changing variance or correlated errors they can be far too small; look at the residuals.
- No standard error fixes a left-out regressor. That makes itself biased (lesson 5.10.2).
Assumptions, t tests and F tests
0 of 12 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Summary card
- Assumptions: linear mean, independent columns, errors of mean 0 unrelated to the regressors, constant variance, uncorrelated errors; normal errors for exact t and F.
- Then is unbiased with .
- and . The interval and the test use degrees of freedom.
- Lesson 3.5.3's slope, 0.4571, has standard error 0.0449 and interval 0.3628 to 0.5513, which covers the true 0.5.
- The F test that all slopes are 0: ; with one slope . Collinear regressors can fail each t test and pass F.
- Changing variance and correlated errors leave unbiased but make the standard errors wrong, often too small; a left-out regressor biases .