hw09_pengyu2.html - STAT 420 Homework 9 Pengyu Chen...

Info icon This preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
STAT 420: Homework 9 Pengyu Chen, NetID:pengyu2 Assignment Exercise 1 (TV is Healthy?) Exercise 2 (Brains) Exercise 3 (EPA Emissions Data, revisited) Exercise 4 (Bigger Is Better?) Assignment Exercise 1 (TV is Healthy?) For this exercise we will use the tvdoctor data which can be found in the faraway package. After loading the faraway package, use ?tvdoctor to learn about this dataset. library(faraway) (a) Fit a simple linear regression with life as the response and tv as the predictor. Plot a scatterplot and add the fitting line. Check the assumptions of this model. fit1 = lm(life ~ tv, data = tvdoctor) plot(life ~ tv, data = tvdoctor, col = "dodgerblue", pch = 20, cex = 1.5) abline(fit1, col = "darkorange", lwd = 2)
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
library(lmtest) ## Loading required package: zoo
Image of page 2
## ## Attaching package: 'zoo' ## The following objects are masked from 'package:base': ## ## as.Date, as.Date.numeric bptest(fit1) ## ## studentized Breusch-Pagan test ## ## data: fit1 ## BP = 0.15641, df = 1, p-value = 0.6925 shapiro.test(resid(fit1)) ## ## Shapiro-Wilk normality test ## ## data: resid(fit1) ## W = 0.96076, p-value = 0.201 plot(fitted(fit1), resid(fit1), col = "dodgerblue", pch = 20, cex = 1, xlab = "Fitted", ylab = "Residuals") abline(h = 0, lty = 2, col = "orange", lwd = 2)
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Since the p-values for Breusch-Pagan test and Shapiro-Wilk normality test are both pretty large, we say the constant variance assumption and the normality assumption are held. However, we see a rather obvious pattern in the fitted versus residuals plot that there is no linear relationship between the response
Image of page 4
and the predictor. The Linearity assumption is violated and we also feel suspecious about the constant variance assumption because we do see that for larger fitted values, the spread of the residuals is larger. Therefore, the constant variance assumption is also violated. (b) Fit higher order polynomial models of degree 3, 5, and 7. For each, plot a fitted versus residuals plot and comment on the constant variance assumption. Based on those plots, which of these three models to you think are acceptable? Use a statistical test(s) to compare the models you just chose. Based on the test, which is preferred? Check the normality assumption of this model. Identify any influential observations of this model. fit_poly3 = lm(life ~ tv + I(tv ^ 2) + I(tv ^ 3), data = tvdoctor) plot(fitted(fit_poly3), resid(fit_poly3), xlab = "Fitted", ylab = "Residuals", col = "dodgerblue", pch = 20, cex =2) abline(h = 0, col = "darkorange", lwd = 2)
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
We see a rather obvious pattern in the fitted versus residuals plot that for larger fitted values, the spread of the residuals is larger. So the constant variance assumption is violated for the model of degree 3.
Image of page 6
fit_poly5 = lm(life ~ tv + I(tv ^ 2) + I(tv ^ 3) + I(tv ^ 4) + I(tv ^5), data = tvdoctor) plot(fitted(fit_poly5), resid(fit_poly5), xlab = "Fitted", ylab = "Residuals", col = "dodgerblue", pch = 20, cex =2) abline(h = 0, col = "darkorange", lwd = 2)
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
On the fitted versus residuals plot, we see that the variance remains about the same as the fitted value increases. So the constant variance assumption holds for the model of degree 5.
Image of page 8
fit_poly7 = lm(life ~ tv + I(tv ^ 2) + I(tv ^ 3) + I(tv ^ 4) + I(tv ^5) + I(tv ^ 6) + I(tv ^ 7), data = tvdoctor) plot(fitted(fit_poly7), resid(fit_poly7), xlab = "Fitted", ylab = "Residuals", col = "dodgerblue", pch = 20, cex =2) abline(h = 0, col = "darkorange", lwd = 2)
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern