# # Epage 231 # # 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. # #----- # version$language == "R" for R version$language == NULL for SPlus if(is.null(version$language) == FALSE){ require(alr3) }else{ library(alr3) } data(galapagos) # lets replace the small elevation islands with 200m: # inds <- galapagos$EM==0 galapagos$Elevation[inds] <- 200.0 attach(galapagos) # do some data analysis on the scatter plots of this data: # postscript("../../WriteUp/Graphics/Chapter10/prob_7_pairs.eps", onefile=FALSE, horizontal=FALSE) pairs(ES/NS~Area+Anear+Dist+DistSC+Elevation) dev.off() # transform some of the variables: Area and Anear postscript("../../WriteUp/Graphics/Chapter10/prob_7_pairs_transformed.eps", onefile=FALSE, horizontal=FALSE) pairs(log(ES/NS)~log(Area)+log(Anear)+Dist+DistSC+log(Elevation)) dev.off() a <- galapagos a$logESONS <- log(a$ES/a$NS) a$logArea <- log(Area) a$logAnear <- log(Anear) a$logElevation <- log(Elevation) # the simplest and most complicated model: # m0 <- lm( logESONS ~ +1, data=a ) m1 <- lm( logESONS ~ +1+logArea+logAnear+Dist+DistSC+logElevation, data=a ) if(is.null(version$language) == FALSE) {require (xtable); xtable(m1)} else m1 # Lets start with forward selection for this problem: # ansf1 <- step(m0,scope=list(lower=~+1, upper=~+1+logArea+logAnear+Dist+DistSC+logElevation), direction="forward", data=a) ansf2 <- step(m1,scope=list(lower=~+1, upper=~+1+logArea+logAnear+Dist+DistSC+logElevation), direction="backward", data=a)