R Under development (unstable) (2025-10-07 r88904 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # Tests for COLR models > > set.seed(0) > > ## Depencies > ## IGNORE_RDIFF_BEGIN > library("tramnet") Loading required package: tram Loading required package: mlt Loading required package: basefun Loading required package: variables Loading required package: mvtnorm Loading required package: CVXR Attaching package: 'CVXR' The following object is masked from 'package:stats': power Loading required package: mlrMBO Loading required package: mlr Loading required package: ParamHelpers Loading required package: smoof Loading required package: checkmate > library("sandwich") > > ## IGNORE_RDIFF_END > old <- options(digits = 3) > > if (require("survival") & require("TH.data")) { + ## Exact and Right censored + data("GBSG2", package = "TH.data") + GBSG2$surv <- with(GBSG2, Surv(time, cens)) + x <- matrix(1 * (GBSG2$horTh == "yes"), ncol = 1) + colnames(x) <- "horTh" + + yCOLR <- Colr(surv ~ 1, data = GBSG2, log_first = TRUE, order = 10, support = c(1e-12, max(GBSG2$time))) + modCOLR <- tramnet(yCOLR, x, lambda = 0, alpha = 0) + yCOLRb <- Colr(surv ~ horTh, data = GBSG2, log_first = TRUE, order = 10) + print(max(abs(coef(yCOLRb, with_baseline = FALSE) - + coef(modCOLR, with_baseline = FALSE)))) + print(logLik(yCOLRb)) + print(logLik(modCOLR)) + print(-modCOLR$result$value) + print(logLik(modCOLR, newdata = tramnet:::.get_tramnet_data(modCOLR)[1:10, ])) + + ## methods + print(coef(modCOLR, tol = 0, with_baseline = TRUE)) + print(logLik(modCOLR)) + print(c(resid(modCOLR)[1:10])) + print(predict(modCOLR, type = "distribution", q = 1)[, 1:10]) + print(predict(modCOLR, type = "quantile", prob = 0.5)[, 1:10]) + print.default(head(simulate(modCOLR))) + print(as.data.frame(head(estfun(modCOLR)))) + plot(modCOLR, type = "survivor") + plot(modCOLR, type = "density", K = 120) + print(modCOLR) + } Loading required package: survival Loading required package: TH.data Loading required package: MASS Attaching package: 'MASS' The following object is masked from 'package:CVXR': huber Attaching package: 'TH.data' The following object is masked from 'package:MASS': geyser [1] 0.00515 'log Lik.' -2606 (df=12) 'log Lik.' -2608 (df=NA) [1] -2608 'log Lik.' -59.7 (df=NA) Bs1(surv) Bs2(surv) Bs3(surv) Bs4(surv) Bs5(surv) Bs6(surv) Bs7(surv) -392.887 -361.455 -321.490 -274.691 -274.621 -274.616 -274.615 Bs8(surv) Bs9(surv) Bs10(surv) Bs11(surv) horTh -37.671 -3.832 -3.832 0.692 -0.474 'log Lik.' -2608 (df=NA) 1 2 3 4 5 6 7 8 9 10 0.1108 -0.0617 -0.6217 -0.1275 -0.4063 -0.7079 0.4914 0.6068 -0.6834 0.5862 [1] 1.05e-24 6.50e-25 6.50e-25 6.50e-25 1.05e-24 1.05e-24 6.50e-25 1.05e-24 [9] 1.05e-24 1.05e-24 [1] 1506 2234 2234 2234 1506 1506 2234 1506 1506 1506 $tleft [1] NA NA NA NA NA NA $cleft [1] NA 2659 2659 NA NA NA $exact [1] 792 NA NA 1871 882 1886 $cright [1] NA Inf Inf NA NA NA $tright [1] NA NA NA NA NA NA $approxy [1] 792 2659 2659 1871 882 1886 attr(,"prob") function (weights) .wecdf(ret$approxy, weights) attr(,"class") [1] "response" "data.frame" Bs1(surv) Bs2(surv) Bs3(surv) Bs4(surv) Bs5(surv) Bs6(surv) Bs7(surv) 1 4.59e-19 3.79e-16 1.39e-13 2.98e-11 4.11e-09 3.76e-07 2.30e-05 2 2.39e-20 2.74e-17 1.40e-14 4.17e-12 7.96e-10 1.01e-07 8.59e-06 3 2.20e-14 5.03e-12 5.08e-10 2.97e-08 1.10e-06 2.66e-05 4.09e-04 4 4.97e-19 4.06e-16 1.47e-13 3.12e-11 4.24e-09 3.83e-07 2.30e-05 5 1.36e-14 3.36e-12 3.66e-10 2.32e-08 9.35e-07 2.48e-05 4.28e-04 6 2.22e-13 3.63e-11 2.59e-09 1.06e-07 2.67e-06 4.17e-05 3.59e-04 Bs8(surv) Bs9(surv) Bs10(surv) Bs11(surv) horTh 1 0.000901 0.0205 0.20300 -0.114 0.0000 2 0.000467 0.0147 0.19725 -0.274 -0.0617 3 0.003587 0.0108 -0.07668 -0.560 -0.6217 4 0.000885 0.0195 0.17924 -0.327 -0.1275 5 0.004486 0.0227 -0.00696 -0.427 0.0000 6 0.000639 -0.0185 -0.17501 -0.515 0.0000 Call: tramnet(model = yCOLR, x = x, lambda = 0, alpha = 0) Convergence: optimal Type: Continuous Outcome Logistic Regression Log-Likelihood: -2608 Coefficients: horTh -0.474 Sparsity: 1 regression coefficients, 1 of which are non-zero Tuning parameters: lambda alpha 0 0 > > > if (FALSE) { + ## left censored + GBSG2$cens <- as.integer(GBSG2$cens) + GBSG2$cens[GBSG2$time < 200] <- 2 + GBSG2$time[GBSG2$cens == 2] <- 100 + + yCOLR <- Colr(Surv(time, time, cens, type = "interval") ~ 1, data = GBSG2, log_first = TRUE, order = 10) + modCOLR <- tramnet(yCOLR, x, lambda = 0, alpha = 0) + yCOLRb <- Colr(Surv(time, time, cens, type = "interval") ~ horTh, data = GBSG2, log_first = TRUE, order = 10) + max(abs(coef(yCOLRb, with_baseline = FALSE) - + coef(modCOLR, with_baseline = FALSE))) + logLik(yCOLRb) + logLik(modCOLR) + + ## methods + coef(modCOLR, tol = 0, with_baseline = TRUE) + logLik(modCOLR) + resid(modCOLR)[1:10] + predict(modCOLR, type = "distribution", q = 1)[, 1:10] + predict(modCOLR, type = "quantile", prob = 0.5)[, 1:10] + head(simulate(modCOLR)) + head(estfun(modCOLR)) + plot(modCOLR, type = "survivor") + plot(modCOLR, type = "density", K = 120) + print(modCOLR) + + ## Unconditional, stratified + yCOLR <- Colr(surv | horTh ~ 1, data = GBSG2) + modCOLR <- tramnet(yCOLR, x = matrix(0, nrow = nrow(GBSG2)), lambda = 0, alpha = 0) + logLik(yCOLR) + logLik(modCOLR) + resid(modCOLR)[1:10] + predict(modCOLR, type = "distribution", q = 1)[, 1:10] + predict(modCOLR, type = "quantile", prob = 0.5)[, 1:10] + head(simulate(modCOLR)) + head(estfun(modCOLR)) + plot(modCOLR, type = "survivor") + plot(modCOLR, type = "density", K = 120) + print(modCOLR) + + + ## interval censored + GBSG2$time2 <- GBSG2$time + 50 + GBSG2$cens[which(GBSG2$cens == 1)[1:100]] <- 3 + + yCOLR <- Colr(Surv(time, time2, cens, type = "interval") ~ 1, data = GBSG2, log_first = TRUE, order = 10) + modCOLR <- tramnet(yCOLR, x, lambda = 0, alpha = 0) + yCOLRb <- Colr(Surv(time, time2, cens, type = "interval") ~ horTh, data = GBSG2, log_first = TRUE, order = 10) + max(abs(coef(yCOLRb, with_baseline = FALSE) - + coef(modCOLR, with_baseline = FALSE))) + logLik(yCOLRb) + logLik(modCOLR) + } > > options(old) > > proc.time() user system elapsed 15.46 0.64 16.09