# # EPage 215 # # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- save_plots = F #install.packages("MPV") library(lattice) # needed for xyplot library(DAAG) library(MPV) set.seed(0) table.b3$x11 = as.factor( table.b3$x11 ) # Part (a): if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter6/prob_10_y_vs_x1_scatter_plot.eps", onefile=FALSE, horizontal=FALSE) } plot( y ~ x1, data=table.b3 ) if( save_plots ){ dev.off() } # Part (b): xyplot( y ~ x1 | x11, data=table.b3 ) # Part (c): m0 = lm( y ~ x1 + x11, data=table.b3 ) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter6/prob_10_y_vs_x1_N_x11_resid_vs_fitted_plot.eps", onefile=FALSE, horizontal=FALSE) } plot( m0, which=1 ) if( save_plots ){ dev.off() } # Lets add a quadradic term and see how well this improves the model ... it actually looks better: m1 = lm( y ~ x1 + I(x1^2) + x11, data=table.b3 ) plot( m1, which=1 ) # Part (d): xyplot( m0$residuals ~ x7 | x11, data=table.b3 )