# # 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. # #----- # version$language == "R" for R version$language == NULL for SPlus if(is.null(version$language) == FALSE){ require(alr3) }else{ library(alr3) } data(UN3) #attach(UN3) bcTransX <- bctrans(ModernC~Change+PPgdp+Frate+Pop+Fertility+Purban, family="yeo.johnson", data=UN3 ) summary(bcTransX) # based on this result lets take some set of transformations: # unTrans <- cbind( UN3$ModernC, powtran(bcTransX,lambda=c(1,0,1,0,0,1),family="yeo.johnson") ) # lets now look for a transformation of the response ModernC (mX means we have transformed the x (independent variables)): # mX <- lm( ModernC ~ Change+logPPgdp+Frate+logPop+logFertility+Purban, data=unTrans ) sX <- summary(mX) ans <- inv.tran.plot( UN3$ModernC, predict(mX) ) unlist( inv.tran.estimate(UN3$ModernC,predict(mX)) ) # lets fit the model suggested (including the optimal value of lambda): # modernCT <- powtran( UN3$ModernC, ans$lambda[1] ) unTrans2 <- cbind( modernCT, powtran(bcTransX,lambda=c(1,0,1,0,0,1),family="yeo.johnson") ) # get all the data into one frame (all variables transformed) mXY <- lm( modernCT ~ Change+logPPgdp+Frate+logPop+logFertility+Purban, data=unTrans2 ) sXY <- summary(mXY) # how well does this model compare with a naive no transformation model? # m0 <- lm( ModernC ~ Change+PPgdp+Frate+Pop+Fertility+Purban, data=UN3 ) s0 <- summary(m0) # how can all of these transformations NOT result in better fits? # print( c(s0$r.squared, sX$r.squared, sXY$r.squared) )