28
Lecture 1: Preliminary Material Regression III: Advanced Methods William G. Jacoby Department of Political Science Michigan State University

Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

  • Upload
    vanmien

  • View
    231

  • Download
    4

Embed Size (px)

Citation preview

Page 1: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

Lecture 1: Preliminary Material

Regression III:Advanced Methods

William G. Jacoby

Department of Political ScienceMichigan State University

Page 2: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

2

Goals of this lecture1. Show some of the “highlights” of the course

– Applied regression, with attention to modern extensions• Explore methods for “problem” data• Emphasis on “looking” at the data—whenever

possible we will use graphical techniques • Incorporate nonparametric regression within the

general regression framework

2. Get you started using course software– Most statistical analyses for the course will be done

using R– John Fox’s lectures on Statistical Computing Using R/S

are “compulsory”– Some analyses (mainly dynamic graphics) will be

carried out with Arc (from Cook and Weisberg)

Page 3: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

3

Suggested Texts

Cook, R. Dennis and Sanford Weisberg. (1999) Applied Regression Including Computing and Graphics. Wiley Interscience

Fox, John. (1997) Applied Regression Analysis, Linear Models, and Related Methods. Sage.

Fox, John. (2002) An R and S-Plus Companion to Applied Regression. Sage.

Course Materials

Course materials (e.g., Syllabus, datasets, R scripts, etc.) will be placed at: Z:/Jacoby on the Summer Program server and also on the course web site (soon):

http://polisci.msu.edu/jacoby/icpsr/regress3

Page 4: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

4

Brief Review of Linear Regression

• Simple linear regression summarizes the relationship between a quantitative predictor variable and quantitative response variable with a straight line

• The linear model can be extended to handle:—Several explanatory variables (multiple regression)—Categorical independent variables and interactions

between independent variables—Categorical dependent variables—Nonlinear relationships

• The linear model is desirable because it is simple to fit and easy to interpret

• The data must satisfy a number of assumptions, however, for the linear regression model to be the appropriate model to fit

Page 5: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

5

Regression and causation:Inferences from observational data

Criteria for a causal theory• Empirical relationship • Cause precedes the effect in time • Elimination of rival explanations (i.e., no confounding

variables)

Control variables• Regression models with observational data can only

describe the outcomes of social processes—they cannot explain them

• Must control for possible confounding and intervening variables when using observational data

Page 6: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

6

Importance of Control Variables

20 30 40 50 60

1.1

1.2

1.3

1.4

1.5

1.6

Model 1: WVS, all cases

Gini

Attit

udes

tow

ards

ineq

ualit

y(m

ean)

Chile

CzechRepublic

Slovakia

• Relationship is clearly not linear—at low levels of income inequality, attitudes towards inequality are negatively related to the Ginicoefficient; at high levels of inequality the trend is in the opposite direction

• There also may be influential outliers

• Next step: Explore outliers, possible control variables and interactions

Page 7: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

7

Control Variables and Interactions

• Addition of democracy and its interaction with Gini coefficient (allowing for different slopes for the two groups) improves the model, but the effects are still not statistically significant

• Two outliers (Slovakia and Czech Republic) are clearly influential for Non-democracy model

20 30 40 50 60

1.1

1.2

1.3

1.4

1.5

1.6

Model 2:WVS, gini*democracy

Gini

Attit

udes

tow

ards

ineq

ualit

y(m

ean)

DemocraticNon-Democratic

CzechRepublic

Slovakia

Page 8: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

8

Influential Cases

• Czech Republic and Slovakia have unusually high levels of attitudes toward inequality

• When these cases are removed from the model there is an enormous improvement in fit

• Both the Gini coefficient and Democracy have significant effects on attitudes and there is a strong interaction between them

30 40 50 60

1.1

1.2

1.3

1.4

Model 3:WVS, outliers deleted

Gini

Attit

udes

tow

ards

ineq

ualit

y(m

ean)

DemocraticNon-Democratic

Page 9: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

9

Assumptions of Multiple Regression• The following equation accurately describes the “true”

