Skip to main content

5.7) Useful Functions For Model Objects (cont'd)


anova() produces an ANOVA table to summarize one or more models. If you give it one model, it shows the variance explained by each term in the model. If you give it more than one model (all with the same response variable), it compares them using using analysis of variance or deviance, to see whether each is a significant improvement on the previous one. In either case, you can get a significance test with the output; try test="F" or test="Chisq". N.B. anova() does not perform an ANOVA analysis!. Use lm() for all kinds of linear models.

Fit a model to see whether the dry mass of grass plants varies among those with different numbers of tillers (make sure GRASS$Tlrs is treated as a factor, not a number). Then make a boxplot of GRASS$Dms for each level of GRASS$Tlrs and, beside it, make a barplot of the same data using the means for each level of GRASS$Tlrs. Use arrows() to add error bars showing the residual standard deviation (see arrows() in Section 3.6 for some advice). Unfortunately, you have to find the right x-coordinates for the error bars by trial and error – or by delving deep into the barplot help file. Hint: the default spacing between bars is 0.2 units.