# 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

A: Plot your data for all independent variable relationships to the dependent variable (as always). Be sure to include informative figure captions.

plot(mpg ~ hp, data=mtcars)

plot(mpg ~ wt, data=mtcars)

hist(mtcars$hp) 

hist(mtcars$wt)

B: Are your continuous variables displaying normal distribution? Provide two pieces of evidence that display your normality assessment for each variable.

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)

C: Did you transform one or more of your variables? If so, state which transformation you used. Provide two pieces of evidence that your data more closely approximates a normal distribution. If not, state why you did not transform the data.

No I did not transform my data because it was normal.

D: Create the final multiple linear regression object with the appropriate data (raw or transformed) including the interaction. Be sure to place the variables on the correct axis. Present your code.

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

E: Did you accept or reject the null hypothesis for the interaction? Are the results statistically significant? Provide and interpret two evidence graphs that the residuals meet the assumptions of the linear model.

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.

F: Did you drop the interaction term? Why or why not? If so, provide and interpret the output and two evidence graphs that residuals meet the assumptions of the linear model.

I do not drop the interaction term because my data was significant.

G: Summarize your results in a paragraph similar to the example in the Reporting Your Results section.

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!