Running 'LmME.R' [4s]
  Running 'Resp.R' [163s]
  Running 'SurvregME.R' [3s]
  Running 'basics.R' [4s]
  Running 'methods.R' [171s]
  Running 'predict.R' [159s]
  Running 'simulate.R' [6s]
  Running 'smooth.R' [158s]
  Running 'test_util.R' [0s]
Running the tests in 'tests/Resp.R' failed.
Complete output:
  > ## ===== Resp class =====
  > ## -- Test utils & settings
  > source("test_util.R")
  > .run_test <- identical(Sys.getenv("NOT_CRAN"), "true")
  > oldopt <- options(digits = 4)
  > set.seed(100)
  > 
  > library("tramME")
  Loading required package: tram
  Loading required package: mlt
  Loading required package: basefun
  Loading required package: variables
  Loading required package: mvtnorm
  > library("survival")
  > 
  > dat <- data.frame(x1 = c(100, 1:10, NA, NA), x2 = c(100, 2:10, NA, 11, NA),
  +                   x3 = c(NA, NA, 0:10))
  > dat$r <- with(dat, Resp(x1, x2, x3))
  > 
  > with(dat, chkid(Resp(x1, x2), Surv(x1, x2, type = "interval2")))
  > 
  > chkid(length(dat$r), 13L)
  > chkid(dat[1:3, ]$r, dat$r[1:3])
  > chkid(is.na(dat$r), c(rep(FALSE, 12), TRUE))
  > 
  > mf <- model.frame(r ~ 1, data = dat, na.action = na.omit)
  > chkid(nrow(mf), 12L)
  > 
  > m1 <- CoxphME(Resp(x1, x2) ~ 1, data = dat, nofit = TRUE)
  > chkid(inherits(d1 <- m1$data[[1]], "Surv"), TRUE)
  > m2 <- CoxphME(Resp(x1, x2, x3) ~ 1, data = dat, nofit = TRUE,
  +               support = c(0, 20))
  > ## NOTE: support is needed otherwise mlt throws an error (Report to Torsten?)
  > chkid(inherits(d2 <- m2$data[[1]], "Resp"), TRUE)
  > chkid(nrow(d1), nrow(d2))
  > chkerr(CoxphME(Resp(x1, x2, x3) ~ 1, data = dat, support = c(0, 20),
  +                nofit = TRUE, na.action = na.fail))
  > ## FIXME: wrong error message?!
  > 
  > ## === setting bounds
  > dat$r2 <- with(dat, Resp(x1, x2, x3, bounds = c(0, Inf)))
  > chkid(print(dat$r[-12]), print(dat$r2[-12]))
   [1] {100}             {( 1,   2]}       {( 2,   3]| >  0} {( 3,   4]| >  1}
   [5] {( 4,   5]| >  2} {( 5,   6]| >  3} {( 6,   7]| >  4} {( 7,   8]| >  5}
   [9] {( 8,   9]| >  6} {( 9,  10]| >  7} {(10, Inf]| >  8} {(NA,  NA]| > 10}
   [1] {100}             {( 1,   2]}       {( 2,   3]| >  0} {( 3,   4]| >  1}
   [5] {( 4,   5]| >  2} {( 5,   6]| >  3} {( 6,   7]| >  4} {( 7,   8]| >  5}
   [9] {( 8,   9]| >  6} {( 9,  10]| >  7} {(10, Inf]| >  8} {(NA,  NA]| > 10}
  > chkid(identical(print(dat$r[12]), print(dat$r2[12])), FALSE)
  [1] {(-Inf, 11]| > 9}
  [1] {(0, 11]| > 9}
  > 
  > ## === adjust in priniting
  > chkid(identical(print(R(dat$r2)), print(dat$r2)), FALSE)
   [1] {100}                         {(1.00e+00,   2]}            
   [3] {(2.00e+00,   3]| > 1.49e-08} {(3.00e+00,   4]| > 1.00e+00}
   [5] {(4.00e+00,   5]| > 2.00e+00} {(5.00e+00,   6]| > 3.00e+00}
   [7] {(6.00e+00,   7]| > 4.00e+00} {(7.00e+00,   8]| > 5.00e+00}
   [9] {(8.00e+00,   9]| > 6.00e+00} {(9.00e+00,  10]| > 7.00e+00}
  [11] {(1.00e+01, Inf]| > 8.00e+00} {(1.49e-08,  11]| > 9.00e+00}
  [13] {(      NA,  NA]| > 1.00e+01}
   [1] {100}             {( 1,   2]}       {( 2,   3]| >  0} {( 3,   4]| >  1}
   [5] {( 4,   5]| >  2} {( 5,   6]| >  3} {( 6,   7]| >  4} {( 7,   8]| >  5}
   [9] {( 8,   9]| >  6} {( 9,  10]| >  7} {(10, Inf]| >  8} {( 0,  11]| >  9}
  [13] {(NA,  NA]| > 10}
  > ## but the saved values are adjusted
  > chkid(all(unclass(dat$r2) > 0, na.rm = TRUE), TRUE)
  > 
  > summarize_tests()
  ==========================
  Number of failed tests: 0
  ==========================
  > 
  > options(oldopt)
  > 
  > 
  > proc.time()
     user  system elapsed 
     2.07    0.39    2.45 
