Running ‘test_a_utils.R’
  Running ‘test_anova.R’ [8s/21s]
  Running ‘test_compare_sas.R’ [6s/16s]
  Running ‘test_contest1D.R’ [8s/20s]
  Running ‘test_contestMD.R’ [9s/24s]
  Running ‘test_contrast_utils.R’ [6s/16s]
  Running ‘test_drop1.R’ [8s/21s]
  Running ‘test_legacy.R’ [7s/20s]
  Running ‘test_lmer.R’ [9s/26s]
  Running ‘test_lmerTest_paper.R’ [35s/96s]
  Running ‘test_ls_means.R’ [7s/18s]
  Running ‘test_ranova_step.R’ [8s/23s]
  Running ‘test_summary.R’ [8s/24s]
  Running ‘test_zerovar.R’ [6s/17s]
  Running ‘zlmerTest_zeroDenom.R’ [6s/17s]
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)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    unable to evaluate scaled gradient
  3: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge: degenerate  Hessian with 1 negative eigenvalues
  4: Model failed to converge with 1 negative eigenvalue: -2.6e+01 
  > 
  > ####### 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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1    17   3.284 0.08766 .
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an1 <- anova(m, ddf="lme4"))
  Analysis of Variance Table
       npar Sum Sq Mean Sq F value
  Days    1 1948.5  1948.5   3.284
  > (an2 <- anova(m, ddf="lme4", type=3)) # 'type' is ignored with ddf="lme4"
  Analysis of Variance Table
       npar Sum Sq Mean Sq F value
  Days    1 1948.5  1948.5   3.284
  > 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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  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)
     npar    AIC    BIC  logLik deviance  Chisq 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)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    unable to evaluate scaled gradient
  3: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge: degenerate  Hessian with 1 negative eigenvalues
  4: Model failed to converge with 1 negative eigenvalue: -2.6e+01 
  > (an <- anova(m, m2, refit=FALSE))
  Data: sleepstudy
  Models:
  m: Reaction ~ Days + (Days | Subject)
  m2: Reaction ~ Days + I(Days^2) + (Days | Subject)
     npar AIC BIC logLik deviance Chisq Df Pr(>Chisq)
  m     6 Inf Inf   -Inf      Inf                    
  m2    7 Inf Inf   -Inf      Inf   NaN  1        NaN
  > 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)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 0.719345 (tol = 0.002, component 1)
  > (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.04    2.02     2 248.07  0.0947 0.9097    
  temp        1966.71 1966.71     1 219.41 92.2233 <2e-16 ***
  recipe:temp    1.74    0.87     2 219.41  0.0408 0.9600    
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  > (an_lme4 <- anova(m, ddf="lme4"))
  Analysis of Variance Table
              npar  Sum Sq Mean Sq F value
  recipe         2   11.77    5.88  0.2759
  temp           1 1966.71 1966.71 92.2233
  recipe:temp    2    1.74    0.87  0.0408
  > 
  > 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))
  Error: c(254.0157612, 222, 222) and an$DenDF are not equal:
    Mean relative difference: 0.01595027
  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
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    unable to evaluate scaled gradient
  3: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge: degenerate  Hessian with 2 negative eigenvalues
  4: Model failed to converge with 2 negative eigenvalues: -3.7e+01 -1.6e+02 
  > 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))
  + )
  Error: an.m[, "Pr(>F)"] and c(2e-05, 0.15512, 0.06939, 0.08223, 0.52459, 0.03119, 0.48344) are not equal:
    Mean relative difference: 0.7703328
  Execution halted
