# # Epage 142 # # 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) } if(is.null(version$language) == FALSE) data(salary) attach(salary) # a scatterplot matrix # postscript("../../WriteUp/Graphics/Chapter6/prob_13.eps", onefile=FALSE, horizontal=FALSE) pairs(Salary~YSdeg+Year) dev.off() SF <- factor( salary$Sex, ordered=FALSE ) m0 <- lm( Salary ~ +1 ) # the common intercept model (same mean for each sex) m1 <- lm( Salary ~ -1 + SF ) # the different intercept model (different means for each sex) # compare the two models: anova(m0,m1) # form the largest of the set of models: HDF <- factor( salary$Degree, ordered=FALSE ) RF <- factor( salary$Rank, ordered=FALSE ) m0 <- lm( Salary ~ Year + HDF + YSdeg ) # the less general model m1 <- lm( Salary ~ Year + HDF + YSdeg + RF ) # the more general model # compare the two models anova(m0,m1) # compare an ever more general model that uses Sex as a factor: m2 <- lm( Salary ~ Year + HDF + YSdeg + RF + SF ) # the most general model # compare these two models: anova(m1,m2)