Running ‘test_a_utils.R’
  Running ‘test_anova.R’ [11s/13s]
  Running ‘test_compare_sas.R’
  Running ‘test_contest1D.R’ [8s/11s]
  Running ‘test_contestMD.R’ [9s/12s]
  Running ‘test_drop1.R’ [9s/10s]
  Running ‘test_lmer.R’ [9s/12s]
  Running ‘test_lmerTest_paper.R’ [37s/47s]
  Running ‘test_ls_means.R’ [9s/15s]
  Running ‘test_ranova_step.R’ [40s/48s]
  Running ‘test_summary.R’ [9s/11s]
  Running ‘test_zerovar.R’
  Running ‘zlmerTest_zeroDenom.R’
Running the tests in ‘tests/test_anova.R’ failed.
Complete output:
  > # test_anova.R
  > 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()
  > 
  > # Kenward-Roger only available with pbkrtest and only then validated in R >= 3.3.3
  > # (faulty results for R < 3.3.3 may be due to unstated dependencies in pbkrtest)
  > has_pbkrtest <- requireNamespace("pbkrtest", quietly = TRUE) && getRversion() >= "3.3.3"
  > 
  > data("sleepstudy", package="lme4")
  > TOL <- 1e-4
  > 
  > ####################################
  > ## Basic anova tests
  > ####################################
  > 
  > m <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
  > 
  > ####### ddf argument:
  > (an1 <- anova(m)) # Also testing print method.
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an2 <- anova(m, ddf="Satterthwaite"))
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an2b <- anova(m, ddf="Satterthwaite", type=3))
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an2c <- anova(m, ddf="Satterthwaite", type=2))
  Type II Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > stopifnot(isTRUE(
  +   all.equal(an1, an2, tolerance=TOL)
  + ))
  > (an3 <- anova(m, ddf="Sat")) ## Abbreviated argument
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > stopifnot(isTRUE(
  +   all.equal(an1, an3, tolerance=TOL)
  + ))
  > if(has_pbkrtest) {
  +   (anova(m, ddf="Kenward-Roger"))
  +   (anova(m, ddf="Kenward-Roger", type=3))
  + }
  Type III Analysis of Variance Table with Kenward-Roger's method
       Sum Sq Mean Sq NumDF DenDF F value    Pr(>F)    
  Days  30024   30024     1    17  45.843 3.268e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an1 <- anova(m, ddf="lme4"))
  Analysis of Variance Table
       Df Sum Sq Mean Sq F value
  Days  1  30024   30024  45.843
  > (an2 <- anova(m, ddf="lme4", type=3)) # 'type' is ignored with ddf="lme4"
  Analysis of Variance Table
       Df Sum Sq Mean Sq F value
  Days  1  30024   30024  45.843
  > stopifnot(isTRUE(
  +   all.equal(an1, an2, tolerance=TOL)
  + ))
  > res <- assertError(anova(m, ddf="KR")) ## Error on incorrect arg.
  > stopifnot(
  +   grepl("'arg' should be one of ", unlist(res[[1]])$message)
  + )
  > 
  > ## lme4 method:
  > an1 <- anova(m, ddf="lme4")
  > an2 <- anova(as(m, "lmerMod"))
  > stopifnot(isTRUE(
  +   all.equal(an1, an2, tolerance=TOL)
  + ))
  > 
  > ###### type argument:
  > (an1 <- anova(m, type="1")) # valid type arg.
  Type I Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an2 <- anova(m, type="I")) # same
  Type I Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > stopifnot(isTRUE(
  +   all.equal(an1, an2, tolerance=TOL)
  + ))
  > (an3 <- anova(m, type=1)) # Not strictly valid, but accepted
  Type I Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > stopifnot(isTRUE(
  +   all.equal(an1, an3, tolerance=TOL)
  + ))
  > 
  > (an1 <- anova(m, type="2")) # valid type arg.
  Type II Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an2 <- anova(m, type="II")) # same
  Type II Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > stopifnot(isTRUE(
  +   all.equal(an1, an2, tolerance=TOL)
  + ))
  > (an3 <- anova(m, type=3)) # Not strictly valid, but accepted
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > stopifnot(isTRUE(
  +   all.equal(an1, an3, check.attributes=FALSE, tolerance=TOL)
  + ))
  > 
  > (an1 <- anova(m, type="3")) # valid type arg.
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an2 <- anova(m, type="III")) # same
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > stopifnot(isTRUE(
  +   all.equal(an1, an2, tolerance=TOL)
  + ))
  > (an3 <- anova(m, type=3)) # Not strictly valid, but accepted
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > stopifnot(isTRUE(
  +   all.equal(an1, an3, tolerance=TOL)
  + ))
  > assertError(anova(m, type=0)) # Not valid arg.
  > assertError(anova(m, type="i")) # Not valid arg.
  > 
  > ####### Model comparison:
  > fm <- lm(Reaction ~ Days, sleepstudy)
  > (an <- anova(m, fm))
  refitting model(s) with ML (instead of REML)
  Data: sleepstudy
  Models:
  fm: Reaction ~ Days
  m: Reaction ~ Days + (Days | Subject)
     Df    AIC    BIC  logLik deviance  Chisq Chi Df Pr(>Chisq)    
  fm  3 1906.3 1915.9 -950.15   1900.3                             
  m   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
  > stopifnot(
  +   nrow(an) == 2L,
  +   rownames(an)[2] == "m"
  + )
  > 
  > m2 <- lmer(Reaction ~ Days + I(Days^2) + (Days | Subject), sleepstudy)
  > (an <- anova(m, m2, refit=FALSE))
  Data: sleepstudy
  Models:
  m: Reaction ~ Days + (Days | Subject)
  m2: Reaction ~ Days + I(Days^2) + (Days | Subject)
     Df    AIC    BIC  logLik deviance  Chisq Chi Df Pr(>Chisq)
  m   6 1755.6 1774.8 -871.81   1743.6                         
  m2  7 1756.8 1779.2 -871.41   1742.8 0.8127      1     0.3673
  > stopifnot(
  +   nrow(an) == 2L,
  +   rownames(an)[1] == "m"
  + )
  > 
  > 
  > ####################################
  > ## Example with factor fixef:
  > ####################################
  > 
  > ## 'temp' is continuous, 'temperature' an ordered factor with 6 levels
  > data("cake", package="lme4")
  > m <- lmer(angle ~ recipe * temp + (1|recipe:replicate), cake)
  > (an <- anova(m))
  Type III Analysis of Variance Table with Satterthwaite's method
               Sum Sq Mean Sq NumDF  DenDF F value Pr(>F)    
  recipe         4.00    2.00     2 254.02  0.0957 0.9088    
  temp        1966.71 1966.71     1 222.00 94.1632 <2e-16 ***
  recipe:temp    1.74    0.87     2 222.00  0.0417 0.9592    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an_lme4 <- anova(m, ddf="lme4"))
  Analysis of Variance Table
              Df  Sum Sq Mean Sq F value
  recipe       2   10.39    5.20  0.2488
  temp         1 1966.71 1966.71 94.1632
  recipe:temp  2    1.74    0.87  0.0417
  > 
  > if(has_pbkrtest) {
  +   (an_KR <- anova(m, ddf="Kenward-Roger"))
  +   # res <- all.equal(an[, c("Sum Sq", "Mean Sq", "F value")],
  +   #                  an_lme4[, c("Sum Sq", "Mean Sq", "F value")])
  +   # stopifnot(isTRUE(res))
  +   res <- all.equal(an[, c("Sum Sq", "Mean Sq", "F value")],
  +                    an_KR[, c("Sum Sq", "Mean Sq", "F value")], tolerance=TOL)
  +   stopifnot(isTRUE(res))
  + }
  > stopifnot(all.equal(c(2, 1, 2), an$NumDF, tol=1e-6),
  +           all.equal(c(254.0157612, 222, 222), an$DenDF, tol=TOL))
  > 
  > an3 <- anova(m, type=3)
  > an2 <- anova(m, type=2)
  > an1 <- anova(m, type=1)
  > 
  > ## Data is balanced, so Type II and III should be identical:
  > ## One variable is continuous, so Type I and II/III are different:
  > stopifnot(
  +   isTRUE(all.equal(an3, an2, check.attributes=FALSE, tolerance=TOL)),
  +   !isTRUE(all.equal(an1, an2, check.attributes=FALSE, tolerance=1e-8))
  + )
  > 
  > # Using an ordered factor:
  > m <- lmer(angle ~ recipe * temperature + (1|recipe:replicate), cake)
  > (an1 <- anova(m, type=1))
  Type I Analysis of Variance Table with Satterthwaite's method
                      Sum Sq Mean Sq NumDF DenDF F value Pr(>F)    
  recipe               10.19    5.09     2    42  0.2488 0.7809    
  temperature        2100.30  420.06     5   210 20.5199 <2e-16 ***
  recipe:temperature  205.98   20.60    10   210  1.0062 0.4393    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an2 <- anova(m, type=2))
  Type II Analysis of Variance Table with Satterthwaite's method
                      Sum Sq Mean Sq NumDF DenDF F value Pr(>F)    
  recipe               10.19    5.09     2    42  0.2488 0.7809    
  temperature        2100.30  420.06     5   210 20.5199 <2e-16 ***
  recipe:temperature  205.98   20.60    10   210  1.0062 0.4393    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > # Type 3 is also available with ordered factors:
  > (an3 <- anova(m, type=3))
  Type III Analysis of Variance Table with Satterthwaite's method
                      Sum Sq Mean Sq NumDF DenDF F value Pr(>F)    
  recipe               10.19    5.09     2    42  0.2488 0.7809    
  temperature        2100.30  420.06     5   210 20.5199 <2e-16 ***
  recipe:temperature  205.98   20.60    10   210  1.0062 0.4393    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > ## Balanced data and only factors: Type I, II and III should be the same:
  > stopifnot(
  +   isTRUE(all.equal(an1, an2, check.attributes=FALSE, tolerance=TOL)),
  +   isTRUE(all.equal(an1, an3, check.attributes=FALSE, tolerance=TOL))
  + )
  > 
  > (an <- anova(m, type=1))
  Type I Analysis of Variance Table with Satterthwaite's method
                      Sum Sq Mean Sq NumDF DenDF F value Pr(>F)    
  recipe               10.19    5.09     2    42  0.2488 0.7809    
  temperature        2100.30  420.06     5   210 20.5199 <2e-16 ***
  recipe:temperature  205.98   20.60    10   210  1.0062 0.4393    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an_lme4 <- anova(m, type=1, ddf="lme4"))
  Analysis of Variance Table
                     Df  Sum Sq Mean Sq F value
  recipe              2   10.19    5.09  0.2488
  temperature         5 2100.30  420.06 20.5199
  recipe:temperature 10  205.98   20.60  1.0062
  > res <- all.equal(an[, c("Sum Sq", "Mean Sq", "F value")],
  +                  an_lme4[, c("Sum Sq", "Mean Sq", "F value")], tolerance=TOL)
  > stopifnot(isTRUE(res))
  > if(has_pbkrtest) {
  +   (an_KR <- anova(m, type=1, ddf="Kenward-Roger"))
  +   res <- all.equal(an[, c("Sum Sq", "Mean Sq", "F value")],
  +                    an_KR[, c("Sum Sq", "Mean Sq", "F value")], tolerance=TOL)
  +   stopifnot(isTRUE(res))
  + }
  > stopifnot(all.equal(c(2, 5, 10), an$NumDF, tolerance=TOL),
  +           all.equal(c(42, 210, 210), an$DenDF, tolerance=TOL))
  > 
  > ########
  > ## Make case with balanced unordered factors:
  > cake2 <- cake
  > cake2$temperature <- factor(cake2$temperature, ordered = FALSE)
  > # str(cake2)
  > stopifnot(
  +   !is.ordered(cake2$temperature)
  + )
  > m <- lmer(angle ~ recipe * temperature + (1|recipe:replicate), cake2)
  > (an1 <- anova(m, type=1))
  Type I Analysis of Variance Table with Satterthwaite's method
                      Sum Sq Mean Sq NumDF DenDF F value Pr(>F)    
  recipe               10.19    5.09     2    42  0.2488 0.7809    
  temperature        2100.30  420.06     5   210 20.5199 <2e-16 ***
  recipe:temperature  205.98   20.60    10   210  1.0062 0.4393    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an2 <- anova(m, type=2))
  Type II Analysis of Variance Table with Satterthwaite's method
                      Sum Sq Mean Sq NumDF DenDF F value Pr(>F)    
  recipe               10.19    5.09     2    42  0.2488 0.7809    
  temperature        2100.30  420.06     5   210 20.5199 <2e-16 ***
  recipe:temperature  205.98   20.60    10   210  1.0062 0.4393    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an3 <- anova(m, type=3))
  Type III Analysis of Variance Table with Satterthwaite's method
                      Sum Sq Mean Sq NumDF DenDF F value Pr(>F)    
  recipe               10.19    5.09     2    42  0.2488 0.7809    
  temperature        2100.30  420.06     5   210 20.5199 <2e-16 ***
  recipe:temperature  205.98   20.60    10   210  1.0062 0.4393    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > ## Balanced data and only factors: Type I, II, and III should be the same:
  > stopifnot(
  +   isTRUE(all.equal(an1, an2, check.attributes=FALSE, tolerance=TOL)),
  +   isTRUE(all.equal(an3, an2, check.attributes=FALSE, tolerance=TOL))
  + )
  > ########
  > 
  > # No intercept:
  > m <- lmer(angle ~ 0 + recipe * temp + (1|recipe:replicate), cake)
  > (an <- anova(m, type=1))
  Type I Analysis of Variance Table with Satterthwaite's method
               Sum Sq Mean Sq NumDF DenDF  F value Pr(>F)    
  recipe      21442.9  7147.6     3    42 342.2200 <2e-16 ***
  temp         1966.7  1966.7     1   222  94.1632 <2e-16 ***
  recipe:temp     1.7     0.9     2   222   0.0417 0.9592    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an2 <- anova(m, type=2))
  Type II Analysis of Variance Table with Satterthwaite's method
               Sum Sq Mean Sq NumDF  DenDF F value Pr(>F)    
  recipe         4.48    1.49     3 254.02  0.0714 0.9752    
  temp        1966.71 1966.71     1 222.00 94.1632 <2e-16 ***
  recipe:temp    1.74    0.87     2 222.00  0.0417 0.9592    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an2 <- anova(m, type=3))
  Type III Analysis of Variance Table with Satterthwaite's method
               Sum Sq Mean Sq NumDF  DenDF F value Pr(>F)    
  recipe         4.48    1.49     3 254.02  0.0714 0.9752    
  temp        1966.71 1966.71     1 222.00 94.1632 <2e-16 ***
  recipe:temp    1.74    0.87     2 222.00  0.0417 0.9592    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > if(has_pbkrtest)
  +   (an_KR <- anova(m, ddf="Kenward-Roger"))
  Type III Analysis of Variance Table with Kenward-Roger's method
               Sum Sq Mean Sq NumDF  DenDF F value Pr(>F)    
  recipe         4.48    1.49     3 254.02  0.0714 0.9752    
  temp        1966.71 1966.71     1 222.00 94.1632 <2e-16 ***
  recipe:temp    1.74    0.87     2 222.00  0.0417 0.9592    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an_lme4 <- anova(m, ddf="lme4"))
  Analysis of Variance Table
              Df  Sum Sq Mean Sq  F value
  recipe       3 21442.9  7147.6 342.2200
  temp         1  1966.7  1966.7  94.1632
  recipe:temp  2     1.7     0.9   0.0417
  > res <- all.equal(an[, c("Sum Sq", "Mean Sq", "F value")],
  +                  an_lme4[, c("Sum Sq", "Mean Sq", "F value")], tolerance=TOL)
  > stopifnot(isTRUE(res))
  > 
  > # ML-fit:
  > m <- lmer(angle ~ recipe * temp + (1|recipe:replicate), cake, REML=FALSE)
  > (an <- anova(m, type=1))
  Type I Analysis of Variance Table with Satterthwaite's method
               Sum Sq Mean Sq NumDF DenDF F value Pr(>F)    
  recipe        10.99    5.49     2    45  0.2666 0.7672    
  temp        1966.71 1966.71     1   225 95.4357 <2e-16 ***
  recipe:temp    1.74    0.87     2   225  0.0423 0.9586    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > if(has_pbkrtest)
  +   assertError(an <- anova(m, ddf="Kenward-Roger")) # KR fits should be REML
  > (an_lme4 <- anova(m, ddf="lme4"))
  Analysis of Variance Table
              Df  Sum Sq Mean Sq F value
  recipe       2   10.99    5.49  0.2666
  temp         1 1966.71 1966.71 95.4357
  recipe:temp  2    1.74    0.87  0.0423
  > res <- all.equal(an[, c("Sum Sq", "Mean Sq", "F value")],
  +                  an_lme4[, c("Sum Sq", "Mean Sq", "F value")], tolerance=TOL)
  > stopifnot(isTRUE(res))
  > 
  > ####################################
  > ## Using contr.sum:
  > ####################################
  > 
  > m <- lmer(angle ~ recipe * temp + (1|recipe:replicate), cake,
  +           contrasts = list('recipe' = "contr.sum"))
  > (an <- anova(m, type=1))
  Type I Analysis of Variance Table with Satterthwaite's method
               Sum Sq Mean Sq NumDF DenDF F value Pr(>F)    
  recipe        10.39    5.20     2    42  0.2488 0.7809    
  temp        1966.71 1966.71     1   222 94.1632 <2e-16 ***
  recipe:temp    1.74    0.87     2   222  0.0417 0.9592    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an2 <- anova(m, type=2))
  Type II Analysis of Variance Table with Satterthwaite's method
               Sum Sq Mean Sq NumDF  DenDF F value Pr(>F)    
  recipe         4.00    2.00     2 254.02  0.0957 0.9088    
  temp        1966.71 1966.71     1 222.00 94.1632 <2e-16 ***
  recipe:temp    1.74    0.87     2 222.00  0.0417 0.9592    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an3 <- anova(m, type=3))
  Type III Analysis of Variance Table with Satterthwaite's method
               Sum Sq Mean Sq NumDF  DenDF F value Pr(>F)    
  recipe         4.00    2.00     2 254.02  0.0957 0.9088    
  temp        1966.71 1966.71     1 222.00 94.1632 <2e-16 ***
  recipe:temp    1.74    0.87     2 222.00  0.0417 0.9592    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > stopifnot(
  +   isTRUE(all.equal(an2, an3, check.attributes=FALSE, tolerance=TOL))
  + )
  > if(has_pbkrtest)
  +   (an_KR <- anova(m, type=1, ddf="Kenward-Roger"))
  Type I Analysis of Variance Table with Kenward-Roger's method
               Sum Sq Mean Sq NumDF DenDF F value Pr(>F)    
  recipe        10.39    5.20     2    42  0.2488 0.7809    
  temp        1966.71 1966.71     1   222 94.1632 <2e-16 ***
  recipe:temp    1.74    0.87     2   222  0.0417 0.9592    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an_lme4 <- anova(m, ddf="lme4"))
  Analysis of Variance Table
              Df  Sum Sq Mean Sq F value
  recipe       2   10.39    5.20  0.2488
  temp         1 1966.71 1966.71 94.1632
  recipe:temp  2    1.74    0.87  0.0417
  > res <- all.equal(an[, c("Sum Sq", "Mean Sq", "F value")],
  +                  an_lme4[, c("Sum Sq", "Mean Sq", "F value")], tolerance=TOL)
  > stopifnot(isTRUE(res))
  > 
  > 
  > ####################################
  > ## Example with continuous fixef:
  > ####################################
  > 
  > # Example with no fixef:
  > m <- lmer(Reaction ~ -1 + (Days | Subject), sleepstudy)
  > # m <- lmer(Reaction ~ 0 + (Days | Subject), sleepstudy) # alternative
  > stopifnot(length(fixef(m)) == 0L)
  > (an <- anova(m, type=1))
  Type I Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
  > (an_2 <- anova(m, type=2))
  Type II Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
  > (an_3 <- anova(m, type=3))
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
  > stopifnot(nrow(an) == 0L,
  +           nrow(an_2) == 0L,
  +           nrow(an_3) == 0L)
  > # anova(m, ddf="lme4") # Bug in lme4 it seems
  > if(has_pbkrtest) {
  +   (an_KR <- anova(m, ddf="Kenward-Roger"))
  +   stopifnot(
  +     nrow(an_KR) == 0L
  +   )
  + }
  > 
  > # Example with intercept only:
  > m <- lmer(Reaction ~ (Days | Subject), sleepstudy)
  > # m <- lmer(Reaction ~ 1 + (Days | Subject), sleepstudy) # alternative
  > stopifnot(length(fixef(m)) == 1L,
  +           names(fixef(m)) == "(Intercept)")
  > (an <- anova(m))
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
  > (an_2 <- anova(m, type=2))
  Type II Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
  > (an_3 <- anova(m, type=3))
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
  > (an_lme4 <- anova(m, ddf="lme4"))
  Analysis of Variance Table
       Df Sum Sq Mean Sq F value
  > stopifnot(nrow(an) == 0L,
  +           nrow(an_2) == 0L,
  +           nrow(an_3) == 0L,
  +           nrow(an_lme4) == 0L)
  > if(has_pbkrtest) {
  +   (an_KR <- anova(m, ddf="Kenward-Roger"))
  +   stopifnot(
  +     nrow(an_KR) == 0L
  +   )
  + }
  > 
  > # Example with 1 fixef without intercept:
  > m <- lmer(Reaction ~ Days - 1 + (Days | Subject), sleepstudy)
  Warning message:
  In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 0.00633737 (tol = 0.002, component 1)
  > # m <- lmer(Reaction ~ 0 + Days + (Days | Subject), sleepstudy) # alternative
  > stopifnot(length(fixef(m)) == 1L,
  +           names(fixef(m)) == "Days")
  > (an <- anova(m))
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  94066   94066     1 17.027  143.61 1.009e-09 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an_2 <- anova(m, type=2))
  Type II Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  94066   94066     1 17.027  143.61 1.009e-09 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an_3 <- anova(m, type=3))
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  94066   94066     1 17.027  143.61 1.009e-09 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an_lme4 <- anova(m, ddf="lme4"))
  Analysis of Variance Table
       Df Sum Sq Mean Sq F value
  Days  1  94066   94066  143.61
  > stopifnot(nrow(an) == 1L,
  +           nrow(an_2) == 1L,
  +           nrow(an_3) == 1L,
  +           nrow(an_lme4) == 1L)
  > if(has_pbkrtest) {
  +   (an_KR <- anova(m, ddf="Kenward-Roger"))
  +   stopifnot(
  +     nrow(an_KR) == 1L
  +   )
  + }
  > 
  > res <- all.equal(an[, c("Sum Sq", "Mean Sq", "F value")],
  +                  an_lme4[, c("Sum Sq", "Mean Sq", "F value")], tolerance=TOL)
  > stopifnot(isTRUE(res))
  > stopifnot(isTRUE(all.equal(
  +   c(1, 17), unname(unlist(an[, c("NumDF", "DenDF")])), tolerance=TOL
  + )))
  Error: isTRUE(all.equal(c(1, 17), unname(unlist(an[, c("NumDF", "DenDF")])),  .... is not TRUE
  Execution halted
Running the tests in ‘tests/test_compare_sas.R’ failed.
Complete output:
  > # test_compare_sas.R
  > 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()
  > 
  > #####################################################################
  > 
  > 
  > # Use contrasts to get particular estimates for the summary table:
  > l <- list(Frequency="contr.SAS", Income="contr.SAS")
  > m.carrots <- lmer(Preference ~ sens2*Frequency*Income
  +                   +(1+sens2|Consumer), data=carrots, contrasts=l)
  fixed-effect model matrix is rank deficient so dropping 12 columns / coefficients
  > an.m <- anova(m.carrots)
  Missing cells for: Frequency3:Income1, Frequency5:Income1, Frequency4:Income2, Frequency3:Income4, Frequency4:Income4, Frequency5:Income4, sens2:Frequency3:Income1, sens2:Frequency5:Income1, sens2:Frequency4:Income2, sens2:Frequency3:Income4, sens2:Frequency4:Income4, sens2:Frequency5:Income4.  
  Interpret type III hypotheses with care.
  > 
  > TOL <- 1e-4
  > TOL2 <- 1e-5
  > # with 4 decimals should agree with SAS output
  > # numbers before decimals should agree with SAS output
  > stopifnot(
  +   all.equal(an.m[,"Pr(>F)"],
  +             c(2e-5, 0.15512,  0.06939, 0.08223, 0.52459, 0.03119, 0.48344),
  +             tolerance = TOL),
  +   all.equal(round(an.m$DenDF), c(83, 83, 83, 83, 83, 83, 83))
  + )
  > 
  > sm <- summary(m.carrots)
  > stopifnot(
  +   isTRUE(all.equal(sm$coefficients[,"Pr(>|t|)"],
  +                    c(1e-10, 0.005061, 0.6865554, 0.342613, 0.129157,
  +                      0.088231, 0.846000, 0.354472, 0.526318, 0.020646, 0.010188,
  +                      0.031242, 0.055356, 0.694689, 0.099382, 0.28547,
  +                      0.977774, 0.855653, 0.427737, 0.321086, 0.417465 , 0.204385, 0.784437,
  +                      0.681434, 0.106180, 0.149122, 0.390870, 0.273686), tolerance=TOL,
  +                    check.attributes = FALSE))
  + )
  > 
  > # Takes too long to run:
  > # if(requireNamespace("pbkrtest", quietly = TRUE)) {
  > #   sm.kr <- summary(m.carrots, ddf = "Kenward-Roger")
  > #
  > #   ## coefficients for Sat and KR agree in this example
  > #   #   cbind(sm$coefficients[,"Pr(>|t|)"], sm.kr$coefficients[,"Pr(>|t|)"])
  > #   all.equal(sm$coefficients[,"Pr(>|t|)"], sm.kr$coefficients[,"Pr(>|t|)"],
  > #             tol=TOL)
  > # }
  > 
  > ################################################################################
  > ## checking lsmeans and difflsmeans
  > ## compare with SAS output
  > m <- lmer(Informed.liking ~ Product*Information*Gender
  +           + (1|Product:Consumer) + (1|Consumer) , data=ham)
  Warning message:
  In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 0.00425257 (tol = 0.002, component 1)
  > 
  > 
  > lsm <- lsmeansLT(m, which = "Product")
  > # head(lsm)
  > 
  > stopifnot(
  +   isTRUE(all.equal(lsm[, "Estimate"], c(5.8084, 5.1012, 6.0909, 5.9256),
  +                    tol=TOL, check.attributes = FALSE)),
  +   isTRUE(all.equal(round(lsm[, "t value"], 2), c(24.93, 21.89, 26.14, 25.43), tolerance=TOL,
  +                    check.attributes = FALSE)),
  +   isTRUE(all.equal(lsm[, "lower"], c(5.3499, 4.6428, 5.6324, 5.4672), tolerance=TOL,
  +                    check.attributes = FALSE)),
  +   isTRUE(all.equal(lsm[, "upper"], c(6.2668, 5.5597, 6.5493, 6.3840), tolerance=TOL,
  +                    check.attributes = FALSE))
  + )
  > 
  > ################################################################################
  > # Not actually 'hard-coded' tests versus SAS results...
  > 
  > m.carrots <- lmer(Preference ~ 0 + sens2 + Homesize +
  +                     (1+sens2 | Consumer), data=carrots)
  > summary(m.carrots)
  Linear mixed model fit by REML. t-tests use Satterthwaite's method [
  lmerModLmerTest]
  Formula: Preference ~ 0 + sens2 + Homesize + (1 + sens2 | Consumer)
     Data: carrots
  
  REML criterion at convergence: 3748.9
  
  Scaled residuals: 
      Min      1Q  Median      3Q     Max 
  -3.5321 -0.5571  0.0309  0.6297  2.8552 
  
  Random effects:
   Groups   Name        Variance Std.Dev. Corr
   Consumer (Intercept) 0.195187 0.44180      
            sens2       0.002778 0.05271  0.18
   Residual             1.070440 1.03462      
  Number of obs: 1233, groups:  Consumer, 103
  
  Fixed effects:
             Estimate Std. Error        df t value Pr(>|t|)    
  sens2     7.068e-02  9.545e-03 1.020e+02   7.404 3.89e-11 ***
  Homesize1 4.910e+00  7.056e-02 1.013e+02  69.584  < 2e-16 ***
  Homesize3 4.661e+00  7.850e-02 1.013e+02  59.372  < 2e-16 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  
  Correlation of Fixed Effects:
            sens2 Homsz1
  Homesize1 0.061       
  Homesize3 0.055 0.003 
  > 
  > (an.1 <- anova(m.carrots, type=1))
  Type I Analysis of Variance Table with Satterthwaite's method
           Sum Sq Mean Sq NumDF  DenDF  F value    Pr(>F)    
  sens2      60.5    60.5     1 102.02   56.542 2.208e-11 ***
  Homesize 8926.6  4463.3     2 101.30 4169.582 < 2.2e-16 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an.3 <- anova(m.carrots))
  Type III Analysis of Variance Table with Satterthwaite's method
           Sum Sq Mean Sq NumDF  DenDF  F value    Pr(>F)    
  sens2      58.7    58.7     1 102.02   54.824 3.888e-11 ***
  Homesize 8926.6  4463.3     2 101.30 4169.582 < 2.2e-16 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an.lme4 <- anova(m.carrots, ddf = "lme4")) # difference in SSQ MS and F-values
  Analysis of Variance Table
           Df Sum Sq Mean Sq   F value
  sens2     1    0.0     0.0    0.0121
  Homesize  2 8926.6  4463.3 4169.5821
  > # Is this a problem with lme4?
  > # fm <- lm(Preference ~ 0 + sens2 + Homesize, data=carrots)
  > # anova(fm)
  > # coef(summary(fm))
  > # Here the F value is a little greater than the squared t-value (as expected)
  > 
  > stopifnot(all.equal(an.1[, "F value"], c(56.5394, 4169.87), tolerance = TOL2),
  +           all.equal(an.3[, "F value"], c(54.8206, 4169.87), tolerance = TOL2))
  Error: an.1[, "F value"] and c(56.5394, 4169.87) are not equal:
    Mean relative difference: 6.886767e-05
  Execution halted