Running the tests in ‘tests/test_legacy.R’ failed.
Complete output:
  > # test_legacy.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
  
  > TOL <- 1e-4
  > #####################################################################
  > 
  > # Read in data set
  > load(system.file("testdata", "legacy_fits.RData", package="lmerTest"))
  > # Generated with the following code using lmerTest version 2.0-37.9002
  > #
  > # library("lmerTest")
  > # packageVersion("lmerTest")
  > # fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
  > # (an1 <- anova(fm1))
  > # (sfm1 <- summary(fm1))
  > #
  > # fm2 <- lmer(Informed.liking ~ Product + Information + Gender +
  > #               (1|Product:Consumer) , data=ham)
  > # (an2 <- anova(fm2))
  > # (sfm2 <- summary(fm2))
  > #
  > # save(fm1, an1, sfm1, fm2, an2, sfm2,
  > #      file="~/GitHub/lmerTestR/package/inst/testdata/legacy_fits.RData")
  > 
  > 
  > #######################################
  > ### Check that arguments for merModLmerTest and lmerModLmerTest methods match up:
  > 
  > stopifnot(
  +   isTRUE(all.equal(formals(lmerTest:::anova.merModLmerTest),
  +                    formals(lmerTest:::anova.lmerModLmerTest))),
  +   isTRUE(all.equal(formals(lmerTest:::summary.merModLmerTest),
  +                    formals(lmerTest:::summary.lmerModLmerTest))),
  +   isTRUE(all.equal(formals(lmerTest:::drop1.merModLmerTest),
  +                    formals(lmerTest:::drop1.lmerModLmerTest))),
  +   isTRUE(all.equal(formals(lmerTest:::step.merModLmerTest),
  +                    formals(lmerTest:::step.lmerModLmerTest))),
  +   isTRUE(all.equal(formals(lmerTest:::ls_means.merModLmerTest),
  +                    formals(lmerTest:::ls_means.lmerModLmerTest))),
  +   isTRUE(all.equal(formals(lmerTest:::difflsmeans.merModLmerTest),
  +                    formals(lmerTest:::difflsmeans.lmerModLmerTest))))
  > 
  > 
  > #######################################
  > ## Tests for fm1:
  > 
  > an1new <- anova(fm1)
  > sfm1new <- summary(fm1)
  > 
  > stopifnot(
  +   isTRUE(all.equal(an1new, an1, check.attributes=FALSE, tol=TOL)),
  +   isTRUE(all.equal(coef(sfm1new), coef(sfm1), tol=TOL))
  + )
  > 
  > contest(fm1, c(0, 1))
      Sum Sq  Mean Sq NumDF DenDF F value      Pr(>F)
  1 30031.01 30031.01     1    17  45.853 3.26379e-06
  > contest(fm1, c(0, 1), joint=FALSE)
    Estimate Std. Error df  t value    lower    upper    Pr(>|t|)
  1 10.46729   1.545789 17 6.771485 7.205956 13.72862 3.26379e-06
  > drop1(fm1)
  Single term deletions using Satterthwaite's method:
  
  Model:
  Reaction ~ Days + (Days | Subject)
       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
  > ranova(fm1)
  ANOVA-like table for random-effects: Single term deletions
  
  Model:
  Reaction ~ Days + (Days | Subject)
                           npar logLik  AIC LRT Df Pr(>Chisq)    
  <none>                      6   -872 1756                      
  Days in (Days | Subject)    4   -Inf  Inf Inf  2  < 2.2e-16 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 1.97927 (tol = 0.002, component 1)
  > step(fm1)
  Backward reduced random-effect table:
  
                           Eliminated npar logLik  AIC LRT Df Pr(>Chisq)    
  <none>                                 6   -872 1756                      
  Days in (Days | Subject)          0    4   -Inf  Inf Inf  2  < 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  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)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 1.97927 (tol = 0.002, component 1)
  > 
  > fm1new <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy,
  +                control=lmerControl(optimizer="bobyqa"))
  > stopifnot(
  +   isTRUE(all.equal(drop1(fm1), drop1(fm1new), tol=TOL)),
  +   isTRUE(all.equal(ranova(fm1), ranova(fm1new), tol=TOL)),
  +   isTRUE(all.equal(contest(fm1, c(0, 1)), contest(fm1new, c(0, 1)), tol=TOL)),
  +   isTRUE(all.equal(contest(fm1, c(0, 1), joint=FALSE),
  +                    contest(fm1new, c(0, 1), joint=FALSE), tol=TOL))
  + )
  Error: isTRUE(all.equal(ranova(fm1), ranova(fm1new), tol = TOL)) is not TRUE
  In addition: Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 1.97927 (tol = 0.002, component 1)
  Execution halted
