In the previous two (recorded) labs, we learned the following:
lm())modelsummary() from
the modelsummary package)summary() to retrieve model estimates,
and qt() to generate critical \(t\)-statistics)In today’s lab we will apply the same exact functions as above to multivariate linear regression modeling – in other words, we will now consider more than just one regressor (independent variable).
Let’s begin by briefly and non-rigorously (and certainly not comprehensively) discussing why multivariate regression model specification is oftentimes necessary.
Suppose we are interested in learning the effect of some variable \(X\) on \(Y\).
Why can’t we just estimate a simple linear regression model of the form \(Y = \beta_0 + \beta_1 X + \varepsilon\)?
Well, sometimes we can! But this is very rare, and difficult to justify.
Oftentimes a simple regression will yield “inaccurate” results with regards to the true effect of \(X\) on \(Y\), because of OMITTED VARIABLE BIAS.
Omitted variable bias is caused by the existence of a third variable \(Z\) that also affects \(Y\) and is correlated with \(X\). In such a case, we must account for the variation in \(Z\) by including it in our model: \[ Y = \beta_0 + \beta_1 X + \beta_2 Z + \upsilon \]
Why? Because if we do not account for the variation in \(Y\) caused by \(Z\), then the least squares (LS) estimator will attribute said variation to \(X\) and bias our estimate of \(\beta_1\):
If \(Corr(X,Z) > 0\) and \(\beta_2 > 0\) and we do not include \(Z\) as a regressor in our model, then our estimate of \(\beta_1\) will likely be larger than its true value (positively biased).
If \(Corr(X,Z) > 0\) and \(\beta_2 < 0\) and we do not include \(Z\) as a regressor in our model, then our estimate of \(\beta_1\) will likely be smaller than its true value (negatively biased).
If \(Corr(X,Z) < 0\) and \(\beta_2 > 0\) and we do not include \(Z\) as a regressor in our model, then our estimate of \(\beta_1\) will likely be smaller than its true value (negatively biased).
If \(Corr(X,Z) < 0\) and \(\beta_2 < 0\) and we do not include \(Z\) as a regressor in our model, then our estimate of \(\beta_1\) will likely be larger than its true value (positively biased).
If you are still unconvinced that excluding \(Z\) from our model of \(Y\) will bias our estimate of \(\beta_1\), consider that if the following is the true model of \(Y\): \[Y = \beta_0 + \beta_1 X + \beta_2 Z + \upsilon\] and instead we estimate \[Y = \beta_0 + \beta_1 X + \varepsilon\] then it must be true that \[ \varepsilon = \beta_2 Z + \upsilon \] which implies that \(Corr(X,\varepsilon) \neq 0\), which violates one of the main assumptions for the linear unbiasedness of the LS estimator! The likely direction of this bias is a product of the covariance/correlation between \(X\) and \(Z\).
Suppose we would like to estimate the effect of education on wage.
Would it be wise to estimate the below regression model?
\[\text{wage} = \beta_0 + \beta_1 \text{education} + \varepsilon\]
Probably not – there are plenty of variables other than education that affect wages while being correlated with education!
Can you think of any?
So the model we should ideally be estimating would look something like the following:
\[\text{wage} = \beta_0 + \beta_1 \text{education} + \beta_2 \text{ability} + \varepsilon\]
Had we estimated the model without controlling for ability, in which direction would \(\beta_1\) likely be biased?
Consider that, intuitively, the following is probably true: - \(Corr(\text{education},\text{ability}) > 0\) - \(\beta_2 > 0\)
Then we know \(\beta_1\) must be biased positively / upward.
In this next example, we will conduct an empirical analysis involving the concepts we have touched on so far.
Load the following packages:
tidyverse – this will be used for data manipulation,
plotting, etc.modelsummary – gives us access to the
modelsummary() function for presenting regression
outputsAER – source of datalibrary(pacman)
p_load(tidyverse, modelsummary, AER);
We will be working with the CASchools dataset that lives
within the AER package.
data(CASchools) # special way to load dataset from `AER`
head(CASchools)
## district school county grades students teachers
## 1 75119 Sunol Glen Unified Alameda KK-08 195 10.90
## 2 61499 Manzanita Elementary Butte KK-08 240 11.15
## 3 61549 Thermalito Union Elementary Butte KK-08 1550 82.90
## 4 61457 Golden Feather Union Elementary Butte KK-08 243 14.00
## 5 61523 Palermo Union Elementary Butte KK-08 1335 71.50
## 6 62042 Burrel Union Elementary Fresno KK-08 137 6.40
## calworks lunch computer expenditure income english read math
## 1 0.5102 2.0408 67 6384.911 22.690001 0.000000 691.6 690.0
## 2 15.4167 47.9167 101 5099.381 9.824000 4.583333 660.5 661.9
## 3 55.0323 76.3226 169 5501.955 8.978000 30.000002 636.3 650.9
## 4 36.4754 77.0492 85 7101.831 8.978000 0.000000 651.9 643.5
## 5 33.1086 78.4270 171 5235.988 9.080333 13.857677 641.8 639.9
## 6 12.3188 86.9565 25 5580.147 10.415000 12.408759 605.7 605.4
This dataset contains 14 variables – we will only be using the following:
students: # of students in a given schoolteachers: # of teachers in a given schoolread: average SAT Reading score in a given scoolmath: average SAT Math score in a given schoolenglish: share of English learning students (non-native
speakers) in a given schooldata_df <- CASchools %>%
select(students, teachers, read, math, english)
Suppose we would like to estimate the effect of classroom size on test scores.
First, we need to construct a measure of classroom size, and a measure of test scores using the given data.
data_df <- data_df %>%
mutate(size = students/teachers,
score = (read + math)/2) %>%
select(-c(students,teachers,read,math)) # Select all but these variables
head(data_df)
## english size score
## 1 0.000000 17.88991 690.80
## 2 4.583333 21.52466 661.20
## 3 30.000002 18.69723 643.60
## 4 0.000000 17.35714 647.70
## 5 13.857677 18.67133 640.85
## 6 12.408759 21.40625 605.55
Let’s plot cross-sections of this data:
ggplot(data_df, aes(x = size, score)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "red") +
theme_minimal()
ggplot(data_df, aes(x = size, english)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "red") +
theme_minimal()
ggplot(data_df, aes(x = english, score)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "red") +
theme_minimal()
Let’s create a correlation matrix using the given sample:
cor(data_df)
## english size score
## english 1.0000000 0.1876424 -0.6441238
## size 0.1876424 1.0000000 -0.2263627
## score -0.6441238 -0.2263627 1.0000000
What story is the above correlation matrix telling us?
So, if we were to estimate below simple regression of
score on size, is our \(\beta_1\) estimate likely to be biased or
unbiased? Why?
\[ \text{score} = \beta_0 + \beta_1 \text{class size} + \varepsilon \]
From the data plots and correlation matrix we know that class size is positive correlated with the share of English learners in the class, which in turn is negatively correlated with the average class score.
Therefore, it is likely the case that our \(\beta_1\) estimate will have negative bias!
What if we instead regress score on both
class size and english by estimating the below
model?
\[ \text{score} = \beta_0 + \beta_1 \text{class size} + \beta_2 \text{english} + \varepsilon \]
We are now controlling for the effect of english on
score, which rids our \(\beta_1\) estimate of omitted variable
bias.
Now let’s actually carry out the above analysis and see what we get:
# Estimate both models
mod_simple <- lm(formula = score ~ size, data = data_df)
mod_multi <- lm(formula = score ~ size + english, data = data_df)
# Create and print regression table
reg_table <- modelsummary(list(mod_simple, mod_multi))
reg_table
| Model 1 | Model 2 | |
|---|---|---|
| (Intercept) | 698.933 | 686.032 |
| (9.467) | (7.411) | |
| size | -2.280 | -1.101 |
| (0.480) | (0.380) | |
| english | -0.650 | |
| (0.039) | ||
| Num.Obs. | 420 | 420 |
| R2 | 0.051 | 0.426 |
| R2 Adj. | 0.049 | 0.424 |
| AIC | 3650.5 | 3441.1 |
| BIC | 3662.6 | 3457.3 |
| Log.Lik. | -1822.250 | -1716.561 |
| F | 22.575 | 155.014 |
| RMSE | 18.58 | 14.46 |
Do these results confirm our initial suspicions?
What can we say about model fit?