24
Diagnostics of Linear Regression Junhui Qian October 27, 2014

Diagnostics of Linear Regression -

  • Upload
    others

  • View
    13

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Diagnostics of Linear Regression -

Diagnostics of Linear Regression

Junhui Qian

October 27, 2014

Page 2: Diagnostics of Linear Regression -

Basics

Nonlinearity

Correlation

Homoscedasticity

Page 3: Diagnostics of Linear Regression -

The Objectives

I After estimating a model, we should always performdiagnostics on the model. In particular, we should checkwhether the assumptions we made are valid.

I For OLS estimation, we should usually check:I Is the relationship between x and y linear?I Are the residuals serially uncorrelated?I Are the residuals uncorrelated with explanatory variables?

(endogeneity)I Does homoscedasticity hold?

Page 4: Diagnostics of Linear Regression -

Residuals

I Residuals are unobservable. But they can be estimated:

ui = yi − x ′i β.

I Using matrix language,

u = (I − PX )Y .

I If β is close to β, then ui is close to ui .

I Let yi = x ′i β, we call yi the “the fitted value”.

I Then the explained variable can be decomposed into

yi = yi + ui .

Page 5: Diagnostics of Linear Regression -

Variations

I SST (total sum of squares)

SST ≡n∑

i=1

(yi − y)2 = Y ′(I − Pι)Y .

I SSE (explained sum of squares)

SSE ≡n∑

i=1

(yi − y)2 = Y ′(PX − Pι)Y .

I SSR (sum of squared residuals)

SSR ≡n∑

i=1

u2i = Y ′(I − PX )Y .

I We have SST = SSE+ SSR.

Page 6: Diagnostics of Linear Regression -

Goodness of Fit

I R2 of the regression:

R2 ≡ SSE/SST = 1− SSR/SST.

I R2 is the fraction of the sample variation in y that isexplained by x . And we have 0 ≤ R2 ≤ 1.

I R2 does NOT validate a model. A high R2 only says that y ispredictable with information in x . In social science, this is notthe case in general.

I If additional regressors are added to a model, R2 will increase.

