Sunteți pe pagina 1din 5

# Regression Models - Peer

Assessments
Executive Summary
industry.
It focus on exploring the relationship between a set of variables and miles per gallon. It
includes :
Is an automatic or manual transmission better for MPG It can be seen that manual is
with greater Miles/(US) gallon
Quantifying how different is the MPG between automatic and manual transmissions?
mtcars\$cyl <- factor(mtcars\$cyl)
mtcars\$vs <- factor(mtcars\$vs)
mtcars\$gear <- factor(mtcars\$gear)
mtcars\$carb <- factor(mtcars\$carb)
mtcars\$am <- factor(mtcars\$am)
Investigate the relationship between MPG, AM
fit <- lm(mpg ~ am, data = mtcars)
fit
##
## Call:
## lm(formula = mpg ~ am, data = mtcars)
##
## Coefficients:
## (ntercept) am!
## !"#!\$ "#%&
Coefficient is shown.
Exploratory data analyses
plot(mtcars\$am, mtcars\$mpg)
summary(fit)
Regression Models - Peer Assessments file:///C:/Users/Tommy Chan/c9a1/c8a1.html
1 of 5 6/23/2014 1:17 AM
##
## Call:
## lm(formula = mpg ~ am, data = mtcars)
##
## 'esiduals:
## (in !) (edian *) (a+
## -,#*,% -*#-,% --#%," *#%&& ,#\$-.
##
## Coefficients:
## /stimate 0td# /rror t value 1r(23t3)
## (ntercept) !"#!\$ !#!% !\$#%\$ !#!e-!\$ 444
## am! "#%& !#"5 &#!! -#---%, 444
## ---
## 0ignif# codes: - 64446 -#--! 6446 -#-! 646 -#-\$ 6#6 -#! 6 6 !
##
## 'esidual standard error: &#, on *- degrees of freedom
## (ultiple '-s7uared: -#*5, 8d9usted '-s7uared: -#**.
## :-statistic: !5#, on ! and *- ;:, p-value: -#---%.\$
abline(fit)
inference Inference is done in it
Regression Models - Peer Assessments file:///C:/Users/Tommy Chan/c9a1/c8a1.html
2 of 5 6/23/2014 1:17 AM
It can be seen that manual is with greater Miles/(US) gallon
Model Selection Fit multiple models and detail their strategy for model selection - Choose
the best one with AM in it
# 1lot a main effect for eac< column of mtcars (e+cept mpg) nitial model in
# step-=ise selection
fit#all <- lm(mpg ~ #, data = mtcars)
result#step <- step(fit#all, direction = >bot<>, scope = list(lo=er = ~am))
summary(result#step)
##
## Call:
## lm(formula = mpg ~ cyl ? <p ? =t ? am, data = mtcars)
##
## 'esiduals:
## (in !) (edian *) (a+
## -*#,*, -!#%\$5 --#&-! !#!%\$ \$#-\$!
##
## Coefficients:
## /stimate 0td# /rror t value 1r(23t3)
## (ntercept) **#"-.* %#5-&, !%#,& "#"e-!* 444
## cyl5 -*#-*!* !#&-"* -%#!\$ -#-&-" 4
## cyl. -%#!5*" %#%.&* --#,\$ -#*\$%*
## <p --#-*%! -#-!*" -%#*\$ -#-%5, 4
## =t -%#&,5. -#..\$5 -%#.% -#--,! 44
## am! !#.-,% !#*,5* !#*- -#%-5\$
## ---
## 0ignif# codes: - 64446 -#--! 6446 -#-! 646 -#-\$ 6#6 -#! 6 6 !
##
## 'esidual standard error: %#&! on %5 degrees of freedom
## (ultiple '-s7uared: -#.55, 8d9usted '-s7uared: -#.&
## :-statistic: **#5 on \$ and %5 ;:, p-value: !#\$!e-!-
From the above model details, we observe that the adjusted R2 value is 0.84. hence more
than 84% of the variability is shown by the above model.
The questions of interest is answered
Appendix
Model Diagnostics Residual plot and some diagnostics
fit <- lm(mpg ~ am, data = mtcars)
plot(residuals(fit), fitted#values(fit))
Regression Models - Peer Assessments file:///C:/Users/Tommy Chan/c9a1/c8a1.html
3 of 5 6/23/2014 1:17 AM
77norm(residuals(fit))
Regression Models - Peer Assessments file:///C:/Users/Tommy Chan/c9a1/c8a1.html
4 of 5 6/23/2014 1:17 AM
Regression Models - Peer Assessments file:///C:/Users/Tommy Chan/c9a1/c8a1.html
5 of 5 6/23/2014 1:17 AM