structure of the data (the process that generated the observations):

• The remaining assumptions of the model for ordinary least squares regression (OLS) concern the errors:

1.Constant error variance2. Normally distributed errors3. Uncorrelated error terms4. X’s are independent of the errors

• When these assumptions are met, the OLS estimators are unbiased and efficient estimates of the population parameters

Page 10: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

10

OLS and Nonlinearity (1):Transformable Nonlinearity

• Transformations of one or both variables can help straighten the relationship between two quantitative variables

• Possible only when the nonlinear relationship is simple and monotone– Simple implies that the

curvature does not change—there is one curve

– Monotone implies that the curve is never reverses direction on itself

Page 11: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

11

OLS and Nonlinearity (2):Polynomial Regression• When the relationship is not monotone or simple, we

could try polynomial regression• If there is only one bend in the curve, we fit a quadratic

model—i.e., we could add an X2 (age2) term to the model – For every bend in the curve, we add another

higher term to the model• The two bends below suggest trying a cubic regression

(i.e., include age, age2 and age3 as predictors)

Page 12: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

12

OLS and Nonlinearity (3): Regression Splines

• Allow the regression line to change direction abruptly

• Piecewise polynomial functions that are constrained to join smoothly at points called knots.– Simply regression

models with restricted dummy regressors

– Separate regression lines are fit within regions (i.e., the range of X is partitioned) that join at knots

Page 13: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

13

Handling Complex Nonlinearity:A more general way to think of regression

• Regression traces the conditional distribution of a dependent variable, Y, as a function of one or more explanatory variables, X’s

• As just noted, we can handle nonlinear patterns within the linear regression framework as long as the pattern is not too complex

• If the relationship is not simple and monotone, nonparametric regression and generalized additive models provide alternative ways of capturing the relationship

Page 14: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

14

• With large samples and when the values of X are discrete, it is possible to estimate the regression by directly examining the conditional distribution of Y

• Here we determine the mean of Y(could also use the median) at each value of X:

• A naïve nonparametric regressionline connects the conditional means

• Here a linear regression would work well for the top graph but poorly for the bottom graph

Page 15: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

15

• With extremely large data sets or when the explanatory variable takes on discrete values, we can easily calculate conditional distributions

• In the ‘real world’ of social science data, however, we do not often have this luxury– If X is continuous, even when the sample size is

large, we may not have enough cases at each value of X to calculate precise conditional means

• If, however, we have a large sample we can dissect the range of X into narrow intervals or “bins” that contain many observations, obtaining fairly precise estimates of the conditional mean of Y within each of them– The smaller the sample size, the larger the bin sizes

need to be, and thus the fewer the bins. As long as the relationship between X and Y is not too complicated this is fine; If there is complex nonlinearity it can become problematic

Page 16: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

16

Locally Weighted Scatterplot Smoothing (Lowess … or Loess)

• A form of nonparametric regression that fits a separate weighted least squaresregression line to each xivalue and then joins the fitted values together

• We choose a span for the proportion of the data to be included in each local regression (larger spans provide smoother fit).

• Especially useful when comparing to a linear regression fit– The blue line is s=.2; the

red line is s=.7; the black line is the linear fit

0 5000 10000 15000 20000 25000

2040

6080

Average Income

Pine

o-Po

rter P

rest

ige

Scor

e

Page 17: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

17

Smoothing Splines

• Smoothing splines offer a compromise between global polynomial regression and local polynomial regression– Different piecewise polynomial trends that are

constrained to joined smoothly at the knots– Not as smooth as global polynomial regression, but

generally behave much better at the peaks• Rather than choose a span as for lowess curves, we

usually choose the degrees of freedom—low degrees of freedom will fit a smooth curve; high degrees of freedom will give a rough curve

Page 18: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

18

Linear and Nonparametric fits

• The black line is the linear fit; the red is the lowess smooth from a local linear regression with a span=.6

• A clear departure from linearity in these data

