21.04.2014 Views

1h6QSyH

1h6QSyH

1h6QSyH

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

290 7. Moving Beyond Linearity<br />

between wage and age. Weusethe anova() function, which performs an anova()<br />

analysis of variance (ANOVA, using an F-test) in order to test the null<br />

analysis of<br />

variance<br />

hypothesis that a model M 1 is sufficient to explain the data against the<br />

alternative hypothesis that a more complex model M 2 is required. In order<br />

to use the anova() function, M 1 and M 2 must be nested models: the<br />

predictors in M 1 must be a subset of the predictors in M 2 .Inthiscase,<br />

we fit five different models and sequentially compare the simpler model to<br />

the more complex model.<br />

> fit.1=lm(wage∼age,data=Wage)<br />

> fit.2=lm(wage∼poly(age ,2),data=Wage)<br />

> fit.3=lm(wage∼poly(age ,3),data=Wage)<br />

> fit.4=lm(wage∼poly(age ,4),data=Wage)<br />

> fit.5=lm(wage∼poly(age ,5),data=Wage)<br />

> anova(fit.1,fit.2,fit.3,fit.4,fit.5)<br />

Analysis of Variance Table<br />

Model 1: wage ∼ age<br />

Model 2: wage ∼ poly(age, 2)<br />

Model 3: wage ∼ poly(age, 3)<br />

Model 4: wage ∼ poly(age, 4)<br />

Model 5: wage ∼ poly(age, 5)<br />

Res.Df RSS Df Sum of Sq F Pr(>F)<br />

1 2998 5022216<br />

2 2997 4793430 1 228786 143.59 |t|)<br />

(Intercept ) 111.70 0.7288 153.2780 0.000e+00<br />

poly(age, 5)1 447.07 39.9161 11.2002 1.491e-28<br />

poly(age, 5)2 -478.32 39.9161 -11.9830 2.368e-32<br />

poly(age, 5)3 125.52 39.9161 3.1446 1.679e-03

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!