Running the tests in 'tests/methods.R' failed.
Complete output:
  > ## -- Test utils & settings
  > source("test_util.R")
  > .run_test <- identical(Sys.getenv("NOT_CRAN"), "true")
  > oldopt <- options(digits = 4)
  > set.seed(100)
  > 
  > library("tramME")
  Loading required package: tram
  Loading required package: mlt
  Loading required package: basefun
  Loading required package: variables
  Loading required package: mvtnorm
  > library("survival")
  > data("sleepstudy", package = "lme4")
  > set.seed(100)
  > gamdat <- mgcv::gamSim(6, n = 500, scale = 2, verbose = FALSE)
  Gu & Wahba 4 term additive model
  > data("mcycle", package = "MASS")
  > 
  > ## -- Set and get parameters
  > mod_lm <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy, nofit = TRUE)
  > chkerr(coef(mod_lm) <- c(1, 1))
  > coef(mod_lm) <- c(1, -1, 0.5) ## doesn't raise an error until varcov is defined
  > vc <- varcov(mod_lm)
  > vc[[1]][] <- diag(2)
  > chkerr(varcov(mod_lm) <- vc, em = "constraints")
  > coef(mod_lm) <- c(-1, 0.5, 1) ## no error
  > varcov(mod_lm) <- vc
  > chkeq(varcov(mod_lm)$Subject, diag(2), check.attributes = FALSE)
  > vc[[1]][] <- matrix(c(1, 0.2, 0.6, 2), ncol = 2)
  > chkerr(varcov(mod_lm) <- vc)
  > 
  > mod_gm <- LmME(y ~ s(x0)+ x1 + s(x2) + (1|fac), data = gamdat, nofit = TRUE)
  > vc <- varcov(mod_gm)
  > chkid(names(vc), "fac")
  > vc <- varcov(mod_gm, full = TRUE)
  > chkid(names(vc), c("fac", "s(x0)", "s(x2)"))
  > cf <- coef(mod_gm, with_baseline = TRUE)
  > chkid(length(cf), 5L) ## NOTE: 2 baseline + 1 shift + 2 smooth
  > 
  > ## -- Log-likelihood
  > mod_lm <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy, nofit = TRUE)
  > stopifnot(is.na(logLik(mod_lm)))
  > chkerr(logLik(mod_lm, param = list(beta = c(-5, -1, 2), theta = c(0, 0, 0))),
  +        em = "constraints")
  > mod_lm2 <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy)
  > ss2 <- sleepstudy[sample(1:nrow(sleepstudy)), ] ## Just reshuffle
  > chkeq(logLik(mod_lm2), logLik(mod_lm2, newdata = ss2))
  > ## NOTE: sometimes there are very small numerical differences
  > ## (it might come from the numerical integration)
  > 
  > ## -- vcov
  > stopifnot(all(is.na(vcov(mod_lm))))
  > chkid(dim(vcov(mod_lm, pargroup = "fixef")), c(3L, 3L))
  > chkid(dim(vcov(mod_lm, pargroup = "ranef")), c(3L, 3L))
  > chkid(dim(vcov(mod_lm, pargroup = "shift")), c(1L, 1L))
  > mod_lm <- update(mod_lm, fixed = c("Days" = 0.5))
  > chkeq(dim(vcov(mod_lm, pargroup = "shift")), c(0L, 0L))
  > chkid(rownames(vcov(mod_lm, pargroup = "fixef")), c("(Intercept)", "Reaction"))
  > 
  > if (!.run_test) {
  +   mod_sr <- SurvregME(Surv(time, status) ~ rx, data = rats)
  +   vc1 <- vcov(mod_sr, method = "numDeriv")
  +   vc2 <- vcov(mod_sr, method = "analytical") ## NOTE: default in this specific model
  +   vc3 <- vcov(mod_sr, method = "optimHess")
  +   chkeq(vc1, vc2)
  +   ## NOTE: w/ optimHess, it's slightly different
  +   chkeq(vc1, vc3, tol = sqrt(.Machine$double.eps), chkdiff = TRUE)
  + }
  > 
  > mod_gm <- LmME(y ~ s(x0)+ x1 + s(x2) + (1|fac), data = gamdat)
  > chkid(dim(vcov(mod_gm, pargroup = "smooth")), c(4L, 4L))
  > 
  > ## -- variable names
  > mod_sr <- SurvregME(Surv(time, status) ~ rx, data = rats, nofit = TRUE)
  > chkid(variable.names(mod_sr, "grouping"), NULL)
  > chkid(variable.names(mod_sr, "interacting"), NULL)
  > chkid(variable.names(mod_sr, "smooth"), NULL)
  > chkid(variable.names(mod_sr, "response"), "Surv(time, status)")
  > mod_sr2 <- SurvregME(Surv(time, status) ~ rx + (1 | litter/rx), data = rats,
  +                  nofit = TRUE)
  > chkid(variable.names(mod_sr2, "grouping"), c("rx", "litter"))
  > 
  > chkid(variable.names(mod_gm, "smooth"), c("x0", "x2"))
  > chkid(variable.names(mod_gm), c("y", "x1", "x0", "x2", "fac"))
  > ## NOTE: linear shift term comes first (x1)
  > 
  > ## -- VarCorr
  > chkid(length(VarCorr(mod_sr)), 0L)
  > chkid(length(VarCorr(mod_sr2)), 2L)
  > chkid(length(VarCorr(mod_gm)), 1L)
  > 
  > ## -- confint
  > ci <- confint(mod_sr, pargroup = "ranef", type = "profile", estimate = TRUE)
  > chkid(dim(ci), c(0L, 3L))
  > ci <- confint(mod_sr2)
  > chkid(dim(ci), c(5L, 2L))
  > stopifnot(all(is.na(ci)))
  > ci <- confint(mod_lm, "foo")
  > chkid(dim(ci), c(0L, 2L))
  > ci <- confint(mod_lm, parm = "Subject", pmatch = TRUE)
  > chkid(dim(ci), c(3L, 2L))
  > 
  > m03 <- LmME(dist ~ speed, data = cars)
  > m04 <- Lm(dist ~ speed, data = cars)
  > chkeq(confint(m03, pargroup = "shift"), confint(m04), tol = 1e-5,
  +       check.attributes = FALSE)
  > 
  > ## -- random effects
  > mod_lm <- update(mod_lm, fixed = NULL)
  > stopifnot(all(is.na(ranef(mod_lm)[[1]])))
  > pr <- list(beta = coef(mod_lm2, fixed = FALSE, with_baseline = TRUE),
  +            theta = varcov(mod_lm2, as.theta = TRUE))
  > re1 <- ranef(mod_lm, param = pr, condVar = TRUE)
  > re2 <- ranef(mod_lm2, condVar = TRUE)
  > chkeq(re1, re2)
  > chkid(ranef(mod_sr), NULL)
  > 
  > nd <- sleepstudy[1:20, ]
  > re1 <- ranef(mod_lm2, newdata = nd)
  > re2 <- ranef(mod_lm2, condVar = FALSE)
  > chkeq(re1$Subject, re2$Subject[1:2, ])
  > 
  > re1 <- ranef(mod_gm, raw = TRUE)
  > re2 <- ranef(mod_gm, condVar = TRUE)
  > chkid(re2$fac[[1]], re1[1:4])
  > chkid(dim(attr(re2$fac, "condVar")), c(4L, 1L))
  > 
  > ## fixing smooth terms, or parts
  > mod_gm2 <- LmME(accel ~ s(times), data = mcycle)
  > re1 <- ranef(mod_gm2, raw = TRUE)
  > re2 <- ranef(mod_gm2, raw = TRUE, newdata = mcycle[1:2, ]) ## fix_smooth is on by default
  > chkeq(re1, re2)
  > pr <- list(beta = coef(mod_gm2, fixed = FALSE, with_baseline = TRUE),
  +            theta = varcov(mod_gm2, as.theta = TRUE, full = TRUE))
  > pr$gamma <- mod_gm2$param$gamma[1]
  > re3 <- ranef(mod_gm2, param = pr, raw = TRUE)
  > chkeq(re1, re3)
  > 
  > pr <- list(beta = coef(mod_gm, fixed = FALSE, with_baseline = TRUE),
  +            theta = varcov(mod_gm, as.theta = TRUE, full = TRUE))
  > pr$gamma <- mod_gm$param$gamma[1]
  > re <- ranef(mod_gm, param = pr, condVar = TRUE, fix_smooth = TRUE)
  > chkid(is.na(attr(re$fac, "condVar")[[1]]), c(TRUE, rep(FALSE, 3)))
  > chkeq(re[[1]], ranef(mod_gm)[[1]], check.attributes = FALSE)
  > 
  > ## -- Residuals
  > library("survival")
  > mod_sr <- SurvregME(Surv(time, status) ~ rx + (1 | litter), data = rats,
  +                     support = c(1, 90))
  > stopifnot(mod_sr$opt$convergence == 0)
  > res1 <- resid(mod_sr, newdata = rats[1:30, ])
  > res2 <- resid(mod_sr)[1:30]
  > ## NOTE: if the smaller sample doesn't contain complete groups, the returned
  > ## residuals will be different for that specific litter. This is because tramME
  > ## refits the random effects when it creates a new object (as it happens with
  > ## newdata)
  > chkeq(res1, res2)
  > 
  > if (!.run_test) {
  +   res1 <- resid(mod_gm, fix_smooth = TRUE, newdata = subset(gamdat, subset = fac == 1))
  +   res2 <- resid(mod_gm, fix_smooth = FALSE)[gamdat$fac == 1]
  +   chkeq(res1, res2)
  +   res1 <- resid(mod_gm, fix_smooth = FALSE, newdata = subset(gamdat, subset = fac == 1))
  +   chkeq(res1, res2, tol = sqrt(.Machine$double.eps), chkdiff = TRUE)
  + }
  > 
  > mod_gm_bc <- BoxCoxME(y ~ s(x0)+ x1 + s(x2) + (1|fac), data = gamdat)
  > res1 <- resid(mod_gm_bc, fix_smooth = TRUE)
  > res2 <- resid(mod_gm_bc, fix_smooth = FALSE)
  > chkeq(res1, res2)
  > 
  > pr <- list(gamma = mod_gm_bc$param$gamma[1:4])
  > res1 <- resid(mod_gm_bc, param = pr, newdata = gamdat)
  > res2 <- resid(mod_gm_bc)
  > chkeq(res1, res2)
  > 
  > ## -- FIXME: the tests below fail! Why?
  > ## probably because of the non-linearity of the log-likelihood
  > ## the derivative of the integrated ll != the derivative of the
  > ## penalized ll wrt the constant
  > ## pr <- list(gamma = mod_sr$param$gamma[1:2])
  > ## res1 <- resid(mod_sr, param = pr, newdata = rats[1:4, ])
  > ## res2 <- resid(mod_sr)[1:4]
  > 
  > ## pr <- list(gamma = mod_sr$param$gamma)
  > ## res1 <- resid(mod_sr, param = pr)
  > ## res2 <- resid(mod_sr)
  > ## all.equal(res1, res2)
  > 
  > ## m <- CoxphME(Surv(y, uncens) ~ trt + (1 | center), data = eortc, log_first = TRUE)
  > ## pr <- list(gamma = m$param$gamma[1:2])
  > ## res1 <- resid(m, param = pr, newdata = eortc[c(1, 65), ])
  > ## res2 <- resid(m)[c(1, 65)]
  > ## all.equal(res1, res2, tol = 1e-3)
  > ## --
  > 
  > m <- CoxphME(Surv(time, status) | celltype ~ trt + s(age) + s(karno), data = veteran,
  +              log_first = TRUE)
  > res1 <- resid(m, fix_smooth = TRUE)
  > res2 <- resid(m, fix_smooth = FALSE)
  > chkeq(res1, res2, tol = 1e-5)
  > 
  > ## -- print & summary
  > mod_sr3 <- SurvregME(Surv(time, status) | celltype ~ trt + age + karno, data = veteran,
  +                      dist = "loglogistic", fixed = c("age" = 0.02))
  > stopifnot(mod_sr3$opt$convergence == 0)
  > mod_sr4 <- Survreg(Surv(time, status) | celltype ~ trt + age + karno, data = veteran,
  +                    dist = "loglogistic", fixed = c("age" = 0.02))
  > chkeq(logLik(mod_sr3), logLik(mod_sr4), check.attributes = FALSE)
  > ss <- summary(mod_sr3)
  > stopifnot(grepl("Stratified", ss$name, fixed = TRUE))
  > chkid(ss$fixed, c("age" = 0.02))
  > ss <- summary(mod_lm)
  > stopifnot(grepl("Mixed-Effects", ss$name, fixed = TRUE))
  > stopifnot(!ss$fitted)
  > ss <- summary(mod_lm2)
  > stopifnot(ss$fitted)
  > f <- dist ~ speed
  > mm <- LmME(f, data = cars)
  > chkid(summary(mm)$formula, f)
  > 
  > ## -- subsets and na.actions
  > data("soup", package = "ordinal")
  > dat <- soup
  > dat$RESP[dat$AGEGROUP == "18-30"] <- NA
  > chkerr(mod_polr1 <- PolrME(SURENESS | SOUPFREQ ~ PROD + (1 | RESP/PROD),
  +                            data = dat, nofit = TRUE, na.action = na.fail))
  > mod_polr1 <- PolrME(SURENESS | SOUPFREQ ~ PROD + (1 | RESP/PROD),
  +                     data = dat, nofit = TRUE, na.action = na.omit)
  > mod_polr2 <- PolrME(SURENESS | SOUPFREQ ~ PROD + (1 | RESP/PROD),
  +                     data = soup, nofit = TRUE, na.action = na.fail,
  +                     subset = AGEGROUP != "18-30")
  > par <- list(beta = coef(mod_polr1, with_baseline = TRUE),
  +             theta = varcov(mod_polr1, as.theta = TRUE))
  > chkeq(logLik(mod_polr1, param = par), logLik(mod_polr2, param = par))
  > 
  > data("eortc", package = "coxme")
  > dat <- eortc
  > dat[dat$center <= 10, "center"] <- NA
  > mm1 <- CoxphME(Surv(y, uncens) ~ trt + (1 | center), data = dat,
  +                 log_first = TRUE, nofit = TRUE) ## na.omit is the default
  > mm2 <- CoxphME(Surv(y, uncens) ~ trt + (1 | center), data = eortc,
  +                 log_first = TRUE, subset = center > 10, nofit = TRUE)
  > par <- list(beta = coef(mm1, with_baseline = TRUE),
  +             theta = varcov(mm1, as.theta = TRUE))
  > chkeq(logLik(mm1, param = par), logLik(mm2, param = par))
  > 
  > ## -- weights & offsets
  > ## NOTE: many of this functionality is disabled at the moment
  > ## data("eortc", package = "coxme")
  > ## mod_cox1 <- CoxphME(Surv(y, uncens) ~ trt + (1 | center/trt), data = eortc,
  > ##                     log_first = TRUE, order = 10, nofit = TRUE, ## w/o do_update = TRUE!
  > ##                     support = c(1, 2500)) ## NOTE: set support explicitly to define same bases
  > ## stopifnot(is.null(weights(mod_cox1)))
  > ## we <- sample(c(1, 3), nrow(eortc), replace = TRUE)
  > ## chkerr(weights(mod_cox1) <- we, "do_update")
  > ## mod_cox1 <- update(mod_cox1, do_update = TRUE)
  > ## weights(mod_cox1) <- we
  > ## chkid(weights(mod_cox1), we)
  > ## mod_cox2 <- CoxphME(Surv(y, uncens) ~ trt + (1 | center/trt), data = eortc,
  > ##                     log_first = TRUE, order = 10, nofit = TRUE, weights = we,
  > ##                     support = c(1, 2500))
  > ## par <- mod_cox2$tmb_obj$par
  > ## chkeq(logLik(mod_cox1, param = par), logLik(mod_cox2, param = par))
  > ## dat <- eortc[rep(1:nrow(eortc), we), ]
  > ## mod_cox3 <- CoxphME(Surv(y, uncens) ~ trt + (1 | center/trt), data = dat,
  > ##                     log_first = TRUE, order = 10, nofit = TRUE,
  > ##                     support = c(1, 2500))
  > ## chkeq(logLik(mod_cox1, param = par), logLik(mod_cox3, param = par))
  > 
  > ## subsequently updated weights and offsets are carried forward...
  > ## mod_cox1 <- CoxphME(Surv(time, status) ~ rx + (1 | litter), data = rats, log_first = TRUE,
  > ##                     order = 12, nofit = TRUE, do_update = TRUE)
  > ## offset(mod_cox1) <- rep(0.1, nrow(rats))
  > ## mod_cox2 <- update(mod_cox1, resid = TRUE)
  > ## chkid(offset(mod_cox1), offset(mod_cox2))
  > ## ## ...but will lead to errors when the data changes its size (as expected)
  > ## chkerr(mod_cox3 <- update(mod_cox1, data = rats[1:200, ]), "differing number of rows")
  > 
  > ## -- weights
  > data("eortc", package = "coxme")
  > we <- sample(c(1, 3), nrow(eortc), replace = TRUE)
  > mod_cox1 <- CoxphME(Surv(y, uncens) ~ trt + (1 | center/trt), data = eortc,
  +                     log_first = TRUE, order = 10, nofit = TRUE, weights = we,
  +                     support = c(1, 2500)) ## NOTE: set support explicitly to define same bases
  > dat <- eortc[rep(1:nrow(eortc), we), ]
  > mod_cox2 <- CoxphME(Surv(y, uncens) ~ trt + (1 | center/trt), data = dat,
  +                     log_first = TRUE, order = 10, nofit = TRUE,
  +                     support = c(1, 2500))
  > par <- list(beta = coef(mod_cox2, with_baseline = TRUE),
  +             theta = varcov(mod_cox2, as.theta = TRUE))
  > chkeq(logLik(mod_cox1, param = par), logLik(mod_cox2, param = par))
  > 
  > ## -- offsets
  > os <- runif(nrow(sleepstudy))
  > mod_lm1 <- Lm(Reaction ~ Days, data = sleepstudy, offset = os)
  > mod_lm2 <- LmME(Reaction ~ Days, data = sleepstudy)
  > chkeq(logLik(mod_lm1), logLik(mod_lm2), check.attributes = FALSE,
  +       tol = 0.1, scale = 1, chkdiff = TRUE)
  > mod_lm2 <- update(mod_lm2, offset = os)
  > chkeq(logLik(mod_lm1), logLik(mod_lm2), check.attributes = FALSE)
  > 
  > ## -- update
  > ## NOTE: When the updated model must have the exact same bases, pass the ctm into update
  > ## (used by e.g. logLik.tramME)
  > mod_cox1 <- CoxphME(Surv(time, status) ~ rx + (1 | litter), data = rats, log_first = TRUE,
  +                     order = 12, nofit = TRUE)
  > mod_cox2 <- update(mod_cox1, data = rats[1:200, ])
  > chkid(mod_cox1$model$ctm, mod_cox2$model$ctm, chkdiff = TRUE) ## not the same
  > mod_cox2 <- update(mod_cox1, data = rats[1:200, ], ctm = mod_cox1$model$ctm)
  > chkid(mod_cox1$model$ctm, mod_cox2$model$ctm) ## same
  > 
  > ## -- fitmod
  > ## FIXME: remove
  > ## data("neck_pain", package = "ordinalCont")
  > ## mod_colr <- ColrME(vas ~ time * laser + (1 | id), data = neck_pain, bounds = c(0, 1),
  > ##                    support = c(0, 1), order = 4, nofit = TRUE)
  > ## fit <- fitmod(mod_colr)
  > ## NOTE: they do not share the environment in the tramTMB
  > ## stopifnot(!identical(mod_colr$tmb_obj$env, fit$tmb_obj$env))
  > ## fit2 <- ColrME(vas ~ time * laser + (1 | id), data = neck_pain, bounds = c(0, 1),
  > ##                support = c(0, 1), order = 4)
  > ## chkeq(logLik(fit), logLik(fit2))
  > 
  > ## data("mcycle", package = "MASS")
  > ## m <- LmME(accel ~ s(times), data = mcycle, nofit = TRUE)
  > ## f1 <- fitmod(m)
  > ## f2 <- LmME(accel ~ s(times), data = mcycle)
  > ## chkeq(f1$param, f2$param, tol = 1e-4) ## NOTE: not exactly equal bec of different starting values
  > 
  > ## -- model.frame
  > mod_cox3 <- CoxphME(Surv(time, status) | celltype ~ trt + s(age) + karno,
  +                     data = veteran, log_first = TRUE, nofit = TRUE)
  > chkeq(model.frame(mod_cox3), mod_cox3$data, check.attributes = FALSE)
  > chkeq(model.frame(mod_cox3, data = veteran[1:10, ]), mod_cox3$data[1:10, ],
  +       check.attributes = FALSE)
  > chkeq(model.frame(mod_cox3, data = veteran[1:10, ], subset = karno < 60),
  +       subset(mod_cox3$data[1:10, ], subset = karno < 60),
  +       check.attributes = FALSE)
  > chkeq(model.frame(mod_cox3, data = veteran, subset = karno < 60),
  +       model.frame(mod_cox3, data = mod_cox3$data, subset = karno < 60),
  +       check.attributes = FALSE)
  > chkeq(model.frame(mod_cox3, subset = karno < 60),
  +       subset(mod_cox3$data, subset = karno < 60),
  +       check.attributes = FALSE)
  > chkeq(model.frame(mod_cox1, subset = litter <= 3),
  +       subset(mod_cox1$data, subset = litter <= 3), check.attributes = FALSE)
  > chkeq(model.frame(mod_cox3, data = veteran, subset = time > 60)[[1]][, 1],
  +       veteran$time[veteran$time > 60])
  > chkeq(nlevels(model.frame(mod_lm,
  +                           subset = as.numeric(as.character(Subject)) > 310,
  +                           drop.unused.levels = TRUE)$Subject),
  +       nlevels(sleepstudy$Subject) - 3L)
  > ## w/ offset
  > st <- sleepstudy
  > st$foo <- runif(nrow(st))
  > mod_os <- update(mod_lm, offset = -log(foo), data = st)
  > chkeq(mf <- model.frame(mod_os, data = st[1:10, ]), mod_os$data[1:10, ])
  > chkid("(offset)" %in% colnames(mf), TRUE)
  > chkerr(model.frame(mod_os, data = sleepstudy[1:10, ]),
  +        "'foo' not found")
  > chkeq(model.frame(mod_os), model.frame(mod_os, data = st))
  > chkeq(model.offset(model.frame(mod_os, subset = Reaction < 250)),
  +       -log(st$foo[st$Reaction < 250]))
  > 
  > ## -- model.matrix
  > nd <- model.frame(mod_cox3)[rep(1, 100), ]
  > nd[[1]] <- seq(1, 120, length.out = 100)
  > mm1 <- model.matrix(mod_cox3, data = nd, simplify = TRUE)
  > mm2 <- model.matrix(mod_cox3, data = nd, simplify = TRUE, keep_sign = FALSE)
  > chkid(mm1, mm2) ## equal in the case of CoxphME
  > mm1 <- model.matrix(mod_cox3, data = veteran, subset = karno > 40)
  > mm2 <- model.matrix(mod_cox3, data = model.frame(veteran, subset = karno > 40))
  > chkid(mm1, mm2)
  > nd <- model.frame(mod_lm)[rep(1, 100), ]
  > nd[[1]] <- seq(150, 250, length.out = 100)
  > mm1 <- model.matrix(mod_lm, data = nd, simplify = TRUE)
  > mm2 <- model.matrix(mod_lm, data = nd, simplify = TRUE, drop_unused_groups = TRUE)
  > chkid(dim(mm1$Zt), c(36L, 100L))
  > chkid(dim(mm2$Zt), c(2L, 100L))
  > 
  > ## -- Anova
  > ## NOTE: this should be at the end because ordinal will mask ranef and VarCorr,
  > ## which can cause problems
  > library("ordinal")
  > fit1a <- PolrME(rating ~ temp + contact + (1 | judge), data = wine, method = "probit")
  > fit2a <- clmm2(rating ~ temp + contact, random = judge, data = wine,
  +                Hess = TRUE, nAGQ = 1, link = "probit")
  > chkeq(logLik(fit1a), logLik(fit2a), tol = 1e-7, check.attributes = FALSE)
  > fit1b <- PolrME(rating | contact ~ temp + (1 | judge), data = wine, method = "probit")
  > fit2b <- clmm2(rating ~ temp, nominal = ~ contact, random = judge, data = wine,
  +                Hess = TRUE, nAGQ = 1, link = "probit")
  > lrt1 <- anova(fit1a, fit1b)
  > lrt2 <- anova(fit2a, fit2b)
  > chkeq(lrt1$Chisq[2], lrt2$`LR stat.`[2], tol = 1e-5)
  > 
  > summarize_tests()
  ==========================
  Number of failed tests: 0
  ==========================
  > 
  > options(oldopt)
  > 
  > proc.time()
     user  system elapsed 
     9.06    0.75    9.79 
