source('../../Data/data_loaders.R') DF = load_appendix_gas_mileage_data() # Part (a): # m = lm( MPG ~ DISP + HP + WT, data=DF ) print( summary(m) ) # Part (b): # print( cor( DF ) ) # Part (c): # #postscript("../../WriteUp/Graphics/Chapter4/ex_4_5_pairs_plot.eps", onefile=FALSE, horizontal=FALSE) pairs( DF ) #dev.off() #postscript("../../WriteUp/Graphics/Chapter4/ex_4_5_boxplot.eps", onefile=FALSE, horizontal=FALSE) boxplot( DF ) #dev.off() # Part (d): # #postscript("../../WriteUp/Graphics/Chapter4/ex_4_5_residuals_vs_fitted.eps", onefile=FALSE, horizontal=FALSE) plot( m, which=1 ) #dev.off() r = m$residuals #postscript("../../WriteUp/Graphics/Chapter4/ex_4_5_residuals_vs_features.eps", onefile=FALSE, horizontal=FALSE) par(mfrow=c(1, 3)) plot( DF$DISP, r, type='p', pch=19, xlab='DISP', ylab='residuals' ) grid() plot( DF$HP, r, type='p', pch=19, xlab='HP', ylab='residuals' ) grid() plot( DF$WT, r, type='p', pch=19, xlab='WT', ylab='residuals' ) grid() par(mfrow=c(1, 1)) #dev.off() # Part (e): # plot( m, which=2 )