The built-in R dataset PlantGrowth records the weight of plants in three groups: a control group (ctrl) and two treatment groups (trt1 and trt2). Investigate whether mean plant weight differs among the groups.
##Starter R Code
data("PlantGrowth")
# Explore the data
str(PlantGrowth)
## 'data.frame': 30 obs. of 2 variables:
## $ weight: num 4.17 5.58 5.18 6.11 4.5 4.61 5.17 4.53 5.33 5.14 ...
## $ group : Factor w/ 3 levels "ctrl","trt1",..: 1 1 1 1 1 1 1 1 1 1 ...
head(PlantGrowth)
## weight group
## 1 4.17 ctrl
## 2 5.58 ctrl
## 3 5.18 ctrl
## 4 6.11 ctrl
## 5 4.50 ctrl
## 6 4.61 ctrl
table(PlantGrowth$group)
##
## ctrl trt1 trt2
## 10 10 10
# Summarize plant weight by group
aggregate(weight ~ group, data = PlantGrowth,
FUN = mean)
## group weight
## 1 ctrl 5.032
## 2 trt1 4.661
## 3 trt2 5.526
# Create a boxplot
boxplot(weight ~ group, data = PlantGrowth,
xlab = "Group",
ylab = "Plant weight",
main = "Plant Weight by Treatment")
# Fit a one-way ANOVA
fit <- aov(weight ~ group, data = PlantGrowth)
summary(fit)
## Df Sum Sq Mean Sq F value Pr(>F)
## group 2 3.766 1.8832 4.846 0.0159 *
## Residuals 27 10.492 0.3886
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Check model diagnostics
par(mfrow = c(2, 2))
plot(fit)
The diagnostic plots suggest that the assumptions for the one-way ANOVA are reasonably plausible.
Equal variances. The Residuals vs Fitted and
Scale–Location plots show fairly similar residual spread across the
three groups. The slight downward trend in the Scale–Location plot
suggests that variability may be somewhat smaller for trt2,
but there is no strong evidence of unequal variances.
Normality. Most points in the Q–Q plot lie near the reference line. A few points in the upper tail depart from the line, indicating a mild departure from normality.
Unusual observations. Observations 15 and 17 have relatively large positive residuals and should be checked for possible data entry errors or unusual circumstances.
Independence. Independence cannot be assessed from these plots. It must be justified by the study design, such as independent plants and appropriate treatment assignment.
Overall, the plots show no major violation that would clearly prevent the use of ANOVA, although the mild upper-tail departure and labeled observations should be noted when reporting the results.
par(mfrow = c(1, 1))
# Check equal variances; install car first if necessary
# install.packages("car")
car::leveneTest(weight ~ group, data = PlantGrowth)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 2 1.1192 0.3412
## 27
# Compare pairs of groups, if appropriate
TukeyHSD(fit)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = weight ~ group, data = PlantGrowth)
##
## $group
## diff lwr upr p adj
## trt1-ctrl -0.371 -1.0622161 0.3202161 0.3908711
## trt2-ctrl 0.494 -0.1972161 1.1852161 0.1979960
## trt2-trt1 0.865 0.1737839 1.5562161 0.0120064
Levene’s test assesses whether the population variances are equal across the three groups. The result is not statistically significant, \(F(2,27)=1.1192\), \(p=0.3412\). Thus, we do not have evidence that the group variances differ. This supports using the equal variance ANOVA model, though the test does not prove the variances are identical.
Tukey’s procedure adjusts for making all three pairwise comparisons.
At the 5% significance level, only trt2 and
trt1 differ significantly: the mean weight for
trt2 is 0.865 higher than for
trt1 (95% family-wise confidence interval: 0.174 to 1.556;
adjusted \(p=0.0120\)).
Neither treatment differs significantly from the control:
trt1 versus ctrl has adjusted \(p=0.3909\), and trt2 versus
ctrl has adjusted \(p=0.1980\). These nonsignificant results do
not establish that either treatment has the same mean as the
control.