Linear models

“Well-specified” linear models

  1. In population, \(y=\beta_0+\beta_{1}x_{1}+\beta_{2}x_{2}+\ldots+\beta_{k}x_{k}+u\)
  2. \({(y_i,\mathbf{x}_i^\prime):i=1 \ldots n}\) are independent random sample of observations following 1
  3. There are no exact linear relationships among the variables \(x_0 \ldots x_k\)
  4. \(E(u|\mathbf{x})=0\)
  5. \(Var(u|x)=\sigma^2\) a constant \(>0\)
  1. \(u \sim N(0,\sigma^2)\)

What we can say under different subsets

What more can we say, under what assumptions

Multivariate Wage regression, (Code)

# Obtain access to data sets used in our textbook
library(foreign) 
#Load library to make pretty table
library(stargazer)
# Import data set of education and wages
wage1<-read.dta(
  "http://fmwww.bc.edu/ec-p/data/wooldridge/wage1.dta")
# Regress log wage on years of education and experience
wageregression2 <- lm(formula = lwage ~ educ + exper, 
                      data = wage1)
# Make table
stargazer(wageregression2,header=FALSE,
  type="html",        
  font.size="tiny", 
  title="Log Wage vs Years of Education, 
  Years of Experience")

Multivariate Wage regression, again

Log Wage vs Years of Education, Years of Experience
Dependent variable:
lwage
educ 0.098***
(0.008)
exper 0.010***
(0.002)
Constant 0.217**
(0.109)
Observations 526
R2 0.249
Adjusted R2 0.246
Residual Std. Error 0.461 (df = 523)
F Statistic 86.862*** (df = 2; 523)
Note: p<0.1; p<0.05; p<0.01

Note on performing tests in R

summary(wageregression2)

Variable choice

How does adding experience change education coefficient? (code 1)

#Run short regression without experience directly
wageregression1<-lm(formula = lwage ~ educ, data = wage1)
betatilde1<-wageregression1$coefficients[2]

#Run regression of omitted variable on included variable
deltareg<-lm(formula = exper ~ educ, data = wage1)

##Display Table with all results
stargazer(wageregression1,wageregression2,deltareg,
          type="html",
    header=FALSE, report="vc",
    omit.stat=c("all"),omit.table.layout="n",
    font.size="small", 
    title="Included and Excluded Experience")

How does adding experience change education coefficient? (code 2)

#Construct short regression coefficient 
# from formula on next slide
delta1<-deltareg$coefficients[2]
betahat1<-wageregression2$coefficients[2] 
betahat2<-wageregression2$coefficients[3] 
omittedformula<-betahat1+betahat2*delta1

How does adding experience change education coefficient?

Included and Excluded Experience
Dependent variable:
lwage exper
(1) (2) (3)
educ 0.083 0.098 -1.468
exper 0.010
Constant 0.584 0.217 35.461

Omitted variables formula

Bias?

Interpretation

Nonlinearities

Residual plot

Regression residuals (Code)

#Plot residuals
plot(wage1$exper,wageregression2$residuals, 
     ylab="Regression Residuals",
     xlab="Years of Experience", main="Residual Plot")

Regression residuals appear to be predictable from experience

A nonlinear prediction (Code)

#Add a nonlinear transform of experience to x
wage1$exper2<-(wage1$exper)^2
#Run the augmented regression
wageregression3 <- lm(formula = 
        lwage ~ educ + exper + expersq, data = wage1)
#Display output of regression
stargazer(wageregression3,header=FALSE,
          type="html",
    single.row=TRUE,omit.stat=c("adj.rsq","ser"),
    font.size="tiny", 
    title="Log Wage vs Years of Education,
    Years of Experience")

A nonlinear prediction

Log Wage vs Years of Education, Years of Experience
Dependent variable:
lwage
educ 0.090*** (0.007)
exper 0.041*** (0.005)
expersq -0.001*** (0.0001)
Constant 0.128 (0.106)
Observations 526
R2 0.300
F Statistic 74.668*** (df = 3; 522)
Note: p<0.1; p<0.05; p<0.01

Residuals now show no easily discernible pattern (Code)

plot(wage1$exper,wageregression3$residuals, 
     ylab="Augmented Regression Residuals",
     xlab="Years of Experience",main="Residual Plot")

Residuals now show no easily discernible pattern

Inference with nonlinear predictors

linearHypothesis(wageregression3,
                 c("exper = 0","expersq = 0"))

Results of F test (Code 1)

library(car)  #A library for performing tests
#F test that coefficients on experience 
# and experience^2 both 0 
linearHypothesis(wageregression3,
                 c("exper = 0","expersq = 0"))

Results of F test (Code 2)

#Manual construction
#Run restricted regression
restrictedreg<-lm(formula = lwage ~ educ, data = wage1)
#Restricted residual sum of squares
RSS_r<-sum((restrictedreg$residuals)^2)
#Unrestricted residual sum of squares
RSS_u<-sum((wageregression3$residuals)^2)
#Difference in degrees of freedom
q<-restrictedreg$df-wageregression3$df 
#Formula
(Fstat<-((RSS_r-RSS_u)/q)/(RSS_u/wageregression3$df))
#p value: reject H0 if small
(pvalue<-1-pf(Fstat,q,wageregression3$df))

Results of F test

## Linear hypothesis test
## 
## Hypothesis:
## exper = 0
## expersq = 0
## 
## Model 1: restricted model
## Model 2: lwage ~ educ + exper + expersq
## 
##   Res.Df    RSS Df Sum of Sq      F    Pr(>F)    
## 1    524 120.77                                  
## 2    522 103.79  2    16.979 42.696 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Meaning of OLS estimate without linearity

But why should we care?

Why care about linear predictors?

Proof

\[E[(y-f(\mathbf{x}))^{2}]=E[y^2-2yf(\mathbf{x})+f(\mathbf{x})^2]\] \[=E[E[y^2-2yf(\mathbf{x})+f(\mathbf{x})^2|\mathbf{x}]]\] \[=E[E[y^2|\mathbf{x}]-2E[y|\mathbf{x}]f(\mathbf{x})+f(\mathbf{x})^2]\]

\[0=-2E[y|\mathbf{x}]+2f(\mathbf{x})\ \forall\mathbf{x}\] \[f(\mathbf{x})=E[y|\mathbf{x}]\]

Conditional expectation functions

Useful special case: discrete \(\mathbf{x}\)

When c.e.f. isn’t linear

\[\beta=\underset{\beta\in\mathbb{R}^{k+1}}{\arg\min}E[(y-\mathbf{x}^{\prime}\beta)^{2}]=\underset{\beta\in\mathbb{R}^{k+1}}{\arg\min}E[(E[y|\mathbf{x}]-\mathbf{x}^{\prime}\beta)^{2}]\]

Proof

\[E[(y-\mathbf{x}^{\prime}\beta)^{2}]=E[(y-E[y|\mathbf{x}]+E[y|\mathbf{x}]-\mathbf{x}^{\prime}\beta)^{2}]\] \[=E[(y-E[y|\mathbf{x}])^{2}+2*(y-E[y|\mathbf{x}])(E[y|\mathbf{x}]-\mathbf{x}^{\prime}\beta)+(E[y|\mathbf{x}]-\mathbf{x}^{\prime}\beta)^{2}]\] \[=E[(y-E[y|\mathbf{x}])^{2}+(E[y|\mathbf{x}]-\mathbf{x}^{\prime}\beta)^{2}]\]

What does this look like? (Code)

#Initialize random number generator
set.seed(20)
#Generate some data from a nonlinear relationship
x1<-rnorm(500,mean = 3, sd=5)
trueerror<-rnorm(500) #Residual from true relationship
#Not same as OLS residual
#A nonlinear relationship: E[y|x]=2*sin(x)
y1<-2*sin(x1)+trueerror 
# Run a regression in which c.e.f. not linear in x
#Include a polynomial terms to allow nonlinearity
misspecifiedregression<-lm(y1 ~ x1 + I(x1^2) + I(x1^3))

What does this look like?

Plot prediction and c.e.f. (Code)

#Generate x values at which to evaluate functions
xinterval<-seq(from=min(x1),to = max(x1),length.out=1000)
new<-data.frame(x1=xinterval)
#Calculate $x'\hat{\beta}$ using predict command
pred<-predict(misspecifiedregression,new)
#plot Data, O.L.S. predictions, and c.e.f.
plot(x1,y1, xlab = "x", ylab="y", 
     main="Data, CEF, and OLS Predicted Values")
points(xinterval,pred, col = "red") #OLS Predictions
points(xinterval,2*sin(xinterval), col = "blue") #True CEF

Plot prediction and c.e.f.

What to make of OLS

Conclusions

Next time