Sub topic 5
Testing Coefficients Jointly: The F-Test and ANOVA Table
Prerequisites and purpose
This chapter assumes that you know simple linear regression, p-values, t-tests, and the meaning of a confidence interval. You should also know that a regression coefficient measures the expected change in the dependent variable when an independent variable changes, holding other included variables constant.
An individual t-test asks whether one coefficient differs from a specified value. The F-test asks whether several restrictions are true at the same time. This makes it useful when a group of variables represents one concept, or when you want to test the overall usefulness of a regression.
The joint hypothesis
Suppose the unrestricted multiple regression is
y = β0 + β1x1 + β2x2 + β3x3 + ε
A joint null hypothesis might be:
H0: β2 = 0 and β3 = 0
The alternative hypothesis is that at least one of these coefficients is not zero. The test does not identify which coefficient is nonzero. You would need individual t-tests for that question.
The model containing all variables is the unrestricted model. The model that imposes the null restrictions is the restricted model. Under the example hypothesis, the restricted model removes x2 and x3:
y = β0 + β1x1 + ε
The F-test compares the fit of these two models. If removing x2 and x3 causes a large increase in the sum of squared errors, the restrictions are unlikely to be true.
F-statistic
Let:
- SSE_R be the restricted model's sum of squared errors.
- SSE_UR be the unrestricted model's sum of squared errors.
- q be the number of restrictions.
- n be the sample size.
- k be the number of independent variables in the unrestricted model, excluding the intercept.
The F-statistic is:
F = [(SSER - SSEUR) / q] / [SSE_UR / (n - k - 1)]
The numerator measures the increase in average error caused by imposing the restrictions. The denominator estimates the error variance from the unrestricted model.
Under the null hypothesis, the statistic follows an F distribution with q numerator degrees of freedom and n - k - 1 denominator degrees of freedom. Reject H0 when the F-statistic exceeds the critical value, or when its p-value is below the chosen significance level.
For the special case of testing whether all slopes equal zero, the restricted model contains only an intercept. The F-test then asks whether the regression explains any variation in the dependent variable beyond its sample mean.
import numpy as np
import statsmodels.api as sm
rng = np.random.default_rng(42)
n = 200
x1 = rng.normal(size=n)
x2 = rng.normal(size=n)
y = 1.0 + 2.0 * x1 - 1.0 * x2 + rng.normal(size=n)
X_unrestricted = sm.add_constant(np.column_stack([x1, x2]))
X_restricted = np.ones((n, 1))
unrestricted = sm.OLS(y, X_unrestricted).fit()
restricted = sm.OLS(y, X_restricted).fit()
f_stat, p_value, df_diff = unrestricted.compare_f_test(restricted)
print("F-statistic:", f_stat)
print("p-value:", p_value)
print("Restrictions tested:", int(df_diff))
print("Unrestricted residual degrees of freedom:",
int(unrestricted.df_resid))A small p-value supports rejecting the joint null. It does not prove that every tested coefficient is significant. One variable may be useful while another is not.
The ANOVA table
An analysis of variance, or ANOVA, table divides the total variation in y into explained and unexplained parts:
SST = SSR + SSE
- SST is total sum of squares, measuring variation around the sample mean.
- SSR is regression sum of squares, measuring variation explained by the fitted model.
- SSE is error sum of squares, measuring unexplained variation.
| Source | Sum of squares | Degrees of freedom | Mean square | F-statistic |
|---|---|---|---|---|
| Regression | SSR | k | SSR / k | MSR / MSE |
| Error | SSE | n - k - 1 | SSE / (n - k - 1) | — |
| Total | SST | n - 1 | — | — |
The overall F-statistic compares the regression mean square with the error mean square:
F = (SSR / k) / [SSE / (n - k - 1)]
This is the joint test H0: β1 = β2 = ... = βk = 0. A significant result means that the independent variables are jointly related to the dependent variable. It does not establish causation or show that every slope is significant.
Reading the result
Use the F-test when the research question concerns a group of coefficients. Report the restrictions, the F-statistic, its degrees of freedom, and the p-value. For example: “The null that β2 and β3 are both zero is rejected, F(2, 196) = 18.4, p < 0.001.”
The test relies on the regression model assumptions, especially a correctly specified conditional mean and an appropriate estimate of the error variance. With heteroskedastic or serially correlated errors, use a suitable robust or other corrected covariance estimate for joint testing.
Exercise
A model has n = 120 observations and k = 4 independent variables. You test q = 2 restrictions. What are the numerator and denominator degrees of freedom for the F-test?
Show answer
The numerator degrees of freedom are q = 2. The denominator degrees of freedom are n - k - 1 = 120 - 4 - 1 = 115, so the test uses F(2, 115).