Compute an ANOVA-like table with tests of random-effect terms in the model.
Each random-effect term is reduced or removed and likelihood ratio tests of
model reductions are presented in a form similar to that of
drop1.
rand is an alias for ranova.
ranova(model, reduce.terms = TRUE, ...)
rand(model, reduce.terms = TRUE, ...)a linear mixed effect model fitted with lmer()
(inheriting from class lmerMod).
if TRUE (default) random-effect terms are
reduced (if possible). If FALSE random-effect terms are simply
removed.
currently ignored
an ANOVA-like table with single term deletions of random-effects
inheriting from class anova and data.frame with the columns:
number of model parameters.
the log-likelihood for the model. Note that this is the REML-logLik if the model is fitted with REML.
the AIC for the model evaluated as -2*(logLik - npar).
Smaller is better.
the likelihood ratio test statistic; twice the difference in log-likelihood, which is asymptotically chi-square distributed.
degrees of freedom for the likelihood ratio test: the difference in number of model parameters.
the p-value.
If the model is fitted with REML the tests are REML-likelihood ratio tests.
A random-effect term of the form (f1 + f2 | gr) is reduced to
terms of the form (f2 | gr) and (f1 | gr) and these reduced
models are compared to the original model.
If reduce.terms is FALSE (f1 + f2 | gr) is removed
instead.
A random-effect term of the form (f1 | gr) is reduced to (1 | gr)
(unless reduce.terms is FALSE).
A random-effect term of the form (1 | gr) is not reduced but
simply removed.
A random-effect term of the form (0 + f1 | gr) or (-1 + f1 | gr)
is reduced (if reduce.terms = TRUE) to (1 | gr).
A random-effect term of the form (1 | gr1/gr2) is automatically
expanded to two terms: (1 | gr2:gr1) and (1 | gr1) using
findbars.
In this exposition it is immaterial whether f1 and f2 are
factors or continuous variables.
Note that anova can be used to compare two models and will often
be able to produce the same tests as ranova. This is, however, not always the
case as illustrated in the examples.
In certain cases tests of non-nested models may be generated. An example
is when (0 + poly(x, 2) | gr) is reduced (the default) to (1 | gr).
To our best knowledge non-nested model comparisons are only generated in
cases which are statistical nonsense anyway (such as in this example where
the random intercept is suppressed).
# Test reduction of (Days | Subject) to (1 | Subject):
fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
ranova(fm1) # 2 df test
#> ANOVA-like table for random-effects: Single term deletions
#>
#> Model:
#> Reaction ~ Days + (Days | Subject)
#> npar logLik AIC LRT Df Pr(>Chisq)
#> <none> 6 -871.81 1755.6
#> Days in (Days | Subject) 4 -893.23 1794.5 42.837 2 4.99e-10 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# This test can also be achieved with anova():
fm2 <- lmer(Reaction ~ Days + (1|Subject), sleepstudy)
anova(fm1, fm2, refit=FALSE)
#> Data: sleepstudy
#> Models:
#> fm2: Reaction ~ Days + (1 | Subject)
#> fm1: Reaction ~ Days + (Days | Subject)
#> npar AIC BIC logLik -2*log(L) Chisq Df Pr(>Chisq)
#> fm2 4 1794.5 1807.2 -893.23 1786.5
#> fm1 6 1755.6 1774.8 -871.81 1743.6 42.837 2 4.99e-10 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# Illustrate reduce.test argument:
# Test removal of (Days | Subject):
ranova(fm1, reduce.terms = FALSE) # 3 df test
#> ANOVA-like table for random-effects: Single term deletions
#>
#> Model:
#> Reaction ~ Days + (Days | Subject)
#> npar logLik AIC LRT Df Pr(>Chisq)
#> <none> 6 -871.81 1755.6
#> (Days | Subject) 3 -946.83 1899.7 150.03 3 < 2.2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# The likelihood ratio test statistic is in this case:
fm3 <- lm(Reaction ~ Days, sleepstudy)
2*c(logLik(fm1, REML=TRUE) - logLik(fm3, REML=TRUE)) # LRT
#> [1] 150.0354
# anova() is not always able to perform the same tests as ranova(),
# for example:
anova(fm1, fm3, refit=FALSE) # compares REML with ML and should not be used
#> Warning: some models fit with REML = TRUE, some not
#> Data: sleepstudy
#> Models:
#> fm3: Reaction ~ Days
#> fm1: Reaction ~ Days + (Days | Subject)
#> npar AIC BIC logLik -2*log(L) Chisq Df Pr(>Chisq)
#> fm3 3 1906.3 1915.9 -950.15 1900.3
#> fm1 6 1755.6 1774.8 -871.81 1743.6 156.66 3 < 2.2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
anova(fm1, fm3, refit=TRUE) # is a test of ML fits and not what we seek
#> refitting model(s) with ML (instead of REML)
#> Data: sleepstudy
#> Models:
#> fm3: Reaction ~ Days
#> fm1: Reaction ~ Days + (Days | Subject)
#> npar AIC BIC logLik -2*log(L) Chisq Df Pr(>Chisq)
#> fm3 3 1906.3 1915.9 -950.15 1900.3
#> fm1 6 1763.9 1783.1 -875.97 1751.9 148.35 3 < 2.2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# Also note that the lmer-fit needs to come first - not an lm-fit:
# anova(fm3, fm1) # does not work and gives an error
# ranova() may not generate all relevant test:
# For the following model ranova() indicates that we should not reduce
# (TVset | Assessor):
fm <- lmer(Coloursaturation ~ TVset * Picture + (TVset | Assessor), data=TVbo)
ranova(fm)
#> ANOVA-like table for random-effects: Single term deletions
#>
#> Model:
#> Coloursaturation ~ TVset + Picture + (TVset | Assessor) + TVset:Picture
#> npar logLik AIC LRT Df Pr(>Chisq)
#> <none> 19 -280.09 598.17
#> TVset in (TVset | Assessor) 14 -302.61 633.22 45.048 5 1.418e-08 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# However, a more appropriate model is:
fm2 <- lmer(Coloursaturation ~ TVset * Picture + (1 | TVset:Assessor), data=TVbo)
anova(fm, fm2, refit=FALSE)
#> Data: TVbo
#> Models:
#> fm2: Coloursaturation ~ TVset * Picture + (1 | TVset:Assessor)
#> fm: Coloursaturation ~ TVset * Picture + (TVset | Assessor)
#> npar AIC BIC logLik -2*log(L) Chisq Df Pr(>Chisq)
#> fm2 14 588.53 634.14 -280.27 560.53
#> fm 19 598.17 660.06 -280.09 560.17 0.3613 5 0.9963
# fm and fm2 has essentially the same fit to data but fm uses 5 parameters
# more than fm.