I The adjusted R2, denoted as R2, is designed to penalize thenumber of regressors,R2 = 1− [SSR/(n − 1− k)]/[SST/(n − 1).

Page 7: Diagnostics of Linear Regression -

−4 −2 0 2 4−4

−2

0

2

4

6Low R2

X

Y

−4 −2 0 2 4−3

−2

−1

0

1

2

3

4High R2

X

Y

Page 8: Diagnostics of Linear Regression -

Residual Plots

We can plot

I Residuals

I Residuals versus Fitted Value

I Residuals versus Explanatory Variables

Any pattern in residual plots suggests nonlinearity or endogeneity.

Page 9: Diagnostics of Linear Regression -

−4 −2 0 2 4−4

−2

0

2

4

6

8

10Regression

Y

0 20 40 60 80 100−4

−2

0

2

4

6Residuals

Res

idua

ls

−4 −2 0 2 4−4

−2

0

2

4

6Residuals v.s. Regressor

Res

idua

ls

X−2 0 2 4 6

−4

−2

0

2

4

6Residuals v.s. Fitted Value

Residuals

Fitt

ed V

alue

Figure : Residual Plots. DGP: y = 0.2 + x + 0.5x2 + u

Page 10: Diagnostics of Linear Regression -

Partial Residual Plots

I To see whether there exists nonlinearity in a regressor, say thej-th explanatory variable xj , We can plot

u + βjxj versus xj ,

where u is residual from the full model.

I Partial residual plots may help us find the true (nonlinear)functional form of xj .

Page 11: Diagnostics of Linear Regression -

Partial Residual Plots: Example

Suppose the true model is

y = β0 + β1x + β2z + g(z) + u,

where g(z) is a nonlinear function. We mistakenly estimate:

y = β0 + β1x + β2z + u.

If we plot β2z + u versus z , we may probably be able to detectnonlinearity in g(z).

Page 12: Diagnostics of Linear Regression -

−3 −2 −1 0 1 2 3 4−4

−2

0

2

4

6

8

10

12Partial Residual Plot

Z

Par

tial r

esid

ual

Figure : Residual Plots. DGP: y = 0.2 + x + 0.5z + z2 + u

Page 13: Diagnostics of Linear Regression -

The iid Assumption

I The CLR assumption dictates that residuals should be iid.

I It is generally difficult to determine whether a given numberof observations are from the same distribution.

I If there is a natural order of the observations (e.g., time),then we may check whether the residuals are correlated.

I If there is correlation, then the iid assumption is violated.

Page 14: Diagnostics of Linear Regression -

Residuals with Time

I When we deal with time series regression, for example,

πt = β0 + β0mt + ut ,

where πt is the inflation rate and mt is the growth rate ofmoney supply, both indexed by time t.

I Now the “natural order” is time, and a time series plot of theestimated residual contains information.

Page 15: Diagnostics of Linear Regression -

Residual Plots

We can plot:

I Residuals over time

I Residuals v.s. previous residual

I Correlogram

Page 16: Diagnostics of Linear Regression -

−4

−2

0

2

4No Correlation

−4

−2

0

2

4Weak Correlation

0 20 40 60 80 100 120 140 160 180 200−10

−5

0

5

10Strong Correlation

Time

Figure : Residuals over time: ut = αut−1 + εt , α = 0, 0.5, 0.95, from topto bottom.

Page 17: Diagnostics of Linear Regression -

−2 0 2 4−2

−1

0

1

2

3

ut−1

u t

No Correlation

−5 0 5−3

−2

−1

0

1

2

3

4

ut−1

u t

Weak Correlation

−5 0 5 10−6

−4

−2

0

2

4

6

8

ut−1

u t

Strong Correlation

Figure : Residuals v.s. previous residual: ut = αut−1 + εt ,α = 0, 0.5, 0.95, from left to right.

Page 18: Diagnostics of Linear Regression -

0 20 40−0.2

0

0.2

0.4

0.6

0.8

1

1.2

Lag

No Correlation

0 20 40−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

Lag

Weak Correlation

0 20 400

0.2

0.4

0.6

0.8

1

Lag

Strong Correlation

Figure : Correlograms: ut = αut−1 + εt , α = 0, 0.5, 0.95, from left toright.

Page 19: Diagnostics of Linear Regression -

Durbin-Watson Test

I Durbin-Watson is the formal test for independence, or moreprecisely, non-correlation.

I It assumes a AR(1) model for ut , ut = αut−1 + εt .

I The null hypothesis is: H0 : ρ = α = 0.

I The test statistic is

DW =

∑Tt=2(ut − ut−1)

2∑Tt=1 u

2t−1

.

Page 20: Diagnostics of Linear Regression -

Durbin-Watson Test

I DW ∈ [0, 4].

I DW = 2 indicates no autocorrelation.

I If DW is substantially less than 2, there is evidence of positiveserial correlation. As a rough rule of thumb, if DW is lessthan 1.0, there may be cause for alarm.

I Small values of DW indicate successive error terms are, onaverage, close in value to one another, or positively correlated.

I Large values of DW indicate successive error terms are, onaverage, much different in value to one another, or negativelycorrelated.

Page 21: Diagnostics of Linear Regression -

Fixing Correlation

I It’s most likely that the model is misspecified.I The usual practices are:

I Add more explanatory variablesI Add more lags of the existing explanatory variables

Page 22: Diagnostics of Linear Regression -

I If var(ui |x) = σ2, we call the model “homoscedastic”. If not,we call it “heteroscedastic”.

I If homoscedasticity does not hold, but CLR Assumptions 1-4still hold, the OLS estimator is still unbiased and consistent.However, OLS is no longer BLUE.

I We can detect heteroscedasticity by looking at the residualsv.s. regressors.

I For simple regressions, we can look at regression lines.I And we can formally test for homoscedasticity.

I White testI Breusch-Pagan test

Page 23: Diagnostics of Linear Regression -

0 0.5 1 1.5 2 2.5−2

−1

0

1

2

X

Res

idua

lsHeteroscedasticity

0 0.5 1 1.5 2 2.5−0.5

0

0.5

1

1.5

2

2.5

3

X

Y

Regression Line

Figure : Heteroscedasticity. DGP: yi = β0 + 0.5xi + xiεi .

Page 24: Diagnostics of Linear Regression -

Fixing Heteroscedasticity

I Use a different specification for the model (different variables,or perhaps non-linear transformations of the variables).

I Use GLS (Generalized Least Square).