Running 'AFT-Ex.R' [4s]
  Comparing 'AFT-Ex.Rout' to 'AFT-Ex.Rout.save' ... OK
  Running 'GBSG2.R' [2s]
  Running 'KM-Ex.R' [161s]
  Running 'faithful.R' [5s]
  Comparing 'faithful.Rout' to 'faithful.Rout.save' ... OK
  Running 'orm-Ex.R' [13s]
  Comparing 'orm-Ex.Rout' to 'orm-Ex.Rout.save' ... OK
  Running 'timedep_covar.R' [176s]
  Running 'truncreg-Ex.R' [2s]
  Comparing 'truncreg-Ex.Rout' to 'truncreg-Ex.Rout.save' ... OK
Running the tests in 'tests/KM-Ex.R' failed.
Complete output:
  > 
  > set.seed(290875)
  > 
  > ret <- TRUE
  > 
  > if (require("survival") && require("tram") && require("coin")) {
  + 
  +     d <- ovarian
  +     d$y <- with(d, Surv(futime, fustat))
  +     d$Ry <- with(d, R(y, as.R.ordered = TRUE))
  +     d$x <- d$rx
  +     tm <- sort(unique(d$futime[d$fustat == 1]))
  + 
  +     tol <- 1e-4
  + 
  +     ### nonpara ML, unconditional
  +     mP0 <- Polr(Ry ~ 1, data = d, method = "cloglog")
  +     s1 <- summary(survfit(y ~ 1, data = d), times = tm)$surv
  +     s2 <- predict(mP0, newdata = data.frame(1), type = "survivor")
  +     ret <- isTRUE(all.equal(s1, s2[-length(s2)], 
  +                      check.attributes = FALSE, tol = tol))  &&
  +                   cor(resid(mP0), logrank_trafo(d$y)) > .9999 &&
  +            isTRUE(all.equal(logLik(mP0, parm = coef(as.mlt(mP0))),
  +                             logLik(mP0, parm = log(-log(s1)))))
  + 
  +     ### conditional: estimate HR
  +     mP1 <- Polr(Ry ~ x, data = d, method = "cloglog")
  +     sf <- survdiff(y ~ x, data = d)
  +     mc1 <- coxph(y ~ x, data = d)
  + 
  +     ### see Survival Analysis: A Practical Approach, 
  +     ### Second Edition David Machin, Yin Bun Cheung, Mahesh K.B. Parmar
  +     ### Page 12
  +     oe <- sf$obs / sf$exp
  +     HR <- oe[1] / oe[2]
  + 
  +     ### compare: mP1 is nonpara ML, mc1 partial likelihood
  +     ### what is HR?
  +     #exp(coef(mP1))
  +     #exp(-coef(mc1))
  + }
  Loading required package: survival
  Loading required package: tram
  Loading required package: mlt
  Loading required package: basefun
  Loading required package: variables
  Loading required package: mvtnorm
  Loading required package: coin
  
  Attaching package: 'coin'
  
  The following object is masked from 'package:variables':
  
      support
  
  > 
  > ret
  [1] TRUE
  > 
  > proc.time()
     user  system elapsed 
     1.70    0.21    1.89 
