# # 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 library(MASS) library(AER) data("USMacroG") MacroDiff = apply(USMacroG,2,diff) MacroDiff = data.frame(MacroDiff) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter12/rlab_pairs_plot.eps", onefile=FALSE, horizontal=FALSE) } with( MacroDiff, pairs(cbind(consumption,dpi,cpi,government,unemp)) ) if( save_plots ){ dev.off() } # Fit a linear model: fitLm1 = lm( consumption ~ dpi + cpi + government + unemp, data=MacroDiff ) summary(fitLm1) confint(fitLm1) anova(fitLm1) fitLm2 = stepAIC(fitLm1) summary(fitLm2) AIC(fitLm1) AIC(fitLm2) AIC(fitLm1) - AIC(fitLm2) library(car) vif(fitLm1) vif(fitLm2) # Plot partial residual plots: attach(MacroDiff) par(mfrow=c(2,2)) sp = 0.8 crPlot(fitLm1,dpi,span=cp,col="black") crPlot(fitLm1,cpi,span=sp,col="black") crPlot(fitLm1,government,span=sp,col="black") crPlot(fitLm1,unemp,span=sp,col="black")