# Motor Trend Car Road Tests ####
# The data was extracted from the 1974 Motor Trend US magazine, and
# comprises fuel consumption and 10 aspects of automobile design and
# performance for 32 automobiles (1973-74 models)
data("mtcars")
head(mtcars)## mpg cyl disp hp drat wt qsec vs am gear carb
## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
## Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
## Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
## Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
## Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
## Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
plot(mpg ~ hp, data=mtcars)plot(mpg ~ wt, data=mtcars)hist(mtcars$hp) hist(mtcars$wt)All of my data is displaying normal distribution.
qqnorm(mtcars$hp) #showing normality of hp
qqline(mtcars$hp)qqnorm(mtcars$wt) #showing normality of wt
qqline(mtcars$wt)qqnorm(mtcars$mpg) #showing normality of mpg
qqline(mtcars$mpg)No I did not transform my data because it was normal.
mtcars.LM <- lm(mpg ~ hp + wt, data= mtcars)
plot(mtcars.LM)summary(mtcars.LM)##
## Call:
## lm(formula = mpg ~ hp + wt, data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.941 -1.600 -0.182 1.050 5.854
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 37.22727 1.59879 23.285 < 2e-16 ***
## hp -0.03177 0.00903 -3.519 0.00145 **
## wt -3.87783 0.63273 -6.129 1.12e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.593 on 29 degrees of freedom
## Multiple R-squared: 0.8268, Adjusted R-squared: 0.8148
## F-statistic: 69.21 on 2 and 29 DF, p-value: 9.109e-12
mtcars.LM3 <- lm(mpg ~ hp + wt + hp * wt, data= mtcars)
plot(mtcars.LM3)summary(mtcars.LM3)##
## Call:
## lm(formula = mpg ~ hp + wt + hp * wt, data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.0632 -1.6491 -0.7362 1.4211 4.5513
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 49.80842 3.60516 13.816 5.01e-14 ***
## hp -0.12010 0.02470 -4.863 4.04e-05 ***
## wt -8.21662 1.26971 -6.471 5.20e-07 ***
## hp:wt 0.02785 0.00742 3.753 0.000811 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.153 on 28 degrees of freedom
## Multiple R-squared: 0.8848, Adjusted R-squared: 0.8724
## F-statistic: 71.66 on 3 and 28 DF, p-value: 2.981e-13
I rejected my null hypothesis and accepted my alternate hypothesis. My results were statistically significant. I installed the packages for the evidence graphs, but I could not get them to work.
I do not drop the interaction term because my data was significant.
The overall multiple linear regression model for mtcars horsepower vs. mtcars weight and mtcars miles per gallon was significant. (p-value=0.000811; Multiple R-squared=0.8848) A significant positive relationship exists between mtcars weight and miles per gallon. A significant positive relationship also exists between mtcars horsepower and miles per gallon. The interaction term was not dropped because my data was significant.
Please turn–in your homework via Sakai by saving and submitting an R Markdown PDF or HTML file from R Pubs!