R Under development (unstable) (2025-01-28 r87664 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. > > suppressWarnings(RNGversion("3.5.2")) > > library("trtf") Loading required package: mlt Loading required package: basefun Loading required package: variables Loading required package: partykit Loading required package: grid Attaching package: 'grid' The following object is masked from 'package:variables': unit Loading required package: libcoin Loading required package: mvtnorm Loading required package: tram > library("partykit") > library("survival") > data("GBSG2", package = "TH.data") > set.seed(290875) > ### Make UL and Windooze happy > options(digits = 5) > > yvar <- numeric_var("y", support = c(100, 2000), bounds = c(0, Inf)) > By <- Bernstein_basis(yvar, order = 5, ui = "incre") > m <- ctm(response = By, todistr = "MinExt") > GBSG2$y <- with(GBSG2, Surv(time, cens)) > > ctrl <- ctree_control(splitstat = "quad", teststat = "quad", minsplit = 40, minbucket = 20) > st2 <- trafotree(m, formula = y ~ horTh + age + menostat + tsize + tgrade + + pnodes + progrec + estrec, control = ctrl, data = GBSG2) > > coef(st2) Bs1(y) Bs2(y) Bs3(y) Bs4(y) Bs5(y) Bs6(y) 3 -3.7201 -0.60370 -0.60370 -0.36144 -0.13315 -0.13315 4 -6.1479 -1.21945 -1.21945 -1.21945 -0.84907 -0.59174 6 -4.2362 -0.42467 -0.42467 -0.16971 -0.16971 0.15229 7 -2.9301 0.22528 0.22528 0.22528 0.41536 0.62964 > logLik(st2) 'log Lik.' -2571.1 (df=24) > logLik(st2, newdata = GBSG2) 'log Lik.' -2571.1 (df=24) > > predict(st2, newdata = GBSG2[1:3,], type = "node") 1 2 3 4 6 6 > predict(st2, newdata = GBSG2[1:3,], type = "coef") Bs1(y) Bs2(y) Bs3(y) Bs4(y) Bs5(y) Bs6(y) 4 -6.1479 -1.21945 -1.21945 -1.21945 -0.84907 -0.59174 6 -4.2362 -0.42467 -0.42467 -0.16971 -0.16971 0.15229 6 -4.2362 -0.42467 -0.42467 -0.16971 -0.16971 0.15229 > predict(st2, newdata = GBSG2[1:3,], type = "hazard") [,1] [,2] [,3] [1,] 0.0000e+00 0.00000000 0.00000000 [2,] 2.9349e-05 0.00015119 0.00015119 [3,] 7.8176e-05 0.00030685 0.00030685 [4,] 1.5955e-04 0.00050786 0.00050786 [5,] 2.6012e-04 0.00070888 0.00070888 [6,] 3.5168e-04 0.00085936 0.00085936 [7,] 4.0786e-04 0.00092841 0.00092841 [8,] 4.1869e-04 0.00091451 0.00091451 [9,] 3.9225e-04 0.00083867 0.00083867 [10,] 3.4638e-04 0.00073070 0.00073070 [11,] 2.9897e-04 0.00061778 0.00061778 [12,] 2.6246e-04 0.00051912 0.00051912 [13,] 2.4287e-04 0.00044562 0.00044562 [14,] 2.4126e-04 0.00040212 0.00040212 [15,] 2.5551e-04 0.00039045 0.00039045 [16,] 2.8169e-04 0.00041213 0.00041213 [17,] 3.1447e-04 0.00047067 0.00047067 [18,] 3.4703e-04 0.00057394 0.00057394 [19,] 3.7069e-04 0.00073697 0.00073697 [20,] 3.7474e-04 0.00098676 0.00098676 > > plot(st2, tp_args = list(type = "survivor")) > > class(st2) <- class(st2)[-1L] > plot(st2) > > st1 <- ctree(y ~ horTh + age + menostat + tsize + tgrade + + pnodes + progrec + estrec, data = GBSG2, control = ctrl) > plot(st1) > > n1 <- predict(st1, type = "node") > n2 <- predict(st2, type = "node") > > table(n1, n2) n2 n1 3 4 6 7 3 21 227 0 0 4 5 123 0 0 6 2 19 69 54 7 3 33 110 20 > > tf <- traforest(m, formula = y ~ horTh + age + menostat + tsize + tgrade + + pnodes + progrec + estrec, data = GBSG2, + control = ctree_control(splitstat = "quad", teststat = "quad", + testtype = "Teststatistic", mincriterion = 1, minbucket = 50), + ntree = 50, trace = FALSE, cores = 1) > > w <- predict(tf, newdata = GBSG2[1:3,], type = "weights") > > cf <- coef(mlt(m, data = GBSG2)) > coef(m1 <- mlt(m, data = GBSG2, weights = w[,1], theta = cf)) Bs1(y) Bs2(y) Bs3(y) Bs4(y) Bs5(y) Bs6(y) -5.78885 -1.02739 -1.02739 -1.02739 -0.59177 -0.31235 > coef(m2 <- mlt(m, data = GBSG2, weights = w[,2], theta = cf)) Bs1(y) Bs2(y) Bs3(y) Bs4(y) Bs5(y) Bs6(y) -4.64957 -0.72016 -0.72016 -0.64744 -0.51526 -0.15658 > coef(m3 <- mlt(m, data = GBSG2, weights = w[,3], theta = cf)) Bs1(y) Bs2(y) Bs3(y) Bs4(y) Bs5(y) Bs6(y) -4.617996 -0.581874 -0.581874 -0.432848 -0.362252 -0.013281 > > layout(matrix(1:3, nr = 1)) > plot(m1, newdata = data.frame(1), type = "survivor") > plot(m2, newdata = data.frame(1), type = "survivor", add = TRUE) > plot(m3, newdata = data.frame(1), type = "survivor", add = TRUE) > > > cmod <- coxph(Surv(time, cens) ~ horTh + age + menostat + tsize + tgrade + + pnodes + progrec + estrec, data = GBSG2) > > plot(survfit(cmod, newdata = GBSG2[1:3,])) > > sf <- cforest(formula = y ~ horTh + age + menostat + tsize + tgrade + + pnodes + progrec + estrec, data = GBSG2, + control = ctree_control(splitstat = "quad", teststat = "quad", + testtype = "Teststatistic", mincriterion = 1, minbucket = 50), + ntree = 50, trace = FALSE) > > w <- predict(sf, newdata = GBSG2[1:3,], type = "weights") > > cf <- coef(mlt(m, data = GBSG2)) > coef(m1 <- mlt(m, data = GBSG2, weights = w[,1], theta = cf)) Bs1(y) Bs2(y) Bs3(y) Bs4(y) Bs5(y) Bs6(y) -5.48124 -1.04500 -1.04500 -1.04500 -0.58777 -0.36249 > coef(m2 <- mlt(m, data = GBSG2, weights = w[,2], theta = cf)) Bs1(y) Bs2(y) Bs3(y) Bs4(y) Bs5(y) Bs6(y) -4.71412 -0.79452 -0.79452 -0.53341 -0.53341 -0.17448 > coef(m3 <- mlt(m, data = GBSG2, weights = w[,3], theta = cf)) Bs1(y) Bs2(y) Bs3(y) Bs4(y) Bs5(y) Bs6(y) -4.417350 -0.589109 -0.589109 -0.303519 -0.303512 0.027579 > > plot(m1, newdata = data.frame(1), type = "survivor") > plot(m2, newdata = data.frame(1), type = "survivor", add = TRUE) > plot(m3, newdata = data.frame(1), type = "survivor", add = TRUE) > > proc.time() user system elapsed 32.98 2.64 35.64