# Orange2 Example # Formulate and test 2-way ANOVA models # Set colClasses argument in read.table to read # variety and pesticide as factors. orange <- read.table("c:/datasets/orange.txt", header=TRUE, colClasses=c("factor", "factor", "numeric")) print(orange) # Create and display additive and saturated ANOVA models. additive <- lm(yield ~ variety + pesticide, data=orange) summary(additive) anova(additive) saturated <- lm(yield ~ variety + pesticide + variety*pesticide, data=orange) summary(saturated) anova(saturated) # Create and display null hypothesis models variety_only <- lm(yield ~ variety, data=orange) summary(variety_only) anova(variety_only) pesticide_only <- lm(yield ~ pesticide, data=orange) summary(pesticide_only) anova(pesticide_only) no_factors <- lm(yield ~ 1, data=orange) summary(no_factors) anova(no_factors) library(car) # Perform tests of hypothesis by supplying # two models to anova function: the full model # and the null hypothesis model # 1. Test whether interaction is significant. anova(saturated, additive) # Conclusion, interaction effect is not significant, # use additive model. # 2. Test whether variety is significant anova(additive, pesticide_only) # Conclusion, pesticide effect is *** significant. # 3. Test whether pesticide is significant anova(additive, variety_only) # Conclusion, variety effect is *** significant