Running the tests in ‘tests/test_ls_means.R’ failed.
Complete output:
  > # test_lsmeans.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
  
  > 
  > TOL <- 1e-4
  > # 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"
  > 
  > ########### Basic model structures:
  > 
  > # Factor * covariate:
  > data("cake", package="lme4")
  > model <- lmer(angle ~ recipe * temp + (1|recipe:replicate), cake)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 0.719345 (tol = 0.002, component 1)
  > (lsm <- ls_means(model))
  Least Squares Means table:
  
          Estimate Std. Error   df t value   lower   upper  Pr(>|t|)    
  recipeA  33.1222     1.6493 48.6  20.082 29.8071 36.4374 < 2.2e-16 ***
  recipeB  31.6444     1.6493 48.6  19.186 28.3293 34.9596 < 2.2e-16 ***
  recipeC  31.6000     1.6493 48.6  19.159 28.2849 34.9151 < 2.2e-16 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  
    Confidence level: 95%
    Degrees of freedom method: Satterthwaite 
  > stopifnot(
  +   nrow(lsm) == 3L,
  +   ncol(lsm) == 7L,
  +   # Balanced, so LS-means equal raw means:
  +   isTRUE(all.equal(c(with(cake, tapply(angle, recipe, mean))), lsm[, "Estimate"],
  +                    check.attributes=FALSE, tolerance=TOL))
  + )
  > 
  > # Pairwise differences of LS-means:
  > plsm <- ls_means(model, pairwise = TRUE)
  > plsm2 <- difflsmeans(model)
  > C <- as.matrix(lmerTest:::get_pairs(rownames(lsm)))
  > stopifnot(
  +   isTRUE(all.equal(plsm, plsm2, tolerance=TOL)),
  +   isTRUE(all.equal(plsm[, "Estimate"], c(lsm[, "Estimate"] %*% C),
  +                    check.attributes=FALSE, tolerance=TOL))
  + )
  > 
  > # Contrasts vectors:
  > show_tests(lsm)
  $recipe
          (Intercept) recipeB recipeC temp recipeB:temp recipeC:temp
  recipeA           1       0       0  200            0            0
  recipeB           1       1       0  200          200            0
  recipeC           1       0       1  200            0          200
  
  > show_tests(plsm)
  $recipe
                    (Intercept) recipeB recipeC temp recipeB:temp recipeC:temp
  recipeA - recipeB           0      -1       0    0         -200            0
  recipeA - recipeC           0       0      -1    0            0         -200
  recipeB - recipeC           0       1      -1    0          200         -200
  
  > 
  > # Factor * Ordered:
  > model <- lmer(angle ~ recipe * temperature + (1|recipe:replicate), cake)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 0.828782 (tol = 0.002, component 1)
  > (lsm2 <- ls_means(model))
  Least Squares Means table:
  
                         Estimate Std. Error   df t value   lower   upper
  recipeA                 33.1222     1.6367 49.7  20.237 29.8342 36.4102
  recipeB                 31.6444     1.6367 49.7  19.334 28.3564 34.9325
  recipeC                 31.6000     1.6367 49.7  19.307 28.3120 34.8880
  temperature175          27.9778     1.1322 96.9  24.711 25.7307 30.2249
  temperature185          29.9556     1.1322 96.9  26.458 27.7085 32.2027
  temperature195          31.4222     1.1322 96.9  27.753 29.1751 33.6693
  temperature205          32.1778     1.1322 96.9  28.421 29.9307 34.4249
  temperature215          35.8444     1.1322 96.9  31.659 33.5973 38.0915
  temperature225          35.3556     1.1322 96.9  31.228 33.1085 37.6027
  recipeA:temperature175  29.1333     1.9610 96.9  14.856 25.2412 33.0254
  recipeB:temperature175  26.8667     1.9610 96.9  13.700 22.9746 30.7588
  recipeC:temperature175  27.9333     1.9610 96.9  14.244 24.0412 31.8254
  recipeA:temperature185  31.5333     1.9610 96.9  16.080 27.6412 35.4254
  recipeB:temperature185  29.4000     1.9610 96.9  14.992 25.5079 33.2921
  recipeC:temperature185  28.9333     1.9610 96.9  14.754 25.0412 32.8254
  recipeA:temperature195  30.8000     1.9610 96.9  15.706 26.9079 34.6921
  recipeB:temperature195  31.7333     1.9610 96.9  16.182 27.8412 35.6254
  recipeC:temperature195  31.7333     1.9610 96.9  16.182 27.8412 35.6254
  recipeA:temperature205  33.5333     1.9610 96.9  17.100 29.6412 37.4254
  recipeB:temperature205  32.1333     1.9610 96.9  16.386 28.2412 36.0254
  recipeC:temperature205  30.8667     1.9610 96.9  15.740 26.9746 34.7588
  recipeA:temperature215  38.6667     1.9610 96.9  19.718 34.7746 42.5588
  recipeB:temperature215  34.4667     1.9610 96.9  17.576 30.5746 38.3588
  recipeC:temperature215  34.4000     1.9610 96.9  17.542 30.5079 38.2921
  recipeA:temperature225  35.0667     1.9610 96.9  17.882 31.1746 38.9588
  recipeB:temperature225  35.2667     1.9610 96.9  17.984 31.3746 39.1588
  recipeC:temperature225  35.7333     1.9610 96.9  18.222 31.8412 39.6254
                          Pr(>|t|)    
  recipeA                < 2.2e-16 ***
  recipeB                < 2.2e-16 ***
  recipeC                < 2.2e-16 ***
  temperature175         < 2.2e-16 ***
  temperature185         < 2.2e-16 ***
  temperature195         < 2.2e-16 ***
  temperature205         < 2.2e-16 ***
  temperature215         < 2.2e-16 ***
  temperature225         < 2.2e-16 ***
  recipeA:temperature175 < 2.2e-16 ***
  recipeB:temperature175 < 2.2e-16 ***
  recipeC:temperature175 < 2.2e-16 ***
  recipeA:temperature185 < 2.2e-16 ***
  recipeB:temperature185 < 2.2e-16 ***
  recipeC:temperature185 < 2.2e-16 ***
  recipeA:temperature195 < 2.2e-16 ***
  recipeB:temperature195 < 2.2e-16 ***
  recipeC:temperature195 < 2.2e-16 ***
  recipeA:temperature205 < 2.2e-16 ***
  recipeB:temperature205 < 2.2e-16 ***
  recipeC:temperature205 < 2.2e-16 ***
  recipeA:temperature215 < 2.2e-16 ***
  recipeB:temperature215 < 2.2e-16 ***
  recipeC:temperature215 < 2.2e-16 ***
  recipeA:temperature225 < 2.2e-16 ***
  recipeB:temperature225 < 2.2e-16 ***
  recipeC:temperature225 < 2.2e-16 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  
    Confidence level: 95%
    Degrees of freedom method: Satterthwaite 
  > stopifnot(
  +   nrow(lsm2) == 3 + 6 + 3*6,
  +   ncol(lsm) == 7L,
  +   # Balanced, so LS-means equal raw means:
  +   isTRUE(all.equal(lsm[1:3, ], lsm2[1:3, ],
  +                    check.attributes=FALSE, tolerance=TOL))
  + )
  Error: isTRUE(all.equal(lsm[1:3, ], lsm2[1:3, ], check.attributes = FALSE,  .... is not TRUE
  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)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    unable to evaluate scaled gradient
  3: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge: degenerate  Hessian with 1 negative eigenvalues
  4: Model failed to converge with 1 negative eigenvalue: -2.6e+01 
  > 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   -Inf Inf                  
  Days in (Days | Subject)    4   -Inf Inf NaN  2        NaN
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 1.97927 (tol = 0.002, component 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   -Inf Inf                  
  Days in (Days | Subject)    4   -Inf Inf NaN  2        NaN
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 1.97927 (tol = 0.002, component 1)
  > lmerTest::step(fm)
  Backward reduced random-effect table:
  
                           Eliminated npar logLik AIC LRT Df Pr(>Chisq)
  <none>                                 6   -Inf Inf                  
  Days in (Days | Subject)          0    4   -Inf Inf NaN  2        NaN
  
  Backward reduced fixed-effect table:
  Degrees of freedom method: Satterthwaite 
  
       Eliminated Sum Sq Mean Sq NumDF  DenDF F value  Pr(>F)  
  Days          1 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  
  Model found:
  Reaction ~ (Days | Subject)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 1.97927 (tol = 0.002, component 1)
  3: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  4: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    unable to evaluate scaled gradient
  5: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge: degenerate  Hessian with 1 negative eigenvalues
  6: Model failed to converge with 1 negative eigenvalue: -9.2e+00 
  > 
  > 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)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    unable to evaluate scaled gradient
  3: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge: degenerate  Hessian with 1 negative eigenvalues
  4: Model failed to converge with 1 negative eigenvalue: -2.6e+01 
  > (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   -Inf Inf                  
  Days in (Days | Subject)    4   -Inf Inf NaN  2        NaN
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 1.97927 (tol = 0.002, component 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   -Inf Inf                  
  Days in (Days | Subject)    4   -Inf Inf NaN  2        NaN
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 1.97927 (tol = 0.002, component 1)
  > step(fm1)
  Backward reduced random-effect table:
  
                           Eliminated npar logLik AIC LRT Df Pr(>Chisq)
  <none>                                 6   -Inf Inf                  
  Days in (Days | Subject)          0    4   -Inf Inf NaN  2        NaN
  
  Backward reduced fixed-effect table:
  Degrees of freedom method: Satterthwaite 
  
       Eliminated Sum Sq Mean Sq NumDF  DenDF F value  Pr(>F)  
  Days          1 1948.5  1948.5     1 115.69   3.284 0.07255 .
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  
  Model found:
  Reaction ~ (Days | Subject)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 1.97927 (tol = 0.002, component 1)
  3: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  4: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    unable to evaluate scaled gradient
  5: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge: degenerate  Hessian with 1 negative eigenvalues
  6: Model failed to converge with 1 negative eigenvalue: -9.2e+00 
  > stopifnot(
  +   nrow(an) == 2L,
  +   an[2L, "Df"] == 2L
  + )
  > 
  > # This test can also be achieved with anova():
  > fm2 <- lmer(Reaction ~ Days + (1|Subject), sleepstudy)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 1.97927 (tol = 0.002, component 1)
  > (stp <- step(fm2))
  Backward reduced random-effect table:
  
                Eliminated npar logLik  AIC  LRT Df Pr(>Chisq)
  <none>                      4   -Inf  Inf                   
  (1 | Subject)          1    3   -947 1900 -Inf  1          1
  
  Backward reduced fixed-effect table:
       Eliminated Df Sum of Sq    RSS    AIC F value    Pr(>F)    
  Days          0  1    162703 567954 1452.2  71.464 9.894e-15 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  
  Model found:
  Reaction ~ Days
  > get_model(stp)
  
  Call:
  lm(formula = Reaction ~ Days, data = sleepstudy)
  
  Coefficients:
  (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 Inf Inf   -Inf      Inf                    
  fm1    6 Inf Inf   -Inf      Inf   NaN  2        NaN
  > 
  > 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   -Inf  Inf                   
  (Days | Subject)    3   -947 1900 -Inf  3          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)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 14.9723 (tol = 0.002, component 1)
  > step(fm)
  Backward reduced random-effect table:
  
                Eliminated npar logLik  AIC  LRT Df Pr(>Chisq)
  <none>                      2   -Inf  Inf                   
  (1 | Subject)          1    1  -1284 2571 -Inf  1          1
  
  Backward reduced fixed-effect table:
       Eliminated Df Sum of Sq RSS AIC F value Pr(>F)
  
  Model found:
  Reaction ~ 1 - 1
  > 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   -Inf  Inf                   
  (1 | Subject)    1  -1284 2571 -Inf  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)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 1.84934 (tol = 0.002, component 1)
  > step(fm1)
  Backward reduced random-effect table:
  
                Eliminated npar logLik  AIC  LRT Df Pr(>Chisq)
  <none>                      4   -Inf  Inf                   
  (1 | Subject)          1    3   -950 1906 -Inf  1          1
  
  Backward reduced fixed-effect table:
       Eliminated Df Sum of Sq    RSS    AIC F value    Pr(>F)    
  Days          0  1    162703 567954 1452.2  71.464 9.894e-15 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  
  Model found:
  Reaction ~ Days
  > 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   -Inf  Inf                   
  (1 | Subject)    3   -950 1906 -Inf  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 1916   -950     1900                    
  fm1    4  Inf  Inf   -Inf      Inf     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)
  + )
  Error: an1[2, "LRT"] and an2[2, "Chisq"] are not equal:
    Mean absolute difference: Inf
  Execution halted
