# Exercise 4.2 Montgomery library(MPV) # contains the dataset table.b1 library(MASS) # needed for studres library(car) # needed for avPlots # a) lm.fit <- lm(y ~ x2 + x7 + x8, data = table.b1) par(mfrow = c(2, 2)) summary(lm.fit) qqnorm(rstandard(lm.fit)) qqnorm(lm.fit$residuals) # QQ-plot seems ok, with a slight deviance in the middle # b) plot(lm.fit$fitted.values, lm.fit$residuals) plot(lm.fit$fitted.values, rstandard(lm.fit)) # c) par(mfrow = c(1, 3)) plot(table.b1$x2, lm.fit$residuals) plot(table.b1$x7, lm.fit$residuals) plot(table.b1$x8, lm.fit$residuals) # seem to be correctly specified, but for x7 and maybe x2, the variance seem to # depend on y_hat (non constant variance), which indicate violation of the # regression assumption of constant variance. # d) avPlots(lm.fit) # Added variable plots (Partial regression plot) # See that all the partial residuals follows a straight line with nonzero slope # meaning that the variables should be in the model. # e) par(mfrow = c(1, 2)) sres <- studres(lm.fit) data.frame(sres) plot(lm.fit$fitted.values, sres, main = "Studentized residuals") # R-student rstud <- rstudent(lm.fit) data.frame(rstud) plot(lm.fit$fitted.values, rstud, main = "R-student residuals") # pnorm(2.454354223, lower.tail = FALSE) #