Running 'test_a_utils.R' [4s/4s]
  Running 'test_anova.R' [10s/12s]
  Running 'test_compare_sas.R' [6s/7s]
  Running 'test_contest1D.R' [6s/7s]
  Running 'test_contestMD.R' [7s/8s]
  Running 'test_drop1.R' [6s/7s]
  Running 'test_legacy.R' [7s/8s]
  Running 'test_lmer.R' [5s/5s]
  Running 'test_lmerTest_paper.R' [26s/28s]
  Running 'test_ls_means.R' [6s/7s]
  Running 'test_ranova_step.R' [6s/6s]
  Running 'test_summary.R' [7s/8s]
  Running 'test_zerovar.R' [4s/5s]
  Running 'zlmerTest_zeroDenom.R' [4s/5s]
Running the tests in 'tests/test_lmer.R' failed.
Complete output:
  > # test_lmer.R
  > 
  > 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)
  > anova(fm)
  Type III Analysis of Variance Table with Satterthwaite's method
       Sum Sq Mean Sq NumDF DenDF F value    Pr(>F)    
  Days  30031   30031     1    17  45.853 3.264e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > summary(fm)
  Linear mixed model fit by REML. t-tests use Satterthwaite's method [
  lmerModLmerTest]
  Formula: form
     Data: data
  
  REML criterion at convergence: 1743.6
  
  Scaled residuals: 
      Min      1Q  Median      3Q     Max 
  -3.9536 -0.4634  0.0231  0.4634  5.1793 
  
  Random effects:
   Groups   Name        Variance Std.Dev. Corr
   Subject  (Intercept) 612.10   24.741       
            Days         35.07    5.922   0.07
   Residual             654.94   25.592       
  Number of obs: 180, groups:  Subject, 18
  
  Fixed effects:
              Estimate Std. Error      df t value Pr(>|t|)    
  (Intercept)  251.405      6.825  17.000  36.838  < 2e-16 ***
  Days          10.467      1.546  17.000   6.771 3.26e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  
  Correlation of Fixed Effects:
       (Intr)
  Days -0.138
  > 
  > # cf. GitHub issue #2:
  > test <- function() {
  +   tmp <- sleepstudy
  +   m <- lmerTest::lmer(Reaction ~ Days + (Days | Subject), data = tmp)
  +   summary(m)
  + }
  > test()
  Linear mixed model fit by REML. t-tests use Satterthwaite's method [
  lmerModLmerTest]
  Formula: Reaction ~ Days + (Days | Subject)
     Data: tmp
  
  REML criterion at convergence: 1743.6
  
  Scaled residuals: 
      Min      1Q  Median      3Q     Max 
  -3.9536 -0.4634  0.0231  0.4634  5.1793 
  
  Random effects:
   Groups   Name        Variance Std.Dev. Corr
   Subject  (Intercept) 612.10   24.741       
            Days         35.07    5.922   0.07
   Residual             654.94   25.592       
  Number of obs: 180, groups:  Subject, 18
  
  Fixed effects:
              Estimate Std. Error      df t value Pr(>|t|)    
  (Intercept)  251.405      6.825  17.000  36.838  < 2e-16 ***
  Days          10.467      1.546  17.000   6.771 3.26e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  
  Correlation of Fixed Effects:
       (Intr)
  Days -0.138
  > test <- function() {
  +   tmp <- sleepstudy
  +   m <- lme4::lmer(Reaction ~ Days + (Days | Subject), data = tmp)
  +   if(requireNamespace("lmerTest", quietly = TRUE)) {
  +     summary(lmerTest::as_lmerModLmerTest(m))
  +   }
  + }
  > test()
  Linear mixed model fit by REML. t-tests use Satterthwaite's method [
  lmerModLmerTest]
  Formula: Reaction ~ Days + (Days | Subject)
     Data: tmp
  
  REML criterion at convergence: 1743.6
  
  Scaled residuals: 
      Min      1Q  Median      3Q     Max 
  -3.9536 -0.4634  0.0231  0.4634  5.1793 
  
  Random effects:
   Groups   Name        Variance Std.Dev. Corr
   Subject  (Intercept) 612.10   24.741       
            Days         35.07    5.922   0.07
   Residual             654.94   25.592       
  Number of obs: 180, groups:  Subject, 18
  
  Fixed effects:
              Estimate Std. Error      df t value Pr(>|t|)    
  (Intercept)  251.405      6.825  17.000  36.838  < 2e-16 ***
  Days          10.467      1.546  17.000   6.771 3.26e-06 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  
  Correlation of Fixed Effects:
       (Intr)
  Days -0.138
  > 
  > 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
  > 
  > #####################################################################
  > # Check that lme4::lmer and lmerTest::lmer have the same arguments
  > lmer_args <- formals(lme4::lmer)
  > lmerTest_args <- formals(lmerTest::lmer)
  > stopifnot(
  +   all.equal(names(lmer_args), names(lmerTest_args)),
  +   all.equal(lmer_args, lmerTest_args)
  + )
  Error: names(lmer_args) and names(lmerTest_args) are not equal:
    Lengths (12, 13) differ (string compare on first 12)
  Execution halted
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 deviance  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 | Subject) - 1
                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 deviance  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
  > stopifnot(
  +   all.equal(an1[2, "LRT"], an2[2, "Chisq"], tolerance=TOL),
  +   all.equal(an1[2, "Df"], an2[2, "Chi Df"], tolerance=TOL),
  +   all.equal(an1[1:2, "logLik"], an2[2:1, "logLik"], tolerance=TOL)
  + )
  Error: an1[2, "Df"] and an2[2, "Chi Df"] are not equal:
    Modes: numeric, NULL
    Lengths: 1, 0
    target is numeric, current is NULL
  Execution halted