# # Epage # # 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. # #----- if(is.null(version$language) == FALSE) require(alr3) else library(alr3) data(mantel) # start with backwards ellimination: # mNone <- lm( Y ~ 1, data=mantel ) # <- our most basic model mAll <- lm( Y ~ X1 + X2 + X3, data=mantel ) # <- the full model # us the R function "step" to do backwards ellimination: # # using the AIC: # step( mAll, scope=list(lower=~1,upper=~1+X1+X2+X3),direction="backward",data=mantel, k=2 ) # using the BIC: # step( mAll, scope=list(lower=~1,upper=~1+X1+X2+X3),direction="backward",data=mantel, k=log(length(mAll$residuals)) ) # using the C_p criterion: # step( mAll, scope=list(lower=~1,upper=~1+X1+X2+X3),direction="backward",data=mantel, scale=sigma.hat(mAll)^2 ) # us the R function "step" to do forward ellimination: # # using the AIC: # step( mNone, scope=list(lower=~1,upper=~1+X1+X2+X3),direction="forward",data=mantel, k=2 ) # using the BIC: # step( mNone, scope=list(lower=~1,upper=~1+X1+X2+X3),direction="forward",data=mantel, k=log(length(mNone$residuals)) ) # using the C_p criterion: # step( mNone, scope=list(lower=~1,upper=~1+X1+X2+X3),direction="forward",data=mantel, scale=sigma.hat(mNone)^2 ) # lets compute the correlation of these variables: # cor(as.matrix(mantel)[,c(2,3,4)])