# Problem 15.2 speed_read.table("speed.txt") speed names(speed)_c("mpg","mph","V3") attach(speed) plot(mph,mpg) speed.lm_lm(mpg~mph) summary(speed.lm) anova(speed.lm) plot(fitted(speed.lm),resid(speed.lm)) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 12.74637 2.49877 5.101 2.57e-05 *** mph 0.03908 0.05312 0.736 0.469 Residual standard error: 5.666 on 26 degrees of freedom Multiple R-Squared: 0.02039, Adjusted R-squared: -0.01729 F-statistic: 0.5411 on 1 and 26 DF, p-value: 0.4686 Response: mpg Df Sum Sq Mean Sq F value Pr(>F) mph 1 17.37 17.37 0.5411 0.4686 Residuals 26 834.63 32.10 speed.lm2_lm(mpg~mph+I(mph^2)) summary(speed.lm2) anova(speed.lm2) plot(mph,mpg) lines(mph[order(mph)],fitted(speed.lm2)[order(mph)]) plot(fitted(speed.lm2),resid(speed.lm2)) plot(mph,resid(speed.lm2)) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -7.5555495 1.4241091 -5.305 1.69e-05 *** mph 1.2716937 0.0757321 16.792 3.99e-15 *** I(mph^2) -0.0145014 0.0008719 -16.633 4.97e-15 *** Residual standard error: 1.663 on 25 degrees of freedom Multiple R-Squared: 0.9188, Adjusted R-squared: 0.9123 F-statistic: 141.5 on 2 and 25 DF, p-value: 2.338e-14 Response: mpg Df Sum Sq Mean Sq F value Pr(>F) mph 1 17.37 17.37 6.2775 0.01911 * I(mph^2) 1 765.46 765.46 276.6417 4.973e-15 *** Residuals 25 69.17 2.77 speed.lm3_lm(mpg~mph+I(mph^2)+I(mph^3)+I(mph^4)) summary(speed.lm3) plot(mph,mpg) lines(mph[order(mph)],fitted(speed.lm3)[order(mph)]) plot(fitted(speed.lm3),resid(speed.lm3)) plot(mph,resid(speed.lm3)) vote_read.table("vote.txt") attach(vote) plot(Dem1980,Dem1984) vote.lm_lm(Dem1984~Dem1980) summary(vote.lm) plot(fitted(vote.lm),resid(vote.lm)) plot(Dem1980,Dem1984,pch=Southern) vote.lm2_lm(Dem1984~Dem1980+Southern) summary(vote.lm2) plot(fitted(vote.lm2),resid(vote.lm2)) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 13.09754 2.40000 5.457 1.77e-06 *** Dem1980 0.69015 0.06204 11.124 9.22e-15 *** Southern -7.24735 1.13936 -6.361 7.64e-08 *** Residual standard error: 3.092 on 47 degrees of freedom Multiple R-Squared: 0.729, Adjusted R-squared: 0.7175 F-statistic: 63.23 on 2 and 47 DF, p-value: 4.711e-14 vote.lm3_lm(Dem1984~Dem1980*Southern) summary(vote.lm3) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 11.24824 2.50360 4.493 4.71e-05 *** Dem1980 0.73904 0.06492 11.384 5.64e-15 *** Southern 8.19964 7.79798 1.052 0.2985 Dem1980:Southern -0.34524 0.17253 -2.001 0.0513 . Residual standard error: 2.998 on 46 degrees of freedom Multiple R-Squared: 0.7507, Adjusted R-squared: 0.7345 F-statistic: 46.18 on 3 and 46 DF, p-value: 6.367e-14