Shaw and Shackleton (2010) studied the effects of four factors (insect supplementation, water treatment, site and rosette size) on growth and seed set of a biennial herb, the teasel (Dipacus fullonum) near London. The design was fully balanced with three plants per factor combination. Preliminary analyses of both response variables (using residual plots) suggested a need transformation. In both cases, small predicted values were associated with small spreads of residuals. For seed set, variance of the residuals increased steadily with predicted values (Figure 7.8), whereas residuals for biomass showed a pattern of strongly increasing, then decreasing spread of the residuals. In both cases, log-transformation of the response variable removed the issues with the distribution of residuals.
Blokenearexeter, CC0, via Wikimedia Commons
Shaw, P. J. A. & Shackleton, K. (2010). Carnivory in the teasel Dipsacus fullonum—the effect of experimental feeding on growth and seed set. PLoS One, 6, e17935.
The paper is here.
First, load the required packages (car, sjstats) + ggplot2, patchwork, emmeans
Import shawshack data file (shawshack.csv)
shawshack <- read.csv("../data/shawshack.csv")
head(shawshack,10)
Convert predictors to factors
shawshack$site <- factor(shawshack$site)
shawshack$sizeclass <- factor(shawshack$sizeclass)
shawshack$maggot <- factor(shawshack$maggot)
shawshack$water <- factor(shawshack$water)
shawshack1.aov <- aov(seedmass~site*sizeclass*maggot*water, data=shawshack)
plot(shawshack1.aov)
shawshack2.aov <- aov(biomass~site*sizeclass*maggot*water, data=shawshack)
plot(shawshack2.aov)
Residuals show patterns
shawshack3.aov <- aov(log10(seedmass)~site*sizeclass*maggot*water, data=shawshack)
plot(shawshack3.aov)
shawshack4.aov <- aov(log10(biomass)~site*sizeclass*maggot*water, data=shawshack)
plot(shawshack4.aov)
Tests, then effect sizes
Seed mass
summary(shawshack3.aov)
Df Sum Sq Mean Sq F value Pr(>F)
site 1 8.60 8.60 56.64 1.2e-09 ***
sizeclass 1 2.56 2.56 16.89 0.00015 ***
maggot 2 1.00 0.50 3.31 0.04512 *
water 1 0.00 0.00 0.02 0.90011
site:sizeclass 1 0.01 0.01 0.08 0.77359
site:maggot 2 0.76 0.38 2.49 0.09372 .
sizeclass:maggot 2 0.25 0.13 0.84 0.44004
site:water 1 0.00 0.00 0.02 0.89538
sizeclass:water 1 0.67 0.67 4.39 0.04134 *
maggot:water 2 0.05 0.03 0.18 0.83571
site:sizeclass:maggot 2 0.20 0.10 0.66 0.51926
site:sizeclass:water 1 0.15 0.15 1.00 0.32226
site:maggot:water 2 0.15 0.07 0.49 0.61625
sizeclass:maggot:water 2 1.02 0.51 3.35 0.04361 *
site:sizeclass:maggot:water 2 0.08 0.04 0.26 0.77302
Residuals 48 7.29 0.15
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
anova_stats(shawshack3.aov)
term | df | sumsq | meansq | statistic | p.value | etasq | partial.etasq | omegasq | partial.omegasq | epsilonsq | cohens.f | power
----------------------------------------------------------------------------------------------------------------------------------------------------------
site | 1 | 8.597 | 8.597 | 56.640 | < .001 | 0.377 | 0.541 | 0.368 | 0.436 | 0.371 | 1.086 | 1.000
sizeclass | 1 | 2.563 | 2.563 | 16.885 | < .001 | 0.112 | 0.260 | 0.105 | 0.181 | 0.106 | 0.593 | 0.984
maggot | 2 | 1.004 | 0.502 | 3.307 | 0.045 | 0.044 | 0.121 | 0.031 | 0.060 | 0.031 | 0.371 | 0.628
water | 1 | 0.002 | 0.002 | 0.016 | 0.900 | 0.000 | 0.000 | -0.007 | -0.014 | -0.007 | 0.018 | 0.052
site:sizeclass | 1 | 0.013 | 0.013 | 0.084 | 0.774 | 0.001 | 0.002 | -0.006 | -0.013 | -0.006 | 0.042 | 0.060
site:maggot | 2 | 0.755 | 0.378 | 2.488 | 0.094 | 0.033 | 0.094 | 0.020 | 0.040 | 0.020 | 0.322 | 0.501
sizeclass:maggot | 2 | 0.254 | 0.127 | 0.835 | 0.440 | 0.011 | 0.034 | -0.002 | -0.005 | -0.002 | 0.187 | 0.194
site:water | 1 | 0.003 | 0.003 | 0.017 | 0.895 | 0.000 | 0.000 | -0.006 | -0.014 | -0.007 | 0.019 | 0.052
sizeclass:water | 1 | 0.667 | 0.667 | 4.395 | 0.041 | 0.029 | 0.084 | 0.022 | 0.045 | 0.023 | 0.303 | 0.554
maggot:water | 2 | 0.055 | 0.027 | 0.180 | 0.836 | 0.002 | 0.007 | -0.011 | -0.023 | -0.011 | 0.087 | 0.078
site:sizeclass:maggot | 2 | 0.202 | 0.101 | 0.664 | 0.519 | 0.009 | 0.027 | -0.004 | -0.009 | -0.004 | 0.166 | 0.162
site:sizeclass:water | 1 | 0.152 | 0.152 | 1.000 | 0.322 | 0.007 | 0.020 | 0.000 | 0.000 | 0.000 | 0.144 | 0.170
site:maggot:water | 2 | 0.148 | 0.074 | 0.489 | 0.616 | 0.007 | 0.020 | -0.007 | -0.014 | -0.007 | 0.143 | 0.131
sizeclass:maggot:water | 2 | 1.016 | 0.508 | 3.346 | 0.044 | 0.045 | 0.122 | 0.031 | 0.061 | 0.031 | 0.373 | 0.633
site:sizeclass:maggot:water | 2 | 0.079 | 0.039 | 0.259 | 0.773 | 0.003 | 0.011 | -0.010 | -0.021 | -0.010 | 0.104 | 0.091
Residuals | 48 | 7.286 | 0.152 | | | | | | | | |
Now biomass
summary(shawshack4.aov)
Df Sum Sq Mean Sq F value Pr(>F)
site 1 10.30 10.30 278.75 < 2e-16 ***
sizeclass 1 2.82 2.82 76.30 1.7e-11 ***
maggot 2 0.09 0.05 1.28 0.287
water 1 0.03 0.03 0.77 0.385
site:sizeclass 1 0.02 0.02 0.59 0.445
site:maggot 2 0.15 0.07 1.96 0.151
sizeclass:maggot 2 0.08 0.04 1.11 0.338
site:water 1 0.01 0.01 0.24 0.629
sizeclass:water 1 0.25 0.25 6.81 0.012 *
maggot:water 2 0.07 0.03 0.94 0.399
site:sizeclass:maggot 2 0.14 0.07 1.96 0.152
site:sizeclass:water 1 0.00 0.00 0.02 0.903
site:maggot:water 2 0.05 0.02 0.61 0.547
sizeclass:maggot:water 2 0.07 0.04 0.98 0.382
site:sizeclass:maggot:water 2 0.02 0.01 0.26 0.775
Residuals 48 1.77 0.04
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
anova_stats(shawshack4.aov)
term | df | sumsq | meansq | statistic | p.value | etasq | partial.etasq | omegasq | partial.omegasq | epsilonsq | cohens.f | power
-----------------------------------------------------------------------------------------------------------------------------------------------------------
site | 1 | 10.300 | 10.300 | 278.747 | < .001 | 0.649 | 0.853 | 0.645 | 0.794 | 0.646 | 2.410 | 1.000
sizeclass | 1 | 2.819 | 2.819 | 76.299 | < .001 | 0.178 | 0.614 | 0.175 | 0.511 | 0.175 | 1.261 | 1.000
maggot | 2 | 0.095 | 0.047 | 1.283 | 0.287 | 0.006 | 0.051 | 0.001 | 0.008 | 0.001 | 0.231 | 0.279
water | 1 | 0.028 | 0.028 | 0.769 | 0.385 | 0.002 | 0.016 | -0.001 | -0.003 | -0.001 | 0.127 | 0.142
site:sizeclass | 1 | 0.022 | 0.022 | 0.594 | 0.445 | 0.001 | 0.012 | -0.001 | -0.006 | -0.001 | 0.111 | 0.120
site:maggot | 2 | 0.145 | 0.073 | 1.964 | 0.151 | 0.009 | 0.076 | 0.004 | 0.026 | 0.004 | 0.286 | 0.408
sizeclass:maggot | 2 | 0.082 | 0.041 | 1.109 | 0.338 | 0.005 | 0.044 | 0.001 | 0.003 | 0.001 | 0.215 | 0.246
site:water | 1 | 0.009 | 0.009 | 0.236 | 0.629 | 0.001 | 0.005 | -0.002 | -0.011 | -0.002 | 0.070 | 0.077
sizeclass:water | 1 | 0.252 | 0.252 | 6.813 | 0.012 | 0.016 | 0.124 | 0.013 | 0.075 | 0.014 | 0.377 | 0.742
maggot:water | 2 | 0.069 | 0.035 | 0.936 | 0.399 | 0.004 | 0.038 | 0.000 | -0.002 | 0.000 | 0.197 | 0.213
site:sizeclass:maggot | 2 | 0.145 | 0.072 | 1.959 | 0.152 | 0.009 | 0.075 | 0.004 | 0.026 | 0.004 | 0.286 | 0.407
site:sizeclass:water | 1 | 0.001 | 0.001 | 0.015 | 0.903 | 0.000 | 0.000 | -0.002 | -0.014 | -0.002 | 0.018 | 0.052
site:maggot:water | 2 | 0.045 | 0.023 | 0.610 | 0.547 | 0.003 | 0.025 | -0.002 | -0.011 | -0.002 | 0.159 | 0.152
sizeclass:maggot:water | 2 | 0.073 | 0.036 | 0.983 | 0.382 | 0.005 | 0.039 | 0.000 | 0.000 | 0.000 | 0.202 | 0.222
site:sizeclass:maggot:water | 2 | 0.019 | 0.009 | 0.256 | 0.775 | 0.001 | 0.011 | -0.003 | -0.021 | -0.003 | 0.103 | 0.090
Residuals | 48 | 1.774 | 0.037 | | | | | | | | |
The first figure, 7.7 in the book, is a panel of 4 residual plots, 2 dependent variables, raw and transformed
p1<-ggplot(shawshack1.aov, aes(x = shawshack1.aov$fitted.values, y = shawshack1.aov$residuals)) +
geom_point(color=sc, alpha=0.5) +
theme_classic(base_size = 10)+
theme(
axis.text = element_blank(),
axis.line = element_line(color = ac),
axis.ticks = element_blank(),
plot.title = element_text(hjust=0.5, size=8)
)+labs(x = NULL, y = NULL, title="Seeds, Raw"
)
p2<-ggplot(shawshack2.aov, aes(x = shawshack2.aov$fitted.values, y = shawshack2.aov$residuals)) +
geom_point(color=sc, alpha=0.5) +
theme_classic(base_size = 10)+
theme(
axis.text = element_blank(),
axis.line = element_line(color = ac),
axis.ticks = element_blank(),
plot.title = element_text(hjust=0.5, size=8)
)+labs(x = NULL, y = NULL, title="Growth, Raw"
)
p3<-ggplot(shawshack1.aov, aes(x = shawshack3.aov$fitted.values, y = shawshack3.aov$residuals)) +
geom_point(color=sc, alpha=0.5) +
theme_classic(base_size = 10)+
theme(
axis.text = element_blank(),
axis.line = element_line(color = ac),
axis.ticks = element_blank(),
plot.title = element_text(hjust=0.5, size=8)
)+labs(x = NULL, y = NULL, title="Seeds, Log-transformed"
)
p4<-ggplot(shawshack1.aov, aes(x = shawshack4.aov$fitted.values, y = shawshack4.aov$residuals)) +
geom_point(color=sc, alpha=.5) +
theme_classic(base_size = 10)+
theme(
axis.text = element_blank(),
axis.line = element_line(color = ac),
axis.ticks = element_blank(),
plot.title = element_text(hjust=0.5, size=8)
)+labs(x = NULL, y = NULL, title="Growth, Log-transformed"
)
p1+p2+p3+p4
The second figure, 7.8 in the book, shows the effects that were detected. For seed number, there was a three-way interaction between plant size, insects, and water. We’ll show that as two panels, each showing the relationship between water and insects, with one for large and one for small plants. There was a separate effect of site, which we show as a simple bar graph. For growth, we detected an interaction between size and water, plus an independent main effect of site. We’ll show the size x water interaction, pooling across the other factors.