Running the tests in 'tests/predict.R' failed.
Complete output:
  > ## -- Test utils & settings
  > source("test_util.R")
  > .run_test <- identical(Sys.getenv("NOT_CRAN"), "true")
  > oldopt <- options(digits = 4)
  > set.seed(100)
  > 
  > library("tramME")
  Loading required package: tram
  Loading required package: mlt
  Loading required package: basefun
  Loading required package: variables
  Loading required package: mvtnorm
  > data("sleepstudy", package = "lme4")
  > 
  > # -- newdata w/ response
  > fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy)
  > pr1 <- predict(fit, newdata = sleepstudy[1:20, ], type = "trafo")
  > pr2 <- predict(fit, type = "trafo")[1:20]
  > chkid(pr1, pr2)
  > 
  > ## -- newdata w/o response
  > nd <- sleepstudy
  > nd[["Reaction"]] <- NULL
  > pr1 <- predict(fit, newdata = nd, ranef = ranef(fit, raw = TRUE), type = "trafo", K = 100)
  > chkid(unname(dim(pr1)), c(100L, nrow(sleepstudy)))
  > chkerr(pr2 <- predict(fit, newdata = nd, K = 100))
  > 
  > ## -- check "zero" option of ranef
  > nd <- sleepstudy[c(4, 14, 24), ]
  > pr1 <- predict(fit, newdata = nd, ranef = rep(0, 6), q = c(300, 320), type = "distribution")
  > pr2 <- predict(fit, newdata = nd, ranef = "zero", q = c(300, 320), type = "distribution")
  > chkid(pr1, pr2)
  > 
  > ## -- various formatting of ranef
  > pr1 <- predict(fit, ranef = ranef(fit, raw = TRUE), type = "quantile", prob = 0.5)
  > ## ... also with formatted ranefs
  > pr2 <- predict(fit, ranef = ranef(fit), type = "quantile", prob = 0.5)
  > chkid(pr1, pr2)
  > 
  > ## -- compare w/ lmer
  > library("lme4")
  Loading required package: Matrix
  > lm1 <- LmME(Reaction ~ Days + (Days || Subject), data = sleepstudy)
  > lm2 <- lmer(Reaction ~ Days + (Days || Subject), data = sleepstudy, REML = FALSE)
  > chkeq(predict(lm1, type = "lp") * sigma(lm1) + coef(lm1, as.lm = TRUE)[1],
  +       fitted(lm2), tol = 1e-6)
  > 
  > ## -- w/ Surv response & w/o shift terms
  > library("survival")
  > fit2 <- SurvregME(Surv(time, status) | rx ~ 1 + (1 | litter), data = rats,
  +                   dist = "rayleigh")
  > pdf(file = NULL)
  > pl <- plot(fit2, newdata = rats[1:2, ], ranef = -1, type = "survivor", K = 100,
  +            col = 1)
  > dev.off()
  null device 
            1 
  > chkeq(dim(pl), c(100L, 2L), check.attributes = FALSE)
  > 
  > ## -- compare with tram
  > m1 <- Lm(dist ~ speed, data = cars, fixed = c(speed = 0.3))
  > m2 <- LmME(dist ~ speed, data = cars, fixed = c(speed = 0.3))
  > stopifnot(m2$opt$convergence == 0)
  > chkeq(logLik(m1), logLik(m2), check.attributes = FALSE)
  > nd <- cars
  > nd[["dist"]] <- NULL
  > pr1 <- predict(as.mlt(m1), newdata = nd, type = "trafo", K = 200)
  > pr2 <- predict(m2, newdata = nd, type = "trafo", K = 200)
  > chkeq(pr1, pr2, tol = 1e-6)
  > 
  > data("neck_pain", package = "ordinalCont")
  > m1 <- ColrME(vas ~ laser * time, data = neck_pain, bounds = c(0, 1), support = c(0, 1))
  > m2 <- Colr(vas ~ laser * time, data = neck_pain, bounds = c(0, 1), support = c(0, 1))
  > stopifnot(m2$opt$convergence == 0)
  > chkeq(logLik(m1), logLik(m2), check.attributes = FALSE)
  > nd <- neck_pain[1, ]
  > nd$vas <- NULL
  > pr1 <- predict(m1, newdata = nd, K = 5, type = "distribution")
  > pr2 <- predict(as.mlt(m2), newdata = nd, K = 5, type = "distribution")
  > chkeq(pr1, pr2, tol = 1e-5)
  > 
  > ## -- edge cases
  > mod <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy, nofit = TRUE)
  > pr <- predict(mod, ranef = "zero", type = "trafo")
  > stopifnot(all(is.na(pr)))
  > coef(mod) <- c(-5, 2, 0.05)
  > pr <- predict(mod, ranef = "zero", type = "trafo")
  > stopifnot(all(!is.na(pr)))
  > chkerr(pr <- predict(mod), "supply random effects")
  > 
  > ## -- check random effects
  > m <- CoxphME(Surv(time, status) ~ rx + (1 | litter), data = rats, log_first = TRUE)
  > nd <- rats[1, ]
  > pr <- predict(m, newdata = nd, type = "trafo", ranef = "zero", K = 5)
  > pr2 <- predict(m, newdata = nd, type = "trafo", ranef = 1, K = 5)
  > chkeq(pr + 1, pr2)
  > m <- LmME(Reaction ~ Days + (1 | Subject), data = sleepstudy)
  > nd <- sleepstudy[10, ]
  > nd$Reaction <- NULL
  > pr <- predict(m, newdata = nd, type = "trafo", ranef = "zero", K = 5)
  > pr2 <- predict(m, newdata = nd, type = "trafo", ranef = 2, K = 5)
  > chkeq(pr - 2, pr2)
  > 
  > 
  > ## --- w/ smooth terms
  > ## lp
  > library("mgcv")
  Loading required package: nlme
  
  Attaching package: 'nlme'
  
  The following object is masked from 'package:lme4':
  
      lmList
  
  The following object is masked from 'package:mlt':
  
      coef<-
  
  This is mgcv 1.9-1. For overview type 'help("mgcv-package")'.
  > fit_sm1 <- LmME(Reaction ~ s(Days) + (1 | Subject), data = sleepstudy)
  > fit_sm2 <- gam(Reaction ~ s(Days) + s(Subject, bs = "re"), data = sleepstudy, method = "ML")
  > ## fitted REs
  > pr1a <- (predict(fit_sm1) - coef(fit_sm1, with_baseline = TRUE)[1]) * sigma(fit_sm1)
  > pr2 <- predict(fit_sm2)
  > chkeq(pr1a, c(pr2), tol = 1e-5)
  > ## zero REs
  > pr1b <- (predict(fit_sm1, ranef = "zero") - coef(fit_sm1, with_baseline = TRUE)[1]) * sigma(fit_sm1)
  > pr2 <- predict(fit_sm2, exclude = "s(Subject)")
  > chkeq(pr1b, c(pr2), tol = 1e-5)
  > ## new data
  > nd <- sleepstudy[1:10,  ]
  > pr1c <- (predict(fit_sm1, newdata = nd) - coef(fit_sm1, with_baseline = TRUE)[1]) * sigma(fit_sm1)
  > chkeq(pr1a[1:10], pr1c)
  > pr2 <- predict(fit_sm2, newdata = nd)
  > chkeq(pr1c, c(pr2), tol = 1e-5)
  > 
  > ## density
  > data("mcycle", package = "MASS")
  > m <- LmME(accel ~ s(times, bs = "cr"), data = mcycle)
  > nd <- data.frame(times = seq(5, 30, by = 5))
  > qs <- seq(-134, 75, length.out = 50)
  > lp <- predict(m, nd, type = "lp")
  > lp2 <- (lp - coef(m, with_baseline = TRUE)[1]) * sigma(m)
  > pr1 <- predict(m, nd, type = "density", q = qs)
  > pr2 <- sapply(lp2, function(x) dnorm(qs, mean = x, sd = sigma(m)))
  > chkeq(pr1, pr2, check.attributes = FALSE)
  > 
  > ## a complicated plot
  > mod_su <- SurvregME(Surv(time, status) | celltype ~ age + s(karno, by = trt),
  +                     data = veteran, dist = "loglogistic")
  > pdf(file = NULL)
  > plot(mod_su, type = "density")
  > dev.off()
  null device 
            1 
  > 
  > summarize_tests()
  ==========================
  Number of failed tests: 0
  ==========================
  > 
  > options(oldopt)
  > 
  > proc.time()
     user  system elapsed 
     5.84    0.54    6.37 
