###Q2 code ###Plot y vs. x plot(dat2$x,dat2$y) abline(lm(y~x, data=dat2)) ###Output of first-order model mod1 <- lm(y~x, data=dat2) summary(mod1) ###Make residuals plots plot(fitted(mod1),residuals(mod1)) ###Output of second-order model mod2 <- lm(y~x + I(x^2), data=dat2) summary(mod2) ###Make residuals plots plot(fitted(mod2),residuals(mod2)) ###Add curve to plot plot(dat2$x,dat2$y) x <- dat2$x curve(mod2$coefficients[1] + mod2$coefficients[2]*x + mod2$coefficients[3]*x^2, from=2, to=16, add=T) ###True model fit modt <- lm(y ~ x + I(x^2) + w, data=dat2) summary(modt)