Running the tests in ‘tests/test_lmerTest_paper.R’ failed.
Complete output:
  > # test_lmerTest_paper.R
  > 
  > 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
  
  > 
  > # Kenward-Roger only available with pbkrtest and only then validated in R >= 3.3.3
  > # (faulty results for R < 3.3.3 may be due to unstated dependencies in pbkrtest)
  > has_pbkrtest <- requireNamespace("pbkrtest", quietly = TRUE) && getRversion() >= "3.3.3"
  > 
  > # Read in data set
  > load(system.file("testdata","test_paper_objects.RData", package="lmerTest"))
  > 
  > # Evaluate code from paper:
  > ## Section 8.2:
  > tv <- lmer(Sharpnessofmovement ~ TVset * Picture + (1 | Assessor) +
  +              (1 | Assessor:TVset) + (1 | Assessor:Picture), data = TVbo)
  Warning message:
  In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 0.00244572 (tol = 0.002, component 1)
  > (an8.2 <- anova(tv))
  Type III Analysis of Variance Table with Satterthwaite's method
                Sum Sq Mean Sq NumDF   DenDF F value    Pr(>F)    
  TVset          1.764  0.8821     2  13.996  0.2436 0.7870471    
  Picture       51.827 17.2757     3  20.988  4.7713 0.0109055 *  
  TVset:Picture 90.767 15.1279     6 138.013  4.1781 0.0006838 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > 
  > if(has_pbkrtest)
  +   (ankr8.2 <- anova(tv, type=2, ddf="Kenward-Roger"))
  Type II Analysis of Variance Table with Kenward-Roger's method
                Sum Sq Mean Sq NumDF DenDF F value    Pr(>F)    
  TVset          1.764  0.8821     2    14  0.2436 0.7870461    
  Picture       51.827 17.2757     3    21  4.7713 0.0108990 *  
  TVset:Picture 90.767 15.1279     6   138  4.1781 0.0006838 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > 
  > ## Section 8.3:
  > m.carrots <- lmer(Preference ~ sens1 + sens2 + (1 + sens1 + sens2 | Consumer) +
  +                     (1 | Product), data=carrots)
  singular fit
  > (sum8.3 <- coef(summary(m.carrots)))
                Estimate Std. Error        df    t value     Pr(>|t|)
  (Intercept) 4.79911149 0.07528238 20.741774 63.7481336 2.788473e-25
  sens1       0.01082921 0.01502486  9.173809  0.7207524 4.890203e-01
  sens2       0.07064554 0.01727434 10.952266  4.0896230 1.806729e-03
  > 
  > ## Section 8.4:
  > tv <- lmer(Sharpnessofmovement ~ TVset * Picture +
  +              (1 | Assessor:TVset) + (1 | Assessor:Picture) +
  +              (1 | Assessor:Picture:TVset) + (1 | Repeat) + (1 | Repeat:Picture) +
  +              (1 | Repeat:TVset) + (1 | Repeat:TVset:Picture) + (1 | Assessor),
  +            data = TVbo)
  singular fit
  > st <- step(tv)
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  singular fit
  Warning messages:
  1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 0.00244572 (tol = 0.002, component 1)
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 0.00244572 (tol = 0.002, component 1)
  > names(st)
  [1] "random" "fixed" 
  > (elim_tab_random8.4 <- st$random)
  Backward reduced random-effect table:
  
                               Eliminated npar  logLik    AIC     LRT Df
  <none>                                    21 -412.70 867.41           
  (1 | Assessor:Picture:TVset)          1   20 -412.70 865.41  0.0000  1
  (1 | Repeat)                          2   19 -412.70 863.41  0.0000  1
  (1 | Repeat:Picture)                  3   18 -412.70 861.41  0.0000  1
  (1 | Repeat:TVset:Picture)            4   17 -412.70 859.41  0.0000  1
  (1 | Repeat:TVset)                    5   16 -412.70 857.41  0.0000  1
  (1 | Assessor:TVset)                  0   15 -414.10 858.20  2.7891  1
  (1 | Assessor:Picture)                0   15 -418.88 867.76 12.3473  1
  (1 | Assessor)                        0   15 -416.44 862.88  7.4698  1
                               Pr(>Chisq)    
  <none>                                     
  (1 | Assessor:Picture:TVset)  1.0000000    
  (1 | Repeat)                  1.0000000    
  (1 | Repeat:Picture)          1.0000000    
  (1 | Repeat:TVset:Picture)    0.9996577    
  (1 | Repeat:TVset)            0.9984636    
  (1 | Assessor:TVset)          0.0949064 .  
  (1 | Assessor:Picture)        0.0004416 ***
  (1 | Assessor)                0.0062742 ** 
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (elim_tab_fixed8.4 <- st$fixed)
  Backward reduced fixed-effect table:
  Degrees of freedom method: Satterthwaite 
  
                Eliminated Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  TVset:Picture          0 90.767  15.128     6 138.01  4.1781 0.0006838 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an8.4 <- anova(get_model(st)))
  Type III Analysis of Variance Table with Satterthwaite's method
                Sum Sq Mean Sq NumDF   DenDF F value    Pr(>F)    
  TVset          1.764  0.8821     2  13.996  0.2436 0.7870471    
  Picture       51.827 17.2757     3  20.988  4.7713 0.0109055 *  
  TVset:Picture 90.767 15.1279     6 138.013  4.1781 0.0006838 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > 
  > ## Section 8.5:
  > # L <- matrix(0, ncol = 12, nrow = 6)
  > # L[1, 7] <- L[2, 8] <- L[3, 9] <- L[4, 10] <- L[5, 11] <- L[6, 12] <- 1
  > L <- cbind(array(0, dim=c(6, 6)), diag(6))
  > (con1_8.5 <- calcSatterth(tv, L))
  $denom
  [1] 137.9995
  
  $Fstat
           [,1]
  [1,] 4.177701
  
  $pvalue
               [,1]
  [1,] 0.0006844127
  
  $ndf
  [1] 6
  
  > (con2_8.5 <- contest(tv, L))
      Sum Sq  Mean Sq NumDF    DenDF  F value       Pr(>F)
  1 90.76718 15.12786     6 137.9995 4.177701 0.0006844127
  > 
  > ## Section C:
  > # m.carrots <- lmer(Preference ~ sens1 + sens2 + (1 + sens1 + sens2 | Consumer) +
  > #                     (1 | product), data = carrots)
  > # step(m.carrots, reduce.fixed = FALSE)
  > (ran_C <- ranova(m.carrots))
  singular fit
  ANOVA-like table for random-effects: Single term deletions
  
  Model:
  Preference ~ sens1 + sens2 + (1 + sens1 + sens2 | Consumer) + 
      (1 | Product)
                                          npar  logLik    AIC     LRT Df
  <none>                                    11 -1869.7 3761.5           
  sens1 in (1 + sens1 + sens2 | Consumer)    8 -1870.7 3757.3  1.8274  3
  sens2 in (1 + sens1 + sens2 | Consumer)    8 -1874.5 3765.0  9.5464  3
  (1 | Product)                             10 -1877.9 3775.8 16.3072  1
                                          Pr(>Chisq)    
  <none>                                                
  sens1 in (1 + sens1 + sens2 | Consumer)    0.60899    
  sens2 in (1 + sens1 + sens2 | Consumer)    0.02284 *  
  (1 | Product)                            5.386e-05 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  Warning message:
  In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 0.00562304 (tol = 0.002, component 1)
  > 
  > # Compare to validated outputs:
  > TOL <- 1e-4
  > stopifnot(
  +   isTRUE(all.equal(an8.2_save, an8.2, check.attributes = FALSE, tolerance=TOL)),
  +   isTRUE(all.equal(sum8.3_save, sum8.3, check.attributes = FALSE, tolerance=TOL)),
  +   isTRUE(all.equal(elim_tab_random8.4_save, elim_tab_random8.4,
  +                    check.attributes = FALSE, tolerance=TOL)),
  +   isTRUE(all.equal(elim_tab_fixed8.4_save, elim_tab_fixed8.4,
  +                    check.attributes = FALSE, tolerance=TOL)),
  +   isTRUE(all.equal(an8.4_save, an8.4, check.attributes = FALSE, tolerance=TOL)),
  +   isTRUE(all.equal(con1_8.5_save, con1_8.5, check.attributes = FALSE, tolerance=TOL)),
  +   isTRUE(all.equal(con2_8.5_save, con2_8.5, check.attributes = FALSE, tolerance=TOL))
  + )
  Error: isTRUE(all.equal(an8.2_save, an8.2, check.attributes = FALSE,  .... is not TRUE
  Execution halted
Running the tests in ‘tests/test_zerovar.R’ failed.
Complete output:
  > # test_zerovar.R
  > 
  > 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
  
  > data("sleepstudy", package="lme4")
  > 
  > # Baseline fit:
  > m0 <- lmer(Reaction ~ Days +  (Days | Subject), sleepstudy)
  > m0
  Linear mixed model fit by REML ['lmerModLmerTest']
  Formula: Reaction ~ Days + (Days | Subject)
     Data: sleepstudy
  REML criterion at convergence: 1743.628
  Random effects:
   Groups   Name        Std.Dev. Corr
   Subject  (Intercept) 24.737       
            Days         5.923   0.07
   Residual             25.592       
  Number of obs: 180, groups:  Subject, 18
  Fixed Effects:
  (Intercept)         Days  
       251.41        10.47  
  > (an0 <- anova(m0))
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30024   30024     1 16.995  45.843 3.273e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > 
  > # Make a fit with a zero variance estimate:
  > n <- nrow(sleepstudy)
  > g <- factor(rep(1:2, c(n - 10, 10)))
  > m <- lmer(Reaction ~ Days +  (Days | Subject) + (1|g), sleepstudy)
  singular fit
  > m
  Linear mixed model fit by REML ['lmerModLmerTest']
  Formula: Reaction ~ Days + (Days | Subject) + (1 | g)
     Data: sleepstudy
  REML criterion at convergence: 1743.628
  Random effects:
   Groups   Name        Std.Dev.  Corr
   Subject  (Intercept) 24.737913     
            Days         5.922713 0.07
   g        (Intercept)  0.002013     
   Residual             25.591837     
  Number of obs: 180, groups:  Subject, 18; g, 2
  Fixed Effects:
  (Intercept)         Days  
       251.41        10.47  
  convergence code 0; 1 optimizer warnings; 0 lme4 warnings 
  > (an <- anova(m))
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
  Days  30026   30026     1 16.996  45.846 3.271e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > 
  > # check that fit has a zero variance
  > vc <- as.data.frame(VarCorr(m))
  > stopifnot(isTRUE(
  +   all.equal(0, vc[vc$grp == "g", "sdcor"], tolerance=1e-4)
  + ))
  Error: isTRUE(all.equal(0, vc[vc$grp == "g", "sdcor"], tolerance = 1e-04)) is not TRUE
  Execution halted