# # 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. # #----- # # EPage 139 # save_plots = F DF = read.csv( "../../Data/gasoline.csv", header=TRUE ) rownames(DF) = DF$country DF$country = NULL DF$sqrtCons = sqrt(DF$consumption) m_direct = lm( price ~ consumption, data=DF ) s_direct = summary(m_direct) influe_direct = influence(m_direct) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter6/ex_4_direct.eps", onefile=FALSE, horizontal=FALSE) } plot( DF$consumption, DF$price ) abline(m_direct) grid() if( save_plots ){ dev.off() } m_sqrt = lm( price ~ sqrtCons, data=DF ) s_sqrt = summary(m_sqrt) influe_sqrt = influence(m_sqrt) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter6/ex_4_sqrt.eps", onefile=FALSE, horizontal=FALSE) } plot( sqrt(DF$consumption), DF$price ) abline(m_sqrt) grid() if( save_plots ){ dev.off() } m_log = lm( price ~ I(log(consumption)), data=DF ) s_log = summary(m_log) influe_log = influence(m_log) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter6/ex_4_log.eps", onefile=FALSE, horizontal=FALSE) } plot( log(DF$consumption), DF$price ) abline(m_log) grid() if( save_plots ){ dev.off() } # What city has the most influence: all_influence = rbind( influe_direct$hat, influe_sqrt$hat, influe_log$hat ) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter6/ex_4_boxplot.eps", onefile=FALSE, horizontal=FALSE) } boxplot( all_influence ) if( save_plots ){ dev.off() } all_influence['Singapore']