Sub topic 15
Testing the slope and building confidence intervals
This chapter assumes you can fit a simple regression line by ordinary least squares. It also assumes you know the ANOVA decomposition (SST, SSR, SSE) and the standard error of estimate (SEE), and you know the one-sample t-test. Here you test whether the fitted slope is evidence of a real relationship, and you build an interval around it.
Why the slope needs a test
The slope b1 from a sample is an estimate. A different sample from the same population would give a different b1, so b1 has its own sampling distribution. If the true slope B1 is zero, X tells you nothing about Y, and any nonzero b1 you see is sampling noise.
The question is whether b1 is far enough from the hypothesized value, compared with its standard error, to rule out noise.
The setup
The usual hypotheses are:
- H0: B1 = 0
- Ha: B1 ≠ 0
The null does not have to be zero. A CFA question may ask whether a stock's beta equals 1. Then H0 is B1 = 1, and the test is still the same procedure.
The test statistic is:
t = (b1 − B1) / s_b1
It follows a t-distribution with n − 2 degrees of freedom. You lose two degrees of freedom because the data were used to estimate two parameters, the intercept and the slope.
The standard error of the slope is:
s_b1 = SEE / sqrt(Σ(xᵢ − x̄)²)
Two things make s_b1 smaller, so the test is more powerful:
- A smaller SEE, meaning the points sit closer to the line.
- A larger spread in X, meaning a bigger denominator.
This is why a regression run on a narrow range of X values gives a noisy slope.
The decision procedure
The procedure matches the one in earlier chapters. Only the standard error and the degrees of freedom change.
A worked example
Take five observations: x = 1, 2, 3, 4, 5 and y = 2.1, 3.9, 6.2, 7.8, 10.1.
- The sample means are x̄ = 3 and ȳ = 6.02.
- Σ(x − x̄)² = 10 and Σ(x − x̄)(y − ȳ) = 19.9.
- The slope is b1 = 19.9 / 10 = 1.99. The intercept is b0 = 6.02 − 1.99 × 3 = 0.05.
- The residuals are 0.06, −0.13, 0.18, −0.21 and 0.10, so SSE = 0.107.
- SEE = sqrt(0.107 / 3) ≈ 0.1889.
- s_b1 = 0.1889 / sqrt(10) ≈ 0.0597.
- t = 1.99 / 0.0597 ≈ 33.3.
- The two-tailed 5% critical value with 3 degrees of freedom is 3.182. Because 33.3 > 3.182, reject H0. The slope is significantly different from zero.
The code below reproduces this and adds the confidence interval:
import numpy as np
from scipy import stats
x = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
y = np.array([2.1, 3.9, 6.2, 7.8, 10.1])
n = len(x)
res = stats.linregress(x, y)
# Manual standard error of the slope, to check scipy
y_hat = res.intercept + res.slope * x
sse = ((y - y_hat) ** 2).sum()
see = np.sqrt(sse / (n - 2))
s_b1 = see / np.sqrt(((x - x.mean()) ** 2).sum())
t_slope = (res.slope - 0.0) / res.stderr
t_crit = stats.t.ppf(1 - 0.05 / 2, df=n - 2)
ci_low = res.slope - t_crit * res.stderr
ci_high = res.slope + t_crit * res.stderr
print(f"manual s_b1 = {s_b1:.4f}, scipy stderr = {res.stderr:.4f}")
print(f"t = {t_slope:.2f}, critical = {t_crit:.3f}, p = {res.pvalue:.2e}")
print(f"95% CI for slope: ({ci_low:.3f}, {ci_high:.3f})")
print("Reject H0: slope = 0" if abs(t_slope) > t_crit else "Fail to reject H0")The two standard errors agree, which confirms that linregress uses the formula above. The interval comes out near (1.80, 2.18).
The confidence interval for the slope
A confidence interval for B1 uses the same ingredients:
b1 ± tcritical × sb1
For the example: 1.99 ± 3.182 × 0.0597 = 1.99 ± 0.190, or about 1.80 to 2.18.
The interval and the two-tailed test are two views of the same result. If the hypothesized value falls outside the 95% interval, a two-tailed test at the 5% level rejects it. Zero is outside (1.80, 2.18), which matches the rejection above. Testing H0: B1 = 2 would fail to reject, because 2 sits inside the interval.
The interval is also more informative than the test. It tells you whether the slope is large enough to matter for your decision, not only whether it differs from zero.
Connecting the slope test to the ANOVA table
In simple regression the slope test and the F-test of the whole model are equivalent:
- F = t², where t is the slope's t-statistic.
- Both tests have the same p-value.
- The F-test has 1 and n − 2 degrees of freedom.
In the example, t² ≈ 1110, which is the F-statistic you would get as SSR / (SSE / (n − 2)). The equivalence holds only with one independent variable. With several regressors, the F-test examines all slopes jointly and no longer matches any single t-test.
The slope test also matches a test of the correlation. Testing H0: ρ = 0 with t = r·sqrt(n − 2) / sqrt(1 − r²) gives the same t-value as the slope test.
Common errors
- Wrong degrees of freedom. Use n − 2, not n − 1. This is the most common slip when switching from a single-mean t-test.
- Using the standard deviation of Y instead of SEE. The slope's standard error comes from the residual spread, not from the total spread of Y.
- Confusing statistical and economic significance. With a large sample, a tiny slope can be highly significant. Check the size of the interval against what matters in practice.
- Reading "fail to reject" as "slope is zero". It means the sample did not provide enough evidence. A wide interval often includes both zero and economically large values.
- Testing a nonzero null with the wrong numerator. For H0: B1 = 1, the numerator is b1 − 1, not b1.
- Ignoring assumption violations. If the residuals show heteroskedasticity or serial correlation, s_b1 is unreliable and the t-statistic is misleading. Later chapters cover these cases.
Summary table
| Item | Formula | Degrees of freedom |
|---|---|---|
| Standard error of the slope | SEE / sqrt(Σ(x − x̄)²) | not applicable |
| Slope t-statistic | (b1 − B1) / s_b1 | n − 2 |
| Confidence interval | b1 ± t_crit × s_b1 | n − 2 |
| Equivalent F-test | F = t² | 1 and n − 2 |
Exercise
A regression of a stock's excess returns on market excess returns uses 27 monthly observations. The estimated slope (beta) is 0.80 and its standard error is 0.30. The two-tailed 5% critical t-value with 25 degrees of freedom is 2.060. (a) Test H0: B1 = 0 at the 5% level. (b) Build the 95% confidence interval for the slope. (c) Test H0: B1 = 1.
Show answer
(a) t = 0.80 / 0.30 = 2.667. Since 2.667 > 2.060, reject H0. The beta differs significantly from zero. (b) 0.80 ± 2.060 × 0.30 = 0.80 ± 0.618, so the interval is about (0.182, 1.418). (c) t = (0.80 − 1) / 0.30 = −0.667. Since |−0.667| < 2.060, fail to reject H0. This agrees with the interval, which contains 1.
Exercise
In a simple regression with n = 12, the slope t-statistic is 3.5. What is the F-statistic, and how many degrees of freedom does it have?
Show answer
F = t² = 3.5² = 12.25, with 1 numerator degree of freedom and n − 2 = 10 denominator degrees of freedom.