• An F-test comparing the RSS from the linear model with the RSS from the more general trend of the lowesscurve allows us to assess whether the relationship is linear

20 30 40 50 60

1.1

1.2

1.3

1.4

1.5

1.6

gini

secp

ay

LinearLowessSmoothing spline

Page 19: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

19

Multiple Nonparametric Regression

• The regression surface is clearly nonlinear for gini

• As with the simple model, we could test for nonlinearity using an F-test, comparing the RSS of this model with the RSS of the linear model

• If we had only one more predictor, the lowessmodel would be impossible to interpret—we can’t see in more than 3 dimensions

Gini Coefficient

2030

40

50

60

GDP

5000

1000015000

2000025000

Attitudes

1.101.151.20

1.25

1.30

1.35

Page 20: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

20

Generalized Additive Models

• Additive Regression Models overcome the curse of dimensionality by applying local regression to low dimensional projections of the data

• The nonparametric additive regression model is

• Additive models create an estimate of the regression surface by combining k one-dimensional functions (a separate function for each independent variable)• In effect, then, they restrict the nonparametric model

by excluding interactions between the predictors• An estimation procedure called backfitting is used to fit

the models

Page 21: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

21

Generalized Additive Model (2):secpay~s(gdp)+s(gini)

0 5000 15000 25000

-0.1

0.0

0.1

0.2

0.3

gdp

s(gd

p,2.

2)

20 30 40 50 60

-0.1

0.0

0.1

0.2

0.3

gini

s(gi

ni,3

.47)

Page 22: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

22

Influential Cases:Influence Plots

0.05 0.10 0.15 0.20

05

1015

hatvalues(Weakliem.ols)

rstu

dent

(Wea

klie

m.o

ls)

Chile

CzechRepublic Slovakia

Page 23: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

23

OLS and Influential cases

• Measured weight for case 12 was miscoded• Significant effect on regression line and R2

40 60 80 120 160

4060

8010

012

0

With outlier

Measured weight

Rep

orte

d w

eigh

t

12

40 60 80 120 160

4060

8010

012

0

Without outlier

Measured weight

Rep

orte

d w

eigh

t

12

Page 24: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

24

Robust Regression (1)• Robust regression (e.g., M-Estimation with Huber

weights, least-trimmed squares regression) can give a significantly better fit to data with influential cases than does OLS– Both slope coefficients and statistical significance can

change drastically– Residual standard error can also be decreased

significantly• Robust regression relies on large sample sizes,

however, so if we have a small one, we may wish to use bootstrapping in order to have greater confidence in our statistical inferences– Random x-resampling selects R bootstrap samples

of the observations and then recalculates the regression estimates for each, calculating the standard errors from the bootstrap sample

Page 25: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

25

Robust Regression (2)

40 60 80 100 120 140 160

4060

8010

012

0

Measured weight

Rep

orte

d W

eigh

t

12

OLSRobust with Huber weight

Fitted Regression Lines

OLS and robust fits to Davis data

Page 26: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

26

OLS and Joint Influence Votes by County, 2000 US Election

• If all three outliers are included, the regression line is similar as to when they are all deleted

• Jointly BROWARD and DADE have nearly equal influence to the influence of PALM BEACH

• If either PALM BEACH or BROWARD/DADE are deleted separately, however, the OLS fit changes dramatically0 e+00 1 e+05 2 e+05 3 e+05 4 e+05

050

010

0015

0020

0025

0030

0035

00

Votes for Gore

Vote

s fo

r Buc

hana

n

All casesAll outliers deletedDade & Broward deletedPalm Beach deleted

OLS regression lines

BROWARD

DADE

PALM.BEACH

Page 27: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

27

Getting Started with R

• What is R?• A tiny R session• Resources• Setup under Windows• Getting data into R• Graphs and Statistical Models

Page 28: Regression III: Advanced Methods - Department of …polisci.msu.edu/jacoby/icpsr/regress3/lectures/week1/1... · Regression III: Advanced Methods ... – Applied regression, ... Fox,

28

Next topics

• R software • Arc software