# # Epage 65 # # 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. # #----- library(alr3) data(BGSgirls) attach(BGSgirls) # 3.1.1: # postscript("../../WriteUp/Graphics/Chapter3/prob_1.eps", onefile=FALSE, horizontal=FALSE) pairs(Soma~WT2+HT2+WT9+HT9+LG9+ST9) dev.off() # 3.1.2: # # the plots needed to duplicate Fig. 3.1: postscript("../../WriteUp/Graphics/Chapter3/prob_1_soma_on_wt9.eps", onefile=FALSE, horizontal=FALSE) plot( WT9, Soma, xlab="WT9", ylab="Soma" ) dev.off() postscript("../../WriteUp/Graphics/Chapter3/prob_1_soma_on_lg9.eps", onefile=FALSE, horizontal=FALSE) plot( LG9, Soma, xlab="LG9", ylab="Soma" ) dev.off() postscript("../../WriteUp/Graphics/Chapter3/prob_1_lg9_on_wt9.eps", onefile=FALSE, horizontal=FALSE) plot( WT9, LG9, xlab="WT9", ylab="LG9" ) dev.off() # the added variable plot: # m0 = lm(Soma ~ WT9) ma = lm(LG9 ~ WT9) postscript("../../WriteUp/Graphics/Chapter3/prob_1_res_ma_on_res_m0.eps", onefile=FALSE, horizontal=FALSE) plot( ma$residuals, m0$residuals, xlab="e_hat LG9 on WT9", ylab="e_hat Soma on WT9" ) dev.off() # 3.1.3: # m = lm( Soma ~ HT2 + WT2 + HT9 + WT9 + ST9 ) m0 = update( m, ~. - HT2 - WT2 - HT9 - WT9 - ST9 ) # get a regression model on just a constant ... # compare the regression model with all terms "m" with that containing no terms "m0" (only a constant) anova(m0,m) summary(m) # 3.1.4/5: # mLR = m mRL = lm( Soma ~ ST9 + WT9 + HT9 + WT2 + HT2 ) anova(mLR) anova(mRL)