Running the tests in 'tests/smooth.R' failed.
Complete output:
  > ## -- Test utils & settings
  > source("test_util.R")
  > .run_test <- identical(Sys.getenv("NOT_CRAN"), "true")
  > oldopt <- options(digits = 4)
  > set.seed(100)
  > 
  > library("mgcv")
  Loading required package: nlme
  This is mgcv 1.9-1. For overview type 'help("mgcv-package")'.
  > library("tramME")
  Loading required package: tram
  Loading required package: mlt
  Loading required package: basefun
  Loading required package: variables
  
  Attaching package: 'mlt'
  
  The following object is masked from 'package:nlme':
  
      coef<-
  
  Loading required package: mvtnorm
  > data("mcycle", package = "MASS")
  > gamdat <- mgcv::gamSim(6, n = 500, scale = 2, verbose = FALSE)
  Gu & Wahba 4 term additive model
  > gamdat2 <- mgcv::gamSim(6, n = 100, scale = 2, verbose = FALSE)
  Gu & Wahba 4 term additive model
  > 
  > ## --
  > m <- LmME(accel ~ s(times), data = mcycle, nofit = TRUE)
  > sm <- smooth_terms(m)
  > chkid(length(sm), 0L)
  > chkid(class(sm), c("smooth.tramME", "list"))
  > 
  > ## -- Check reparametrization
  > m <- LmME(accel ~ s(times), data = mcycle)
  > sm <- smooth_terms(m, as.lm = TRUE)
  > sm2 <- smooth_terms(m)
  > chkeq(sm[[1]][, 2], sm2[[1]][, 2] * sigma(m))
  > 
  > ## -- basic comparison to mgcv w/ MLE
  > m2 <- mgcv::gam(accel ~ s(times), data = mcycle, method = "ML")
  > nd <- with(mcycle, data.frame(times = seq(min(times), max(times), length.out = 100)))
  > sm2 <- predict(m2, newdata = nd, type = "terms")
  > chkeq(sm[[1]][, 2], sm2[, 1], check.attributes = FALSE, tol = 1e-6)
  > 
  > ## -- set up and eval smooth on different data: out-of-sample logLik
  > ll1 <- logLik(m)
  > nd <- mcycle[sample(seq(nrow(mcycle))), ]
  > ll2 <- logLik(m, newdata = nd, type = "integrated") ## only same when no RE is fixed
  > chkeq(ll1, ll2)
  > 
  > nd <- mcycle[1:100, ]
  > m3 <- LmME(accel ~ s(times), data = nd, nofit = TRUE)
  > sm <- tramME:::.tramME_smooth(m) ## set up the smooth term on the whole dataset
  > m4 <- LmME(accel ~ s(times), data = nd, smooth = sm, nofit = TRUE)
  > chkeq(m3$tmb_obj$env$data$X, m4$tmb_obj$env$data$X, tol = 0.1, scale = 1,
  +       chkdiff = TRUE) ## not the same
  > 
  > mod_gm <- LmME(y ~ s(x0)+ s(x1) + s(x2) + (1|fac), data = gamdat)
  > ## NOTE: by fixing random effects, we change the log-likelihood
  > chkeq(logLik(mod_gm, newdata = gamdat2),
  +       logLik(mod_gm, newdata = gamdat2, type = "integrated"),
  +       tol = 0.1, scale = 1, chkdiff = TRUE) ## not the same
  > 
  > ## -- restrict smooths to be evaluated through newdata argument
  > if (!.run_test) {
  +   chkid(length(sm1 <- smooth_terms(mod_gm)), 3L)
  +   nd <- data.frame(x0 = sm1[[1]]$x0, x2 = sm1[[3]]$x2)
  +   chkid(length(sm2 <- smooth_terms(mod_gm, newdata = nd)), 2L)
  +   chkeq(sm1[c(1, 3)], sm2, check.attributes = FALSE)
  +   nd <- nd[c(1, 50, 100), 1, drop = FALSE]
  +   chkid(length(sm3 <- smooth_terms(mod_gm, newdata = nd)), 1L)
  +   chkeq(sm1[[1]][c(1, 50, 100), ], sm3[[1]], check.attributes = FALSE)
  + }
  > 
  > ## -- function of variable in smoother
  > mod <- LmME(accel ~ s(sqrt(times)), data = mcycle)
  > mod2 <- gam(accel ~ s(sqrt(times)), data = mcycle, method = "ML")
  > chkeq(-summary(mod2)$sp.criterion, as.numeric(logLik(mod)),
  +       check.attributes = FALSE, tol = 1e-5)
  > chkid(variable.names(mod, which = "smooth"), "times")
  > pr1 <- (predict(mod, newdata = data.frame(times = 1:10), type = "lp") -
  +   coef(mod, with_baseline = TRUE)[1]) * sigma(mod)
  > pr2 <- c(predict(mod2, newdata = data.frame(times = 1:10)))
  > chkeq(pr1, pr2, tol = 1e-5)
  > 
  > ## w/ by factor
  > gamdat <- mgcv::gamSim(4, n = 200)
  Factor `by' variable example
  > m1 <- BoxCoxME(y ~ x0 + x1 + s(x2, by = fac, fx = TRUE, k = 8), data = gamdat)
  > edf1 <- edf_smooth(m1)
  > m2 <- gam(y ~ x0 + x1 + s(x2, by = fac, fx = TRUE, k = 8), data = gamdat)
  > edf2 <- summary(m2)$edf
  > chkeq(edf1, as.vector(edf2), check.attributes = FALSE)
  > 
  > summarize_tests()
  ==========================
  Number of failed tests: 0
  ==========================
  > 
  > options(oldopt)
  > 
  > proc.time()
     user  system elapsed 
     4.45    0.46    4.90