Running the tests in ‘tests/zlmerTest_zeroDenom.R’ failed.
Complete output:
  > 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
  
  > 
  > # Read in data set
  > load(system.file("testdata","potdata.RData", package="lmerTest"))
  > 
  > # Mixed model
  > lmerout <- lmer(biomass ~ CO2*nutrients + (1|chamber),data=potdata)
  Warning messages:
  1: In optwrap(optimizer, devfun, getStart(start, rho$pp), lower = rho$lower,  :
    convergence code -2 from nloptwrap: NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).
  2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
    Model failed to converge with max|grad| = 0.788311 (tol = 0.002, component 1)
  > summary(lmerout)
  Linear mixed model fit by REML. t-tests use Satterthwaite's method [
  lmerModLmerTest]
  Formula: biomass ~ CO2 * nutrients + (1 | chamber)
     Data: potdata
  
  REML criterion at convergence: Inf
  
  Scaled residuals: 
      Min      1Q  Median      3Q     Max 
  -1.4961 -0.5349  0.0000  0.5349  1.4961 
  
  Random effects:
   Groups   Name        Variance Std.Dev.
   chamber  (Intercept) 0.07571  0.2752  
   Residual             1.71728  1.3105  
  Number of obs: 24, groups:  chamber, 4
  
  Fixed effects:
                    Estimate Std. Error      df t value Pr(>|t|)    
  (Intercept)        12.8500     0.9468 11.8625  13.572 1.39e-08 ***
  CO2675              2.0000     1.3390 11.8625   1.494 0.161390    
  nutrients2          7.3500     1.3105  7.3492   5.609 0.000682 ***
  nutrients3         10.4500     1.3105  7.3492   7.974 7.15e-05 ***
  nutrients4         18.6500     1.3105  7.3492  14.232 1.29e-06 ***
  nutrients5         25.0500     1.3105  7.3492  19.116 1.55e-07 ***
  nutrients6         29.0000     1.3105  7.3492  22.130 5.39e-08 ***
  CO2675:nutrients2  -0.5000     1.8533  7.3492  -0.270 0.794737    
  CO2675:nutrients3   1.9000     1.8533  7.3492   1.025 0.337816    
  CO2675:nutrients4   3.4500     1.8533  7.3492   1.862 0.102962    
  CO2675:nutrients5   5.9000     1.8533  7.3492   3.184 0.014448 *  
  CO2675:nutrients6   5.2500     1.8533  7.3492   2.833 0.024051 *  
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  
  Correlation of Fixed Effects:
              (Intr) CO2675 ntrnt2 ntrnt3 ntrnt4 ntrnt5 ntrnt6 CO2675:2 CO2675:3
  CO2675      -0.707                                                            
  nutrients2  -0.692  0.489                                                     
  nutrients3  -0.692  0.489  0.500                                              
  nutrients4  -0.692  0.489  0.500  0.500                                       
  nutrients5  -0.692  0.489  0.500  0.500  0.500                                
  nutrients6  -0.692  0.489  0.500  0.500  0.500  0.500                         
  CO2675:ntr2  0.489 -0.692 -0.707 -0.354 -0.354 -0.354 -0.354                  
  CO2675:ntr3  0.489 -0.692 -0.354 -0.707 -0.354 -0.354 -0.354  0.500           
  CO2675:ntr4  0.489 -0.692 -0.354 -0.354 -0.707 -0.354 -0.354  0.500    0.500  
  CO2675:ntr5  0.489 -0.692 -0.354 -0.354 -0.354 -0.707 -0.354  0.500    0.500  
  CO2675:ntr6  0.489 -0.692 -0.354 -0.354 -0.354 -0.354 -0.707  0.500    0.500  
              CO2675:4 CO2675:5
  CO2675                       
  nutrients2                   
  nutrients3                   
  nutrients4                   
  nutrients5                   
  nutrients6                   
  CO2675:ntr2                  
  CO2675:ntr3                  
  CO2675:ntr4                  
  CO2675:ntr5  0.500           
  CO2675:ntr6  0.500    0.500  
  optimizer (nloptwrap) convergence code: -2 (NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera).)
  Model failed to converge with max|grad| = 0.788311 (tol = 0.002, component 1)
  
  > 
  > an.sat <- anova(lmerout)
  > anova(lmerout, ddf="lme4")
  Analysis of Variance Table
                npar  Sum Sq Mean Sq  F value
  CO2              1  103.33  103.33  60.1718
  nutrients        5 3050.44  610.09 355.2632
  CO2:nutrients    5   35.47    7.09   4.1307
  > TOL <- 1e-5
  > stopifnot(isTRUE(all.equal(
  +   an.sat[,"DenDF"], c(2, 10, 10), tolerance=TOL
  + )))
  Error: isTRUE(all.equal(an.sat[, "DenDF"], c(2, 10, 10), tolerance = TOL)) is not TRUE
  Execution halted