CRAN Package Check Results for Package lmerTest

Last updated on 2026-07-23 13:49:57 CEST.

Flavor Version Tinstall Tcheck Ttotal Status Flags
r-devel-linux-x86_64-debian-clang 3.2-1 14.87 282.71 297.58 OK
r-devel-linux-x86_64-debian-gcc 3.2-1 9.22 184.65 193.87 ERROR
r-devel-linux-x86_64-fedora-clang 3.2-1 24.00 432.22 456.22 OK
r-devel-linux-x86_64-fedora-gcc 3.2-1 9.00 173.68 182.68 OK
r-devel-windows-x86_64 3.2-1 14.00 256.00 270.00 OK
r-patched-linux-x86_64 3.2-1 13.92 263.52 277.44 OK
r-release-linux-x86_64 3.2-1 10.90 262.99 273.89 OK
r-release-macos-arm64 3.2-1 3.00 62.00 65.00 OK
r-release-macos-x86_64 3.2-1 10.00 278.00 288.00 OK
r-release-windows-x86_64 3.2-1 17.00 262.00 279.00 OK
r-oldrel-macos-arm64 3.2-1 OK
r-oldrel-macos-x86_64 3.2-1 10.00 209.00 219.00 OK
r-oldrel-windows-x86_64 3.2-1 22.00 368.00 390.00 OK

Check Details

