Introduction
One of the advantages of the R statistical language is that you can save not only variables but also complete model results. There are several reasons you can choose to do so, conducting new statistical procedures on saved models. In this blog post, we’ll show you how and why to save and name models in R so that they can be used as arguments by other functions.
Load Dataset
Let’s load R’s built-in plant growth dataset:
data <- PlantGrowth
print(data)
These data measure plant growth as a function of three independent conditions or groups: (a) A control group, (b) treatment 1, and (c) treatment 2. The independent variable is group, the dependent variable is weight, and data is the name given to the data frame that holds these two variables.
Save Model Results as an Argument for Another Procedure
Let’s run an ANOVA in R on the selected data:
mod.aov <- aov(weight~group, data=data)
summary(mod.aov)
Here are the results:
The ANOVA model is significant, F(2, 27) = 4.85, p = .0159. However, on its own, this result only tells us that there is some effect of group on weight. We need the Tukey pairwise comparison in order to identify the magnitude and statistical significance of weight differences between the groups.
Note that we had to name and save the ANOVA model so that we could use it as an argument for Tukey’s pairwise comparison:
TukeyHSD(mod.aov)
By the way, here’s what you get from that command:
Here we see that the only significant difference is between treatment 2 and treatment 1, p = .012. The mean weight associated with treatment 2 is 0.865 higher than the mean weight associated with treatment 1. Naming and saving the ANOVA results (mod.aov) lets us get Tukey results very easily.
BridgeText can help you with all of your statistical analysis needs.