Garcia et al. (2015) studied the effect of the appetite-regulating hormone leptin on appetite and mating preferences in the spadefoot toad Spea bombifrons. Eighteen female toads collected from the wild were allocated to a treatment group (n = 9) which received a subcutaneous injection of leptin once per day for six days, and a control group (n = 9), which received saline injections with the same frequency. One hour after the day 6 injections, each toad was presented with approximately 50 crickets. The response variable was the cumulative number of attacks by each toad over three-minute intervals for 15 minutes. Treatment (leptin versus control was the fixed between-subject factor and toads were the subjects. The within-subjects fixed factor was time with five groups representing 3, 6, 9, 12 and 15 minutes after the introduction of crickets.
Plains spadefoot toad. USFWS Mountain-Prairie, Public domain, via Wikimedia Commons
Garcia, N. W., Pfennig, K. S. & Burmeister, S. S. (2015). Leptin manipulation reduces appetite and causes a switch in mating preference in the Plains Spadefoot Toad (Spea bombifrons). PLoS One, 10, e0125981.
Link to the paper
First, load the required packages (afex, car, lattice, lme4, lmerTest, nlme, VCA, ez, emmeans, Rmisc, MuMIn)
Import garcia data file
garcia <- read.csv("../data/garcia.csv")
garcia
set contrasts using afex
set_sum_contrasts()
setting contr.sum globally: options(contrasts=c('contr.sum', 'contr.poly'))
set toad as factor and create timefac as categorical version of time
garcia$toad <- factor(garcia$toad)
garcia$timefac <- factor(garcia$time, ordered=TRUE)
Check residuals - uneven spread related to mean
garcia1.aov <- aov(cumattack~treatment*time, garcia)
plot(garcia1.aov)
Check boxplots - unequal spread related to mean
boxplot(cumattack~treatment*time,data=garcia)
Check homogeneity of within-group variances - very different variances
garcia_stats <- summarySE(data=garcia,measurevar="cumattack", groupvars=c("treatment","time"))
garcia_stats
fully balanced so all SS are OK
garcia2.aov <- aov(cumattack~treatment*timefac+Error(toad), garcia)
summary(garcia2.aov)
Error: toad
Df Sum Sq Mean Sq F value Pr(>F)
treatment 1 1647 1646.9 8.593 0.00978 **
Residuals 16 3066 191.7
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
timefac 4 3525 881.2 91.81 < 2e-16 ***
treatment:timefac 4 579 144.7 15.08 9.82e-09 ***
Residuals 64 614 9.6
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
summary(garcia2.aov, split=list(timefac=list(linear=1, quadratic=2, cubic=3)))
Error: toad
Df Sum Sq Mean Sq F value Pr(>F)
treatment 1 1647 1646.9 8.593 0.00978 **
Residuals 16 3066 191.7
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
timefac 4 3525 881 91.813 < 2e-16 ***
timefac: linear 1 3494 3494 364.023 < 2e-16 ***
timefac: quadratic 1 27 27 2.848 0.0963 .
timefac: cubic 1 2 2 0.255 0.6151
treatment:timefac 4 579 145 15.077 9.82e-09 ***
treatment:timefac: linear 1 572 572 59.647 9.92e-11 ***
treatment:timefac: quadratic 1 1 1 0.070 0.7924
treatment:timefac: cubic 1 4 4 0.422 0.5183
Residuals 64 614 10
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
emmeans(garcia2.aov, ~timefac|treatment)
treatment = Leptin:
timefac emmean SE df lower.CL upper.CL
3 6.89 2.26 22.8 2.21 11.6
6 10.78 2.26 22.8 6.10 15.5
9 13.67 2.26 22.8 8.99 18.3
12 15.89 2.26 22.8 11.21 20.6
15 17.44 2.26 22.8 12.77 22.1
treatment = Saline:
timefac emmean SE df lower.CL upper.CL
3 8.89 2.26 22.8 4.21 13.6
6 14.78 2.26 22.8 10.10 19.5
9 22.44 2.26 22.8 17.77 27.1
12 28.22 2.26 22.8 23.54 32.9
15 33.11 2.26 22.8 28.43 37.8
Warning: EMMs are biased unless design is perfectly balanced
Confidence level used: 0.95
ezgarcia1 <- ezANOVA(data=garcia, dv=cumattack, wid=toad, within=timefac, between=treatment, type=3, detailed=TRUE)
Warning: Converting "treatment" to factor for ANOVA.
print(ezgarcia1)
$ANOVA
Effect DFn DFd SSn SSd F p p<.05 ges
1 (Intercept) 1 16 26660.0111 3066.4444 139.105790 2.642036e-09 * 0.8786887
2 treatment 1 16 1646.9444 3066.4444 8.593376 9.780788e-03 * 0.3091338
3 timefac 4 64 3524.6000 614.2222 91.813025 8.657540e-26 * 0.4891700
4 treatment:timefac 4 64 578.7778 614.2222 15.076700 9.818711e-09 * 0.1358810
$`Mauchly's Test for Sphericity`
Effect W p p<.05
3 timefac 0.03247946 1.720133e-07 *
4 treatment:timefac 0.03247946 1.720133e-07 *
$`Sphericity Corrections`
Effect GGe p[GG] p[GG]<.05 HFe p[HF] p[HF]<.05
3 timefac 0.371348 6.293100e-11 * 0.4004872 1.275427e-11 *
4 treatment:timefac 0.371348 1.881095e-04 * 0.4004872 1.182037e-04 *
Use lme4 using time as factor - use anova and Anova to look at fixed effects (Type 3 is OK to decide whether to keep intyeraction)
garcia1.lmer <- lmer(cumattack~treatment*timefac+(1|toad), garcia)
summary(garcia1.lmer, ddf="Kenward-Roger")
Linear mixed model fit by REML. t-tests use Kenward-Roger's method ['lmerModLmerTest']
Formula: cumattack ~ treatment * timefac + (1 | toad)
Data: garcia
REML criterion at convergence: 488
Scaled residuals:
Min 1Q Median 3Q Max
-2.49115 -0.47848 0.02588 0.47055 2.87421
Random effects:
Groups Name Variance Std.Dev.
toad (Intercept) 36.411 6.034
Residual 9.597 3.098
Number of obs: 90, groups: toad, 18
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 17.2111 1.4593 16.0000 11.794 2.64e-09 ***
treatment1 -4.2778 1.4593 16.0000 -2.931 0.00978 **
timefac.L 13.9316 0.7302 64.0000 19.079 < 2e-16 ***
timefac.Q -1.2324 0.7302 64.0000 -1.688 0.09633 .
timefac.C -0.3689 0.7302 64.0000 -0.505 0.61512
timefac^4 0.2590 0.7302 64.0000 0.355 0.72401
treatment1:timefac.L -5.6394 0.7302 64.0000 -7.723 9.92e-11 ***
treatment1:timefac.Q -0.1930 0.7302 64.0000 -0.264 0.79236
treatment1:timefac.C 0.4743 0.7302 64.0000 0.650 0.51827
treatment1:timefac^4 -0.2988 0.7302 64.0000 -0.409 0.68375
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) trtmn1 tmfc.L tmfc.Q tmfc.C tmfc^4 tr1:.L tr1:.Q tr1:.C
treatment1 0.000
timefac.L 0.000 0.000
timefac.Q 0.000 0.000 0.000
timefac.C 0.000 0.000 0.000 0.000
timefac^4 0.000 0.000 0.000 0.000 0.000
trtmnt1:t.L 0.000 0.000 0.000 0.000 0.000 0.000
trtmnt1:t.Q 0.000 0.000 0.000 0.000 0.000 0.000 0.000
trtmnt1:t.C 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
trtmnt1:t^4 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
anova(garcia1.lmer, ddf="Kenward-Roger")
Type III Analysis of Variance Table with Kenward-Roger's method
Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
treatment 82.5 82.47 1 16 8.5934 0.009781 **
timefac 3524.6 881.15 4 64 91.8130 < 2.2e-16 ***
treatment:timefac 578.8 144.69 4 64 15.0767 9.819e-09 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Get var comps
garcia1.ci <- confint.merMod(garcia1.lmer)
Computing profile confidence intervals ...
garcia1.vc <- (garcia1.ci)^2
print(garcia1.vc)
2.5 % 97.5 %
.sig01 17.178221 69.20280818
.sigma 6.258163 12.05099182
(Intercept) 206.327227 402.32844979
treatment1 50.762687 2.04708022
timefac.L 157.856396 234.06210257
timefac.Q 6.759322 0.01825933
timefac.C 3.015192 0.99713403
timefac^4 1.228844 2.64538702
treatment1:timefac.L 49.096557 18.24910212
treatment1:timefac.Q 2.435224 1.37939474
treatment1:timefac.C 0.797729 3.39237469
treatment1:timefac^4 2.776574 1.14210094
garcia1a.lmer <- lmer(cumattack~treatment*timefac+(timefac|toad), garcia)
Error: number of observations (=90) <= number of random effects (=90) for term (timefac | toad); the random-effects parameters and the residual variance (or scale parameter) are probably unidentifiable
garcia1.lme <- lme(cumattack~treatment*timefac, random=~1|toad, method="REML",garcia)
summary(garcia1.lme)
Linear mixed-effects model fit by REML
Data: garcia
Random effects:
Formula: ~1 | toad
(Intercept) Residual
StdDev: 6.034162 3.097938
Fixed effects: cumattack ~ treatment * timefac
Correlation:
(Intr) trtmn1 tmfc.L tmfc.Q tmfc.C tmfc^4 tr1:.L tr1:.Q tr1:.C
treatment1 0
timefac.L 0 0
timefac.Q 0 0 0
timefac.C 0 0 0 0
timefac^4 0 0 0 0 0
treatment1:timefac.L 0 0 0 0 0 0
treatment1:timefac.Q 0 0 0 0 0 0 0
treatment1:timefac.C 0 0 0 0 0 0 0 0
treatment1:timefac^4 0 0 0 0 0 0 0 0 0
Standardized Within-Group Residuals:
Min Q1 Med Q3 Max
-2.49114675 -0.47847867 0.02588476 0.47055427 2.87421248
Number of Observations: 90
Number of Groups: 18
anova(garcia1.lme, type="marginal")
garcia2.lme <- lme(cumattack~treatment*timefac, random=~1|toad, method="ML",garcia)
garcia3.lme <- lme(cumattack~treatment*timefac, random=~1|toad, weights = varIdent(form= ~ 1 | treatment*timefac),method="ML",garcia)
anova(garcia2.lme, garcia3.lme)
AICc(garcia2.lme, garcia3.lme)
garcia4.lme <- lme(cumattack~treatment*timefac, random=~1|toad, weights = varIdent(form= ~ 1 | treatment*timefac),method="REML",garcia)
anova(garcia4.lme, type="marginal")
xyplot(cumattack~time|toad, groups=treatment, type=c("p","r"), auto.key=T, garcia)
Now examine individual slopes (and intercepts) - again, variation in slopes
list_garcia <- lmList(cumattack~time|toad, garcia)
summary(list_garcia)
Call:
Model: cumattack ~ time | toad
Data: garcia
Coefficients:
(Intercept)
Estimate Std. Error t value Pr(>|t|)
1 3.3 1.767138 1.86742599 6.727360e-02
2 -3.0 1.767138 -1.69765999 9.532860e-02
3 2.8 1.767138 1.58448266 1.189234e-01
4 9.9 1.767138 5.60227798 7.342449e-07
5 -2.5 1.767138 -1.41471666 1.628923e-01
6 9.1 1.767138 5.14956865 3.765460e-06
7 0.1 1.767138 0.05658867 9.550817e-01
8 6.7 1.767138 3.79144065 3.795788e-04
9 7.2 1.767138 4.07438399 1.522204e-04
10 1.7 1.767138 0.96200733 3.403341e-01
11 3.0 1.767138 1.69765999 9.532860e-02
12 2.3 1.767138 1.30153933 1.985994e-01
13 11.5 1.767138 6.50769665 2.590922e-08
14 5.1 1.767138 2.88602199 5.597604e-03
15 3.8 1.767138 2.15036933 3.602079e-02
16 7.9 1.767138 4.47050465 4.042883e-05
17 4.0 1.767138 2.26354666 2.764355e-02
18 -1.0 1.767138 -0.56588666 5.738150e-01
time
Estimate Std. Error t value Pr(>|t|)
1 1.2333333 0.1776041 6.944285 5.074414e-09
2 1.1333333 0.1776041 6.381235 4.149348e-08
3 3.0666667 0.1776041 17.266870 1.206819e-23
4 1.7666667 0.1776041 9.947219 8.244742e-14
5 2.3000000 0.1776041 12.950153 3.392342e-18
6 0.7666667 0.1776041 4.316718 6.804628e-05
7 2.0333333 0.1776041 11.448686 4.591067e-16
8 1.1666667 0.1776041 6.568918 2.062162e-08
9 0.6000000 0.1776041 3.378301 1.359576e-03
10 0.3666667 0.1776041 2.064517 4.378554e-02
11 2.0666667 0.1776041 11.636369 2.446958e-16
12 3.3000000 0.1776041 18.580654 4.030655e-25
13 0.9666667 0.1776041 5.442818 1.310882e-06
14 0.4333333 0.1776041 2.439884 1.800572e-02
15 0.8666667 0.1776041 4.879768 9.796650e-06
16 1.7000000 0.1776041 9.571852 3.144289e-13
17 1.2000000 0.1776041 6.756601 1.023403e-08
18 1.4666667 0.1776041 8.258068 3.789301e-11
Residual standard error: 1.6849 on 54 degrees of freedom
First ML model with random slopes and intercepts
garcia2.lmer <- lmer(cumattack~treatment+time+treatment*time+(time|toad), REML=FALSE, garcia)
Second just random intercepts
garcia3.lmer <- lmer(cumattack~treatment*time+(1|toad), REML=FALSE, garcia)
Test random slopes term - note the comparison is based on ML fits
anova(garcia3.lmer,garcia2.lmer)
Data: garcia
Models:
garcia3.lmer: cumattack ~ treatment * time + (1 | toad)
garcia2.lmer: cumattack ~ treatment + time + treatment * time + (time | toad)
npar AIC BIC logLik deviance Chisq Df Pr(>Chisq)
garcia3.lmer 6 518.48 533.48 -253.24 506.48
garcia2.lmer 8 465.00 485.00 -224.50 449.00 57.483 2 3.294e-13 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
AICc(garcia3.lmer,garcia2.lmer)
garcia4.lmer <- lmer(cumattack~treatment+time+treatment*time+(time|toad), REML=TRUE, garcia)
summary(garcia4.lmer, ddf="Kenward-Roger")
Linear mixed model fit by REML. t-tests use Kenward-Roger's method ['lmerModLmerTest']
Formula: cumattack ~ treatment + time + treatment * time + (time | toad)
Data: garcia
REML criterion at convergence: 449.9
Scaled residuals:
Min 1Q Median 3Q Max
-1.89438 -0.62632 0.07927 0.48621 1.75457
Random effects:
Groups Name Variance Std.Dev. Corr
toad (Intercept) 13.9359 3.7331
time 0.3144 0.5607 -0.04
Residual 2.8390 1.6849
Number of obs: 90, groups: toad, 18
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 3.9944 0.9735 16.0000 4.103 0.000831 ***
treatment1 1.0722 0.9735 16.0000 1.101 0.287014
time 1.4685 0.1386 16.0000 10.592 1.23e-08 ***
treatment1:time -0.5944 0.1386 16.0000 -4.288 0.000565 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) trtmn1 time
treatment1 0.000
time -0.154 0.000
tretmnt1:tm 0.000 -0.154 0.000
anova(garcia4.lmer, type="3", ddf="Kenward-Roger")
Type III Analysis of Variance Table with Kenward-Roger's method
Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
treatment 3.44 3.44 1 16 1.2131 0.2870140
time 318.53 318.53 1 16 112.2005 1.226e-08 ***
treatment:time 52.19 52.19 1 16 18.3848 0.0005649 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
get var comps
garcia4.ci <- confint.merMod(garcia4.lmer, oldNames=FALSE)
Computing profile confidence intervals ...
garcia4.vc <- (garcia4.ci)^2
print(garcia4.vc)
2.5 % 97.5 %
sd_(Intercept)|toad 5.1156549 28.4594487
cor_time.(Intercept)|toad 0.2677897 0.2562486
sd_time|toad 0.1382368 0.6086524
sigma 1.9907550 4.2456171
(Intercept) 4.3897541 34.7358522
treatment1 0.6840088 8.8297571
time 1.4352649 3.0241614
treatment1:time 0.7481169 0.1049445
garcia5.lmer <- lmer(cumattack~treatment*time+(1|toad), REML=TRUE, garcia)
summary(garcia5.lmer, ddf="Kenward-Roger")
Linear mixed model fit by REML. t-tests use Kenward-Roger's method ['lmerModLmerTest']
Formula: cumattack ~ treatment * time + (1 | toad)
Data: garcia
REML criterion at convergence: 508.1
Scaled residuals:
Min 1Q Median 3Q Max
-2.7723 -0.5665 0.1216 0.5436 2.6657
Random effects:
Groups Name Variance Std.Dev.
toad (Intercept) 36.469 6.039
Residual 9.308 3.051
Number of obs: 90, groups: toad, 18
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 3.9944 1.6109 23.5011 2.480 0.0207 *
treatment1 1.0722 1.6109 23.5011 0.666 0.5121
time 1.4685 0.0758 70.0000 19.374 < 2e-16 ***
treatment1:time -0.5944 0.0758 70.0000 -7.842 3.56e-11 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) trtmn1 time
treatment1 0.000
time -0.423 0.000
tretmnt1:tm 0.000 -0.423 0.000
anova(garcia5.lmer, type="3", ddf="Kenward-Roger")
Type III Analysis of Variance Table with Kenward-Roger's method
Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
treatment 4.1 4.1 1 23.501 0.4431 0.5121
time 3493.6 3493.6 1 70.000 375.3426 < 2.2e-16 ***
treatment:time 572.4 572.4 1 70.000 61.5023 3.565e-11 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Get CIs as well
garcia5.ci <- confint.merMod(garcia5.lmer, oldNames=FALSE)
Computing profile confidence intervals ...
garcia5.vc <- (garcia5.ci)^2
print(garcia5.vc)
2.5 % 97.5 %
sd_(Intercept)|toad 17.0727070 69.0998289
sigma 6.6384482 12.7832490
(Intercept) 0.7734961 50.5436071
treatment1 4.1727702 17.5324806
time 1.7425498 2.6146253
treatment1:time 0.5519097 0.1989005
lmeControl(maxIter = 100) #Controls lme optimization process
$maxIter
[1] 100
$msMaxIter
[1] 50
$tolerance
[1] 1e-06
$niterEM
[1] 25
$msMaxEval
[1] 200
$msTol
[1] 1e-07
$msVerbose
[1] FALSE
$returnObject
[1] FALSE
$gradHess
[1] TRUE
$apVar
[1] TRUE
$.relStep
[1] 6.055454e-06
$opt
[1] "nlminb"
$optimMethod
[1] "BFGS"
$minAbsParApVar
[1] 0.05
$natural
[1] TRUE
$sigma
[1] 0
$allow.n.lt.q
[1] FALSE
garcia5.lme <- lme(cumattack~treatment*time, random=~time|toad, method="ML",garcia)
garcia6.lme <- lme(cumattack~treatment*time, random=~time|toad, correlation=corAR1(, form=~1|toad),method="ML",garcia)
Error in lme.formula(cumattack ~ treatment * time, random = ~time | toad, :
nlminb problem, convergence error code = 1
message = iteration limit reached without convergence (10)
couldn’t get convergence with AR(1) with random slopes even when increasing max iterations to 100 so use random intercept model. For the rand. int. model, we still need to keep the number of iterations above the default
garcia7.lme <- lme(cumattack~treatment*time, random=~1|toad, method="ML",garcia)
garcia8.lme <- lme(cumattack~treatment*time, random=~1|toad, correlation=corAR1(, form=~1|toad),method="ML",garcia)
anova(garcia7.lme,garcia8.lme)
AICc(garcia7.lme,garcia8.lme)