# # # 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. # #----- # fix the random.seed, so I'll always get the same answer: set.seed(10131985) data(Orange) attach(Orange) # Lets display the data and the linear model: # postscript("../../WriteUp/Graphics/Chapter1/ex_1_21_plot.eps", onefile=FALSE, horizontal=FALSE) plot( age, circumference ) m1 = lm( circumference ~ age ) # the model with only one predictor: age abline(m1) dev.off() summary(m1) # create a factor based on the specific tree: # TF = as.factor( Tree ) m2 = lm( circumference ~ age + TF ) # the model with two predictors: age and the specific tree factor summary(m2) # We can use the anova method to compare whether this second model (m2) is an improvement over the first model (m1): # m1 < m2, since m2 has the additional factor term # anova(m1,m2)