Running the tests in 'tests/timedep_covar.R' failed.
Complete output:
  > 
  > library("mlt")
  Loading required package: basefun
  Loading required package: variables
  > library("survival")
  > library("flexsurv")
  > 
  > chk <- function(x, y, ...) {
  + 
  +     ret <- all.equal(x, y, ...)
  +     if (isTRUE(ret)) return(ret)
  +     print(ret)
  +     return(TRUE)
  + }
  > tol <- .001
  > 
  > ### right-censored veteran data
  > ### exponential model
  > fit1 <- coxph(Surv(time, status) ~ karno + age + trt, veteran)
  > fit2 <- survreg(Surv(time, status) ~ karno + age + trt, veteran, dist = "exponential")
  > fit3 <- flexsurvreg(Surv(time, status) ~ karno + age + trt, data= veteran, dist = "exponential")
  > 
  > veteran$ytime <- with(veteran, Surv(time, status))
  > dy <- numeric_var("ytime", support = c(0.1, 1000))
  > by <- log_basis(dy, ui = "increasing")
  > m <- mlt(ctm(by, shift = ~ karno + age + trt, data = veteran, todistr = "MinExtr"),
  +          data = veteran, fixed = c("log(ytime)" = 1))
  > 
  > stopifnot(chk(fit3$logliki, m$logliki(coef(m)[-2], weights(m)), 
  +                     tol = tol, check.attributes = FALSE))
  > 
  > stopifnot(chk(logLik(fit2), logLik(m), tol = tol))
  > stopifnot(chk(logLik(fit3), logLik(m), tol = tol, 
  +               check.attributes = FALSE))
  > 
  > ### Weibull model
  > fit2 <- survreg(Surv(time, status) ~ karno + age + trt, veteran, dist = "weibull")
  > fit3 <- flexsurvreg(Surv(time, status) ~ karno + age + trt, data= veteran, dist = "weibull")
  > 
  > veteran$ytime <- with(veteran, Surv(time, status))
  > dy <- numeric_var("ytime", support = c(0.1, 1000))
  > # by <- Bernstein_basis(dy, order = 10, ui = "increasing")
  > by <- log_basis(dy, ui = "increasing")
  > m <- mlt(ctm(by, shift = ~ karno + age + trt, data = veteran, todistr = "MinExtr"),
  +          data = veteran)
  > 
  > stopifnot(chk(fit3$logliki, m$logliki(coef(m), weights(m)), 
  +               tol = tol, check.attributes = FALSE))
  > 
  > stopifnot(chk(logLik(fit2), logLik(m), tol = tol))
  > stopifnot(chk(logLik(fit3), logLik(m), tol = tol,
  +               check.attributes = FALSE))
  > 
  > ### now with time-dependent covariates
  > vet2 <- survSplit(Surv(time, status) ~., veteran,
  +                   cut=c(60, 120), episode ="timegroup")
  > vet2$timegroup <- factor(vet2$timegroup)
  > vet2$ytime <- with(vet2, Surv(tstart, time, status))
  > 
  > ## exponential model
  > suppressWarnings(fit3 <- flexsurvreg(Surv(tstart, time, status) ~ 
  +     karno + karno:timegroup + age + trt, data= vet2, dist = "exponential"))
  > m <- mlt(ctm(by, shift = ~ karno + karno:timegroup + age + trt, data = vet2, todistr = "MinExtr"),
  +          data = vet2, fixed = c("log(ytime)" = 1))
  > 
  > stopifnot(chk(fit3$logliki, m$logliki(coef(m)[-2], weights(m)), 
  +               tol = tol, check.attributes = FALSE))
  > stopifnot(chk(logLik(fit3), logLik(m), tol = tol, check.attributes = FALSE))
  > 
  > ### Weibull model
  > fit3 <- flexsurvreg(Surv(tstart, time, status) ~ karno + karno:timegroup +
  +                      age + trt, data= vet2, dist = "weibull")
  > m <- mlt(ctm(by, shift = ~ karno + karno:timegroup + age + trt, data = vet2, todistr = "MinExtr"),
  +          data = vet2, scale = TRUE)
  > 
  > stopifnot(chk(fit3$logliki, m$logliki(coef(m), weights(m)), 
  +               tol = tol, check.attributes = FALSE))
  > stopifnot(chk(logLik(fit3), logLik(m), tol = tol, check.attributes = FALSE))
  > 
  > ## Cox model, see ?survival::survSplit
  > fit1 <- coxph(Surv(tstart, time, status) ~ karno + karno:strata(timegroup) +
  +               age + trt, data= vet2)
  > 
  > ### refit this model using mlt
  > btg <- as.basis(vet2$timegroup)
  > by <- Bernstein_basis(dy, order = 3, ui = "increasing")
  > m <- mlt(ctm(by, interacting = btg, 
  +          shift = ~ karno + karno:timegroup + age + trt, data = vet2, todistr = "MinExtr"),
  +          data = vet2, scale = TRUE)
  > 
  > ### noLD issues, unclear where they come from
  > #max(abs(coef(fit1) - coef(m)[-(1:12)])) < 1e-1
  > #max(abs(diag(vcov(m))[-(1:12)] - diag(vcov(fit1)))) < 1e-2
  > 
  > proc.time()
     user  system elapsed 
     9.35    1.35   10.71