Version: 3.2-1
Check: tests
Result: ERROR Running ‘test_a_utils.R’ [2s/3s] Running ‘test_anova.R’ [6s/7s] Running ‘test_compare_sas.R’ [4s/5s] Running ‘test_contest1D.R’ [4s/5s] Running ‘test_contestMD.R’ [4s/5s] Running ‘test_contrast_utils.R’ [3s/4s] Running ‘test_devfun_vp.R’ [4s/5s] Running ‘test_drop1.R’ [4s/5s] Running ‘test_legacy.R’ [5s/6s] Running ‘test_lmer.R’ [5s/6s] Running ‘test_lmerTest_paper.R’ [14s/18s] Running ‘test_ls_means.R’ [4s/6s] Running ‘test_ranova_step.R’ [10s/11s] Running ‘test_re_covar_structures.R’ [16s/22s] Running ‘test_summary.R’ [4s/5s] Running ‘test_zerovar.R’ [3s/5s] Running ‘zlmerTest_zeroDenom.R’ [3s/3s] Running the tests in ‘tests/test_ranova_step.R’ failed. Complete output: > # test_ranova.R > > # Test functionality _before_ attaching lmerTest > stopifnot(!"lmerTest" %in% .packages()) # ensure that lmerTest is NOT attached > data("sleepstudy", package="lme4") > f <- function(form, data) lmerTest::lmer(form, data=data) > form <- "Reaction ~ Days + (Days|Subject)" > fm <- f(form, data=sleepstudy) > lmerTest::ranova(fm) 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 > lmerTest::rand(fm) 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 > lmerTest::step(fm) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df Pr(>Chisq) <none> 6 -871.81 1755.6 Days in (Days | Subject) 0 4 -893.23 1794.5 42.837 2 4.99e-10 <none> Days in (Days | Subject) *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Days 0 30031 30031 1 17 45.853 3.264e-06 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ Days + (Days | Subject) > > library(lmerTest) Loading required package: lme4 Loading required package: Matrix Attaching package: 'lmerTest' The following object is masked from 'package:lme4': lmer The following object is masked from 'package:stats': step > > # WRE says "using if(requireNamespace("pkgname")) is preferred, if possible." > # even in tests: > assertError <- function(expr, ...) + if(requireNamespace("tools")) tools::assertError(expr, ...) else invisible() > assertWarning <- function(expr, ...) + if(requireNamespace("tools")) tools::assertWarning(expr, ...) else invisible() > > TOL <- 1e-4 > ##################################################################### > data("sleepstudy", package="lme4") > > # Test reduction of (Days | Subject) to (1 | Subject): > fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy) > (an <- rand(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 > (an <- 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 > step(fm1) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df Pr(>Chisq) <none> 6 -871.81 1755.6 Days in (Days | Subject) 0 4 -893.23 1794.5 42.837 2 4.99e-10 <none> Days in (Days | Subject) *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Days 0 30031 30031 1 17 45.853 3.264e-06 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ Days + (Days | Subject) > stopifnot( + nrow(an) == 2L, + an[2L, "Df"] == 2L + ) > > # This test can also be achieved with anova(): > fm2 <- lmer(Reaction ~ Days + (1|Subject), sleepstudy) > (stp <- step(fm2)) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df Pr(>Chisq) <none> 4 -893.23 1794.5 (1 | Subject) 0 3 -946.83 1899.7 107.2 1 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Days 0 162703 162703 1 161 169.4 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ Days + (1 | Subject) > get_model(stp) Linear mixed model fit by REML ['lmerModLmerTest'] Formula: Reaction ~ Days + (1 | Subject) Data: sleepstudy REML criterion at convergence: 1786.465 Random effects: Groups Name Std.Dev. Subject (Intercept) 37.12 Residual 30.99 Number of obs: 180, groups: Subject, 18 Fixed Effects: (Intercept) Days 251.41 10.47 > (ana <- 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 > > stopifnot( + all.equal(an[2L, "LRT"], ana[2L, "Chisq"], tolerance=TOL) + ) > > # Illustrate complete.test argument: > # Test removal of (Days | Subject): > (an <- 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) > LRT <- 2*c(logLik(fm1, REML=TRUE) - logLik(fm3, REML=TRUE)) # LRT > stopifnot( + nrow(an) == 2L, + an[2L, "Df"] == 3L, + all.equal(an[2L, "LRT"], LRT, tolerance=TOL) + ) > > ## _NULL_ model: > fm <- lmer(Reaction ~ -1 + (1|Subject), sleepstudy) > step(fm) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df Pr(>Chisq) <none> 2 -992.84 1989.7 (1 | Subject) 0 1 -1284.32 2570.7 582.97 1 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Model found: Reaction ~ -1 + (1 | Subject) > ranova(fm) ANOVA-like table for random-effects: Single term deletions Model: Reaction ~ -1 + (1 | Subject) npar logLik AIC LRT Df Pr(>Chisq) <none> 2 -992.84 1989.7 (1 | Subject) 1 -1284.32 2570.7 582.97 1 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > lm1 <- lm(Reaction ~ 0, data=sleepstudy) > LRT <- 2*c(logLik(fm, REML=FALSE) - logLik(lm1, REML=FALSE)) > > ## Tests of ML-fits agree with anova(): > fm1 <- lmer(Reaction ~ Days + (1|Subject), sleepstudy, REML=FALSE) > step(fm1) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df Pr(>Chisq) <none> 4 -897.04 1802.1 (1 | Subject) 0 3 -950.15 1906.3 106.21 1 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Days 0 162703 162703 1 162 170.45 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ Days + (1 | Subject) > lm2 <- lm(Reaction ~ Days, sleepstudy) > (an1 <- ranova(fm1)) ANOVA-like table for random-effects: Single term deletions Model: Reaction ~ Days + (1 | Subject) npar logLik AIC LRT Df Pr(>Chisq) <none> 4 -897.04 1802.1 (1 | Subject) 3 -950.15 1906.3 106.21 1 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > (an2 <- anova(fm1, lm2)) Data: sleepstudy Models: lm2: Reaction ~ Days fm1: Reaction ~ Days + (1 | Subject) npar AIC BIC logLik -2*log(L) Chisq Df Pr(>Chisq) lm2 3 1906.3 1915.9 -950.15 1900.3 fm1 4 1802.1 1814.8 -897.04 1794.1 106.21 1 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > j <- grep("Chi Df|Df", colnames(an2)) > stopifnot( + all.equal(an1[2, "LRT"], an2[2, "Chisq"], tolerance=TOL), + all.equal(an1[2, "Df"], an2[2, j[length(j)]], tolerance=TOL), + all.equal(an1[1:2, "logLik"], an2[2:1, "logLik"], tolerance=TOL) + ) > ## Note that lme4 version <1.1-22 use "Chi Df" while >=1.1-22 use "Df" > > # Expect warnings when old (version < 3.0-0) arguments are used: > assertWarning(step(fm, reduce.fixed = FALSE, reduce.random = FALSE, + type=3, fixed.calc = FALSE, lsmeans.calc = FALSE, + difflsmeans.calc = TRUE, test.effs = 42, keep.e="save")) > assertWarning(step(fm, reduce.fixed = FALSE, reduce.random = FALSE, + lsmeans=3)) > > > check_nrow <- function(obj, expect_nrow) { + stopifnot( + is.numeric(expect_nrow), + nrow(obj) == expect_nrow + ) + } > > # Statistical nonsense, but it works: > fm1 <- lmer(Reaction ~ Days + (1 | Subject) + (0 + Days|Subject), sleepstudy) > step(fm1) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df <none> 5 -871.83 1753.7 (1 | Subject) 0 4 -883.26 1774.5 22.856 1 Days in (0 + Days | Subject) 0 4 -893.23 1794.5 42.796 1 Pr(>Chisq) <none> (1 | Subject) 1.746e-06 *** Days in (0 + Days | Subject) 6.076e-11 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Days 0 29442 29442 1 18.156 45.046 2.594e-06 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ Days + (1 | Subject) + (0 + Days | Subject) > (an <- ranova(fm1)) ANOVA-like table for random-effects: Single term deletions Model: Reaction ~ Days + (1 | Subject) + (0 + Days | Subject) npar logLik AIC LRT Df Pr(>Chisq) <none> 5 -871.83 1753.7 (1 | Subject) 4 -883.26 1774.5 22.856 1 1.746e-06 *** Days in (0 + Days | Subject) 4 -893.23 1794.5 42.796 1 6.076e-11 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > check_nrow(an, 3) > ranova(fm1, reduce.terms = FALSE) ANOVA-like table for random-effects: Single term deletions Model: Reaction ~ Days + (1 | Subject) + (0 + Days | Subject) npar logLik AIC LRT Df Pr(>Chisq) <none> 5 -871.83 1753.7 (1 | Subject) 4 -883.26 1774.5 22.856 1 1.746e-06 *** (0 + Days | Subject) 4 -893.23 1794.5 42.796 1 6.076e-11 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > # Statistical nonsense, but it works: > fm1 <- lmer(Reaction ~ Days + (0 + Days|Subject), sleepstudy) > step(fm1) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df Pr(>Chisq) <none> 4 -883.26 1774.5 Days in (0 + Days | Subject) 0 4 -893.23 1794.5 19.94 0 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Days 0 26395 26395 1 21.679 31.347 1.32e-05 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ Days + (0 + Days | Subject) > (an <- ranova(fm1)) # no test of non-nested models ANOVA-like table for random-effects: Single term deletions Model: Reaction ~ Days + (0 + Days | Subject) npar logLik AIC LRT Df Pr(>Chisq) <none> 4 -883.26 1774.5 Days in (0 + Days | Subject) 4 -893.23 1794.5 19.94 0 > stopifnot( + nrow(an) == 2L, + an[2L, "Df"] == 0, + all(is.na(an[2L, "Pr(>Chisq)"])) + ) > fm0 <- lmer(Reaction ~ Days + (1|Subject), sleepstudy) > step(fm0) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df Pr(>Chisq) <none> 4 -893.23 1794.5 (1 | Subject) 0 3 -946.83 1899.7 107.2 1 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Days 0 162703 162703 1 161 169.4 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ Days + (1 | Subject) > (an2 <- anova(fm1, fm0, refit=FALSE)) Data: sleepstudy Models: fm1: Reaction ~ Days + (0 + Days | Subject) fm0: Reaction ~ Days + (1 | Subject) npar AIC BIC logLik -2*log(L) Chisq Df Pr(>Chisq) fm1 4 1774.5 1787.3 -883.26 1766.5 fm0 4 1794.5 1807.2 -893.23 1786.5 0 0 > stopifnot( + (packageVersion("lme4")<="1.1.23" && an2[2L, "Pr(>Chisq)"] == 1) || + is.na(an2[2L, "Pr(>Chisq)"]) + ) > ranova(fm1, reduce.terms = FALSE) ANOVA-like table for random-effects: Single term deletions Model: Reaction ~ Days + (0 + Days | Subject) npar logLik AIC LRT Df Pr(>Chisq) <none> 4 -883.26 1774.5 (0 + Days | Subject) 3 -946.83 1899.7 127.14 1 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > fm1 <- lmer(Reaction ~ Days + (-1 + Days|Subject), sleepstudy) > step(fm1) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df <none> 4 -883.26 1774.5 Days in (-1 + Days | Subject) 0 4 -893.23 1794.5 19.94 0 Pr(>Chisq) <none> Days in (-1 + Days | Subject) Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Days 0 26395 26395 1 21.679 31.347 1.32e-05 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ Days + (-1 + Days | Subject) > (an3 <- ranova(fm1)) # no test of non-nested models ANOVA-like table for random-effects: Single term deletions Model: Reaction ~ Days + (-1 + Days | Subject) npar logLik AIC LRT Df Pr(>Chisq) <none> 4 -883.26 1774.5 Days in (-1 + Days | Subject) 4 -893.23 1794.5 19.94 0 > stopifnot( + all.equal(an, an3, check.attributes=FALSE, tolerance=TOL) + ) > > # Example where comparison of non-nested models is generated > fm <- lmer(Reaction ~ poly(Days, 2) + (0 + poly(Days, 2) | Subject), sleepstudy) boundary (singular) fit: see help('isSingular') > step(fm) Backward reduced random-effect table: Eliminated npar logLik AIC <none> 7 -937.05 1888.1 poly(Days, 2) in (0 + poly(Days, 2) | Subject) 1 5 -884.67 1779.3 (1 | Subject) 0 4 -938.16 1884.3 LRT Df Pr(>Chisq) <none> poly(Days, 2) in (0 + poly(Days, 2) | Subject) -104.77 2 1 (1 | Subject) 106.98 1 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) poly(Days, 2) 0 163782 81891 2 160 85.329 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ poly(Days, 2) + (1 | Subject) > an <- ranova(fm) > stopifnot( + nrow(an) == 2L, + an[2, "Pr(>Chisq)"] == 1 + ) > ranova(fm, reduce.terms = FALSE) # test of nested models ANOVA-like table for random-effects: Single term deletions Model: Reaction ~ poly(Days, 2) + (0 + poly(Days, 2) | Subject) npar logLik AIC LRT Df Pr(>Chisq) <none> 7 -937.05 1888.1 (0 + poly(Days, 2) | Subject) 4 -938.16 1884.3 2.2153 3 0.5289 > > # These models are nested, though: > fm <- lmer(Reaction ~ poly(Days, 2) + (1 + poly(Days, 2) | Subject), sleepstudy) > step(fm) Backward reduced random-effect table: Eliminated npar logLik AIC <none> 10 -856.40 1732.8 poly(Days, 2) in (1 + poly(Days, 2) | Subject) 0 5 -884.67 1779.3 LRT Df Pr(>Chisq) <none> poly(Days, 2) in (1 + poly(Days, 2) | Subject) 56.524 5 6.338e-11 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) poly(Days, 2) 0 24216 12108 2 17 23.367 1.323e-05 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ poly(Days, 2) + (1 + poly(Days, 2) | Subject) > ranova(fm) ANOVA-like table for random-effects: Single term deletions Model: Reaction ~ poly(Days, 2) + (1 + poly(Days, 2) | Subject) npar logLik AIC LRT Df <none> 10 -856.40 1732.8 poly(Days, 2) in (1 + poly(Days, 2) | Subject) 5 -884.67 1779.3 56.524 5 Pr(>Chisq) <none> poly(Days, 2) in (1 + poly(Days, 2) | Subject) 6.338e-11 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > fm0 <- lmer(Reaction ~ poly(Days, 2) + (1 | Subject), sleepstudy) > step(fm0) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df Pr(>Chisq) <none> 5 -884.67 1779.3 (1 | Subject) 0 4 -938.16 1884.3 106.98 1 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) poly(Days, 2) 0 163782 81891 2 160 85.329 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ poly(Days, 2) + (1 | Subject) > anova(fm0, fm, refit=FALSE) Data: sleepstudy Models: fm0: Reaction ~ poly(Days, 2) + (1 | Subject) fm: Reaction ~ poly(Days, 2) + (1 + poly(Days, 2) | Subject) npar AIC BIC logLik -2*log(L) Chisq Df Pr(>Chisq) fm0 5 1779.3 1795.3 -884.67 1769.3 fm 10 1732.8 1764.7 -856.40 1712.8 56.524 5 6.338e-11 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > ranova(fm, reduce.terms = FALSE) ANOVA-like table for random-effects: Single term deletions Model: Reaction ~ poly(Days, 2) + (1 + poly(Days, 2) | Subject) npar logLik AIC LRT Df Pr(>Chisq) <none> 10 -856.40 1732.8 (1 + poly(Days, 2) | Subject) 4 -938.16 1884.3 163.51 6 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > # A model with ||-notation: > fm1 <- lmer(Reaction ~ Days + (Days||Subject), sleepstudy) > step(fm1) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df <none> 5 -871.83 1753.7 (1 | Subject) 0 4 -883.26 1774.5 22.856 1 Days in (0 + Days | Subject) 0 4 -893.23 1794.5 42.796 1 Pr(>Chisq) <none> (1 | Subject) 1.746e-06 *** Days in (0 + Days | Subject) 6.076e-11 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Days 0 29442 29442 1 18.156 45.046 2.594e-06 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ Days + ((1 | Subject) + (0 + Days | Subject)) > ranova(fm1) ANOVA-like table for random-effects: Single term deletions Model: Reaction ~ Days + (1 | Subject) + (0 + Days | Subject) npar logLik AIC LRT Df Pr(>Chisq) <none> 5 -871.83 1753.7 (1 | Subject) 4 -883.26 1774.5 22.856 1 1.746e-06 *** Days in (0 + Days | Subject) 4 -893.23 1794.5 42.796 1 6.076e-11 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > # What about models with nested factors? > fm <- lmer(Coloursaturation ~ TVset*Picture + (1|Assessor:TVset) + (1|Assessor), + data=TVbo) > step(fm) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df Pr(>Chisq) <none> 15 -280.22 590.44 (1 | Assessor) 1 14 -280.27 588.53 0.090 1 0.7643 (1 | Assessor:TVset) 0 13 -312.24 650.47 63.941 1 1.282e-15 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) TVset:Picture 0 13.8 2.2999 6 159 2.6761 0.01679 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Coloursaturation ~ TVset + Picture + (1 | Assessor:TVset) + TVset:Picture > (an1 <- ranova(fm)) ANOVA-like table for random-effects: Single term deletions Model: Coloursaturation ~ TVset * Picture + (1 | Assessor:TVset) + (1 | Assessor) npar logLik AIC LRT Df Pr(>Chisq) <none> 15 -280.22 590.44 (1 | Assessor:TVset) 14 -302.61 633.22 44.777 1 2.208e-11 *** (1 | Assessor) 14 -280.27 588.53 0.090 1 0.7643 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > fm <- lmer(Coloursaturation ~ TVset * Picture + + (1|Assessor/TVset), data=TVbo) > step(fm) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df Pr(>Chisq) <none> 15 -280.22 590.44 (1 | Assessor) 1 14 -280.27 588.53 0.090 1 0.7643 (1 | TVset:Assessor) 0 13 -312.24 650.47 63.941 1 1.282e-15 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) TVset:Picture 0 13.8 2.2999 6 159 2.6761 0.01679 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Coloursaturation ~ TVset + Picture + (1 | TVset:Assessor) + TVset:Picture > (an2 <- ranova(fm)) ANOVA-like table for random-effects: Single term deletions Model: Coloursaturation ~ TVset * Picture + (1 | TVset:Assessor) + (1 | Assessor) npar logLik AIC LRT Df Pr(>Chisq) <none> 15 -280.22 590.44 (1 | TVset:Assessor) 14 -302.61 633.22 44.777 1 2.208e-11 *** (1 | Assessor) 14 -280.27 588.53 0.090 1 0.7643 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > stopifnot( + all.equal(an1, an2, check.attributes=FALSE, tolerance=TOL) + ) > > ##################################################################### > # Test evaluation within functions, i.e. in other environments etc. > attach(sleepstudy) > fm <- lmer(Reaction ~ Days + (Days|Subject)) > step(fm) Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df Pr(>Chisq) <none> 6 -871.81 1755.6 Days in (Days | Subject) 0 4 -893.23 1794.5 42.837 2 4.99e-10 <none> Days in (Days | Subject) *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Days 0 30031 30031 1 17 45.853 3.264e-06 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Reaction ~ Days + (Days | Subject) > ranova(fm) # OK 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 > detach(sleepstudy) > > # Evaluating in a function works: > f <- function(form, data) lmer(form, data=data) > form <- "Informed.liking ~ Product+Information+ + (1|Consumer) + (1|Product:Consumer) + (1|Information:Consumer)" > fm <- f(form, data=ham) > ranova(fm) boundary (singular) fit: see help('isSingular') ANOVA-like table for random-effects: Single term deletions Model: Informed.liking ~ Product + Information + (1 | Consumer) + (1 | Product:Consumer) + (1 | Information:Consumer) npar logLik AIC LRT Df Pr(>Chisq) <none> 9 -1353.9 2725.8 (1 | Consumer) 8 -1355.1 2726.1 2.295 1 0.1298 (1 | Product:Consumer) 8 -1436.3 2888.6 164.753 1 <2e-16 *** (1 | Information:Consumer) 8 -1354.5 2725.1 1.255 1 0.2626 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > step_res <- step(fm) boundary (singular) fit: see help('isSingular') > stopifnot( + all(c("Sum Sq", "Mean Sq", "NumDF", "DenDF", "F value", "Pr(>F)") %in% + colnames(step_res$fixed)) + ) > > ########################### > # Evaluation in function without the formula: > # Reported by Uwe Ligges 2025-01-16. > f <- function(data) { + lmer(Petal.Length ~ Sepal.Length + (1|Species), data=data) + } > > res <- f(iris) > ranova(res) # used to fail - now it works ANOVA-like table for random-effects: Single term deletions Model: Petal.Length ~ Sepal.Length + (1 | Species) npar logLik AIC LRT Df Pr(>Chisq) <none> 4 -34.66 77.32 (1 | Species) 3 -193.84 393.68 318.36 1 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > data <- iris > ranova(res) # now it works ANOVA-like table for random-effects: Single term deletions Model: Petal.Length ~ Sepal.Length + (1 | Species) npar logLik AIC LRT Df Pr(>Chisq) <none> 4 -34.66 77.32 (1 | Species) 3 -193.84 393.68 318.36 1 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > ########################### > # Evaluation in function without the formula(2): > # A model with ||-notation: > f2 <- function(data) { + lmer(Reaction ~ Days + (Days||Subject), data) + } > res <- f2(sleepstudy) > ranova(res) ANOVA-like table for random-effects: Single term deletions Model: Reaction ~ Days + (1 | Subject) + (0 + Days | Subject) npar logLik AIC LRT Df Pr(>Chisq) <none> 5 -871.83 1753.7 (1 | Subject) 4 -883.26 1774.5 22.856 1 1.746e-06 *** Days in (0 + Days | Subject) 4 -893.23 1794.5 42.796 1 6.076e-11 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > # A model with multiple RE terms: > f3 <- function(data) { + lmer(Coloursaturation ~ TVset*Picture + (1|Assessor:TVset) + (1|Assessor), data) + } > res <- f3(TVbo) > ranova(res) ANOVA-like table for random-effects: Single term deletions Model: Coloursaturation ~ TVset * Picture + (1 | Assessor:TVset) + (1 | Assessor) npar logLik AIC LRT Df Pr(>Chisq) <none> 15 -280.22 590.44 (1 | Assessor:TVset) 14 -302.61 633.22 44.777 1 2.208e-11 *** (1 | Assessor) 14 -280.27 588.53 0.090 1 0.7643 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > ########################### > > # Check that step works when form is a character vector > m <- lmer(form, data=ham) > step_res <- step(m) boundary (singular) fit: see help('isSingular') > (drop1_table <- attr(step_res, "drop1")) Single term deletions using Satterthwaite's method: Model: Informed.liking ~ Product + Information + (1 | Consumer) + (1 | Product:Consumer) Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Product 19.3466 6.4489 3 240 3.8291 0.01048 * Information 6.5201 6.5201 1 323 3.8714 0.04997 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > stopifnot( + all(c("Sum Sq", "Mean Sq", "NumDF", "DenDF", "F value", "Pr(>F)") %in% + colnames(drop1_table)) + ) > # In version < 3.0-1.9002 attr(step_res, "drop1") picked up lme4::drop1.merMod > # and returned an AIC table after the model had been update'd. > > ##################################################################### > # Model with 2 ranef covarites: > > # Model of the form (x1 + x2 | gr): > model <- lmer(Preference ~ sens2 + Homesize + (sens1 + sens2 | Consumer) + , data=carrots) boundary (singular) fit: see help('isSingular') Warning message: Model failed to converge with 1 negative eigenvalue: -3.1e+02 > step(model) boundary (singular) fit: see help('isSingular') Backward reduced random-effect table: Eliminated npar logLik AIC LRT Df <none> 10 -1874.4 3768.8 sens1 in (sens1 + sens2 | Consumer) 1 7 -1874.5 3762.9 0.1333 3 sens2 in (sens2 | Consumer) 0 5 -1878.0 3765.9 6.9944 2 Pr(>Chisq) <none> sens1 in (sens1 + sens2 | Consumer) 0.98757 sens2 in (sens2 | Consumer) 0.03028 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) sens2 0 58.685 58.685 1 102.02 54.8236 3.888e-11 *** Homesize 0 5.979 5.979 1 100.95 5.5852 0.02003 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Preference ~ sens2 + Homesize + (sens2 | Consumer) > stopifnot( + nrow(ranova(model)) == 3L, + nrow(ranova(model, reduce.terms = FALSE)) == 2L + ) boundary (singular) fit: see help('isSingular') > > # Model of the form (f1 + f2 | gr): > model <- lmer(Preference ~ sens2 + Homesize + Gender + + (Gender+Homesize|Consumer), data=carrots) boundary (singular) fit: see help('isSingular') > step(model) Backward reduced random-effect table: Eliminated npar logLik AIC LRT <none> 11 -1872.3 3766.5 Gender in (Gender + Homesize | Consumer) 1 8 -1875.1 3766.3 5.7408 Homesize in (Homesize | Consumer) 0 6 -1878.4 3768.7 6.4705 Df Pr(>Chisq) <none> Gender in (Gender + Homesize | Consumer) 3 0.12493 Homesize in (Homesize | Consumer) 2 0.03935 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Backward reduced fixed-effect table: Degrees of freedom method: Satterthwaite Eliminated Sum Sq Mean Sq NumDF DenDF F value Pr(>F) Gender 1 0.632 0.632 1 91.80 0.5686 0.45275 sens2 0 83.385 83.385 1 1129.09 75.0490 < 2e-16 *** Homesize 0 6.212 6.212 1 97.82 5.5910 0.02003 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Model found: Preference ~ sens2 + Homesize + (Homesize | Consumer) Warning messages: 1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : unable to evaluate scaled gradient 2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model failed to converge: degenerate Hessian with 1 negative eigenvalues See ?lme4::convergence and ?lme4::troubleshooting. 3: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : unable to evaluate scaled gradient 4: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model failed to converge: degenerate Hessian with 1 negative eigenvalues See ?lme4::convergence and ?lme4::troubleshooting. 5: Model failed to converge with 1 negative eigenvalue: -2.7e-04 > stopifnot( + nrow(ranova(model)) == 3L, + nrow(ranova(model, reduce.terms = FALSE)) == 2L + ) Warning messages: 1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : unable to evaluate scaled gradient 2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model failed to converge: degenerate Hessian with 1 negative eigenvalues See ?lme4::convergence and ?lme4::troubleshooting. > > # Model of the form (-1 + f2 | gr): > model <- lmer(Preference ~ sens2 + Homesize + Gender + + (Gender -1 |Consumer), data=carrots) Warning message: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :*** buffer overflow detected ***: terminated Aborted Flavor: r-devel-linux-x86_64-debian-gcc