Multiple Regression The following dataset gives information on makes of cars taken from the April, 1990 issue of Consumer Reports. In particular, the data frame "fuel.frame" contains data on mileage, weight of car, engine displacement and size of car (qualitative, 6 possibilities, saved under "Type"). Question: Can we use a regression model to predict mileage from some of these variables? We should begin with some plots to study the relationships among the variables. Size of car is qualitative, but R can figure this out under "plot": > plot(Mileage ~ Type, fuel.frame) Regression is done in R using the "lm" command, for linear model. > fuel.fit <- lm(Mileage ~ Weight, fuel.frame) > fuel.fit1 <- lm(Mileage ~ Weight+ Disp., fuel.frame) If we wanted to use all the variables in our data frame, we'd do the following: > lm(Mileage ~ ., fuel.frame) > fuel.fit Call: lm(formula = Mileage ~ Weight, data = fuel.frame) Coefficients: (Intercept) Weight 48.349347 -0.008193 > summary(fuel.fit1) Call: lm(formula = Mileage ~ Weight + Disp., data = fuel.frame) Residuals: Min 1Q Median 3Q Max -4.5726 -1.5814 -0.2569 1.8499 4.6783 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 44.379702 2.654526 16.719 < 2e-16 *** Weight -0.006044 0.001188 -5.088 4.23e-06 *** Disp. -0.016540 0.007641 -2.165 0.0346 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.485 on 57 degrees of freedom Multiple R-squared: 0.7402, Adjusted R-squared: 0.7311 F-statistic: 81.21 on 2 and 57 DF, p-value: < 2.2e-16 > fuel.fit1$residuals # Gives residuals > residuals(fuel.fit1) # Does same thing. R prefers this method. > coefficients(fuel.fit1) # Gives coefficient estimates > predict(fuel.fit1) # Gives predicted values for mileages > anova(fuel.fit1) # NOTE: This adds terms sequentially (first to last) Analysis of Variance Table Response: Mileage Response: Mileage Df Sum Sq Mean Sq F value Pr(>F) Weight 1 973.75 973.75 157.7259 < 2e-16 *** Disp. 1 28.93 28.93 4.6863 0.03461 * Residuals 57 351.90 6.17 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > par(mfrow=c(2,2)) > plot(fuel.fit1) # Gives some summary plots of the fitted model