The anova() function will compute an analysis of variance (ANOVA) for a model, and present the statistics in an ANOVA table, that includes:
- sums of squares (Sum Sq)
- degrees of freedom (Df)
- mean squares (Mean Sq)
- F values
- p-values (Pr(>F))
Example 1:
Use the anova() function to get the ANOVA table for an empty model. You can save the model into an object first and use its name as the argument (Example 2 and Example 3), or you can use the lm() function directly in the anova() function (Example 1).
# Generate the ANOVA table for the empty model of Thumb
# using the lm() function within the anova() function
anova(lm(Thumb ~ NULL, data = Fingers))
Example output:
Example 2:
Use the anova() function to get the ANOVA table for a model with a single predictor.
# Generate the ANOVA table for the Sex model of Thumb
# Save the model into an object first
sex_model <- lm(Thumb ~ Sex, data = Fingers)
anova(sex_model)
Example output:
Example 3:
Use the anova() function to get the ANOVA table for a multivariate model.
# Generate the ANOVA table for the Sex + Height model of Thumb
sex_height_model <- lm(Thumb ~ Sex + Height, data = Fingers)
anova(sex_height_model)
Example output: