hw09_pengyu2.html

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

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

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)

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

View Full Document
## ## 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)

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

View Full Document
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
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)

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

View Full Document
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.
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)

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

View Full Document
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.
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)

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern