Lecture Linear Regression Inference
Lecture Linear Regression Inference
Osman DOĞAN
1 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Readings:
1 Stock and Watson (2020, Chapter 5),
2 Doğan and Taşpınar (2025, Chapter 15).
2 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
In other words, under this claim, the slope of the population regression function
is zero, i.e., β1 = 0.
Can you reject the taxpayer’s hypothesis that β1 = 0, or should you accept it,
at least tentatively pending further new evidence?
3 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
To this end, we will start by stating the null and the alternative hypotheses.
The null hypothesis will state the claim to be tested and we use H0 to denote
it. In our example, H0 : β1 = 0.
The alternative hypothesis will state the scenario when the null hypothesis does
not hold and we use H1 to denote it:
1 If H1 : β1 ̸= 0 it is called a two-sided alternative.
2 If H1 : β1 < 0 or H1 : β1 > 0, it is called a one-sided alternative.
4 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
In order to decide between H0 and H1 , we need a test statistics that will make
use of the sample data and help us to reach a tentative conclusion.
estimator-hypothesized value
t= (1)
standard error of the estimator
Thus, the t-statistic for testing H0 : β1 = c, where c is the hypothesized value,
takes the following form:
βb1 − c
t= , (2)
SE(βb1 )
5 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Recall from Chapter 4 that under the least squares assumptions, in large
samples, we have
A
1 var ((Xi − µX )ui )
βb1 ∼ N β1 , σβ2b1 , where σβ2b1 = . (3)
n (var(Xi ))2
The idea is to replace the unknown terms in σβ2b with their sample
1
counterparts. Thus, an estimator of σβ2b is
1
1
Pn 2 2
1 n−2 i=1 (Xi − X̄) ubi
bβ2b1
σ = n 2 (4)
n 1
P
i=1 (Xi − X̄)
2
n
q
Then, SE(βb1 ) in (2) can be computed through SE(βb1 ) = σbβ2b .
1
6 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
A
βb1 − β1 A
βb1 ∼ N β1 , σβ2b1 ⇒ ≡ Z ∼ N (0, 1) (5)
σβb1
Also, (5) suggests that if H0 is true then, the sampling distribution of the
A
t-statistic can be approximated by N (0, 1) in large samples, i.e., t ∼ N (0, 1).
Recall the types of errors you can make in a testing problem (Chapter 3)
□ we reject a TRUE H0 , i.e., Type-I error,
We choose a (significance) level for committing the Type-I error, and then
minimize the likelihood of committing Type-II error.
We can now use the level and the sampling distribution of the test to define
the rejection regions.
7 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Example 1
Consider H1 : β1 ̸= c in Figure 1c, and assume that α = 5%. Then, the critical
value on the left tail is the 2.5th percentile of N (0, 1), which is
−zα/2 = −1.96, and the critical value on the right tail is the 97.5th percentile
of N (0, 1), which is zα/2 = 1.96. In R, we can use the following:
qnorm (0.025 , mean = 0 , sd =1 , lower . tail = TRUE ) = -1.96
β̂1 −c
Assume that we obtained t = SE( β̂1 )
= 2. Then, we will reject H0 because the
test statistic value is in the rejection region. i.e., t = 2 > zα/2 = 1.96.
8 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
(c) H0 : β1 = c versus H1 : β1 ̸= c
9 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Hypothesis Testing
where tcalc is the value of the test statistic obtained from (2).
PH0 means this probability is calculated from the distribution of the test
statistic under the null hypothesis.
10 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Hypothesis Testing
It gives the likelihood of obtaining a test statistic value that is more extreme
than the actual one when the null is correct.
Hence, the smaller p-value, the less likely that the null is correct. If the level is
chosen as 5%, then reject H0 if p-value is less than 5%.
Example 2
Consider H1 : β1 ̸= c in Figure 1c, and assume that α = 5%. Assume that we
obtained t = 2 from (2). Then,
p-value = PH0 (|t| > 2) = PH0 (t > 2) + PH0 (t < −2) = 2 × Φ(−2).
11 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
In R, the lm function computes the t-statistic for each regressor and provides
the corresponding p-values for a two sided null hypothesis. The estimation
results are given in Listing 1.
Consider H0 : β1 = 0 versus H1 : β1 ̸= 0 and assume α = 5%. Then, we can
compute t-statistic as
β̂1 − 0 −2.28
t= = ≈ −4.75 (7)
SE(β̂1 ) 0.48
The critical value is zα/2 = −1.96. Since t = −4.75 < zα/2 = −1.96. We
reject H0 and conclude that β1 is statistically significant at 5% level.
12 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
library ( stargazer )
library ( readxl )
CAschool = read _ excel ( " caschool . xlsx " , col _ names = TRUE , skip = 0)
results = lm ( testscr ∼ str , data = CAschool )
summary ( results )
Call :
lm ( formula = testscr ∼ str , data = mydata )
Residuals :
Min 1Q Median 3Q Max
-47.727 -14.251 0.483 12.822 48.540
Coefficients :
Estimate Std . Error t value Pr ( >| t |)
( Intercept ) 698.9330 9.4675 73.825 < 2e -16 * * *
str -2.2798 0.4798 -4.751 2.78 e -06 * * *
---
Signif . codes : 0 ’* * * ’ 0.001 ’* * ’ 0.01 ’* ’ 0.05 ’. ’ 0.1 ’ ’ 1
13 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Then,
the 95% CI for β1 refers
to the set of values for β1 such that
b1 −β1
β
P {β1 : SE(βb ) ≤ 1.96} = 0.95. Hence,
1
βb1 − β1 βb1 − β1
{β1 : ≤ 1.96} = {β1 : −1.96 ≤ ≤ 1.96}
SE(βb1 ) SE(βb1 )
= {β1 : βb1 − 1.96 SE(βb1 ) ≤ β1 ≤ βb1 + 1.96 SE(βb1 )}
h i
Thus, the 95% CI for β1 is βb1 − 1.96 × SE(βb1 ), βb1 + 1.96 × SE(βb1 ) .
14 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Similarly, you can construct 90% and 99% CIs. You just need to change the
critical value, 1.64 and 2.57, respectively.
In other words, from one sample to the next, it provides different values for the
lower bound and upper bound of the interval.
It does not mean that for the sample at hand the likelihood of the true
(unknown) value of β1 being in the interval constructed is 95%.
15 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Example 3
Consider the test score example in (6). The estimation results are provided in
Listing 1. Then, the 95% CI for β1 is β̂1 ± 1.96 × SE(β̂1 ), which gives
[−3.22, −1.34] .
The 95% CI for β1 can be used to construct a 95% CI for the predicted effect
of a general change in X.
Recall that the expected change in Y associated with this change in X is β1 ∆x.
16 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Sometimes a regressor can be binary–that is, it takes on only two values, 0 and
1. For example, X can be
1 a worker’s sex: X = 1 if female, X = 0 otherwise,
2 whether a school district is urban or rural: X = 1 if urban, X = 0 otherwise),
3 whether the district’s class size is small or large: X = 1 if small, X = 0
otherwise.
A binary variable is also called an dummy variable or sometimes a indicator
variable.
17 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Hence,
In our example, it is the difference between the mean test score in districts with
low student-teacher ratios and the mean test score in districts with high
student-teacher ratios.
Listing 2 provides the estimation result for (8). The results show that
β̂1 = 7.37.
Thus, the students in districts with the STR less than 20 on average have 7.37
more points than the students in districts with the STR larger or equal to 20.
19 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Call :
lm ( formula = testscr ∼ D , data = mydata )
Residuals :
Min 1Q Median 3Q Max
-50.601 -14.047 -0.451 12.841 49.399
Coefficients :
Estimate Std . Error t value Pr ( >| t |)
( Intercept ) 649.979 1.388 468.380 < 2e -16 * * *
DTRUE 7.372 1.843 3.999 7.52 e -05 * * *
---
Signif . codes : 0 ’* * * ’ 0.001 ’* * ’ 0.01 ’* ’ 0.05 ’. ’ 0.1 ’ ’ 1
20 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
import numpy as np
import pandas as pd
import statsmodels . api as sm
import statsmodels . formula . api as smf
# Import data
CAschool = pd . read _ excel ( " data / caschool . xlsx " )
# Create the dummy variable D
CAschool [ " D " ] = CAschool [ " str " ] < 20
21 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Definition 1
The error term ui is homoskedastic if the variance of the conditional
distribution of ui given Xi is constant for i = 1, 2, . . . , n, and in particular does
not depend on Xi . Otherwise, the error term ui is heteroskedastic.
Recall the least squares assumptions did not say anything about the the
conditional distribution of ui given Xi . In other words, we have been assuming
heteroskedasticity implicitly.
And we derived the variance of the sampling distribution of the OLS estimator
under heteroskedasticity.
1 var ((Xi − µX )ui )
σβ2b1 =
n (var(Xi ))2
Under homoskedasticity, this formula simplifies to
1 var ((Xi − µX )ui ) 1 var ((Xi − µX )) var (ui ) 1 var (ui )
σβ2b1 = = = .
n (var(Xi ))2 n (var(Xi ))2 n var(Xi )
22 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
23 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
stargazer ( r1 , r1 ,
se = list ( NULL , robust _ se ) ,
type = " text " ,
column . labels = c ( " Homoskedastic " ,
" Heteroskedastic " ) ,
align = TRUE )
24 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
============================================================
Dependent variable :
-----------------------------
testscr
Homoskedastic Heteroskedastic
(1) (2)
------------------------------------------------------------
str -2.280 * * * -2.280 * * *
(0.480) (0.519)
------------------------------------------------------------
Observations 420 420
R2 0.051 0.051
Adjusted R2 0.049 0.049
Residual Std . Error ( df = 418) 18.581 18.581
F Statistic ( df = 1; 418) 22.575 * * * 22.575 * * *
============================================================
Note : *p <0.1; * *p <0.05; * * *p <0.01)
25 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
import numpy as np
import pandas as pd
import statsmodels . api as sm
import statsmodels . formula . api as smf
from statsmodels . iolib . summary2 import summary _ col
26 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
If the errors are heteroskedastic and you use the homoskedasticity-only formula
for standard errors, your standard errors will be wrong (the
homoskedasticity-only estimator of the variance of β̂1 is inconsistent if there is
heteroskedasticity).
Therefore, Stock and Watson (2020) suggest that we should always use
heteroskedasticity-robust standard errors.
27 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Recall the three least squares assumptions. Now, add the homoskedasticity
assumption on the error term.
Then, it can be shown analytically that the OLS estimator is the most precise
estimator (conditional on X’s) within the class of linear unbiased estimators.
This results is known as the Gauss-Markov theorem. See Appendix 5.2 for a
proof.
28 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
So far we have not specified the distribution of the error term, we just made
assumptions on its moments.
Then, the OLS estimator βb1 is exactly distributed as normal with mean β1 and
σβ2b under homoskedasticity.
1
For inference, this creates a difference if the sample size very small, say n < 30:
the Student t critical values can be a fair bit larger than the standard normal
critical values.
29 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Practical implications
If n < 50 and you really believe that, for your application, ui is homoskedastic
and normally distributed, then use the tn−2 instead of the N (0, 1) critical
values for hypothesis tests and confidence intervals.
30 / 31
Outline Significance testing Confidence intervals Regression with binary X Heteroskedasticity Efficiency of the OLS References
Bibliography I
31 / 31