### Example: Personalised Medicine Using Partitioned and Aggregated Cox-Models
### A combination of and
### based on infrastructure in the mlt R add-on package described in
### https://cran.r-project.org/web/packages/mlt.docreg/vignettes/mlt.pdf
library("trtf")
library("survival")
### German Breast Cancer Study Group 2 data set
data("GBSG2", package = "TH.data")
GBSG2$y <- with(GBSG2, Surv(time, cens))
### set-up Cox model with overall treatment effect in hormonal therapy
cmod <- Coxph(y ~ horTh, data = GBSG2, support = c(100, 2000), order = 5)
### overall log-hazard ratio
coef(cmod)
### roughly the same as
coef(coxph(y ~ horTh, data = GBSG2))
if (FALSE) {
### estimate age-dependent Cox models (here ignoring all other covariates)
ctrl <- ctree_control(minsplit = 50, minbucket = 20, mincriterion = 0)
set.seed(290875)
tf_cmod <- traforest(cmod, formula = y ~ horTh | age, control = ctrl,
ntree = 50, mtry = 1, trace = TRUE, data = GBSG2)
### plot age-dependent treatment effects vs. overall treatment effect
nd <- data.frame(age = 30:70)
cf <- predict(tf_cmod, newdata = nd, type = "coef")
nd$logHR <- sapply(cf, function(x) x["horThyes"])
plot(logHR ~ age, data = nd, pch = 19, xlab = "Age", ylab = "log-Hazard Ratio")
abline(h = coef(cmod <- mlt(m, data = GBSG2))["horThyes"])
### treatment most beneficial in very young patients
### NOTE: scale of log-hazard ratios depends on
### corresponding baseline hazard function which _differs_
### across age; interpretation of positive / negative treatment effect is,
### however, save.
### mclapply doesn't work in Windows
if (.Platform$OS.type != "windows") {
### computing predictions: predicted coefficients
cf1 <- predict(tf_cmod, newdata = nd, type = "coef")
### speedup with plenty of RAM and 4 cores
cf2 <- predict(tf_cmod, newdata = nd, cores = 4, type = "coef")
### memory-efficient with low RAM and _one_ core
cf3 <- predict(tf_cmod, newdata = nd, cores = 4, applyfun = lapply, type = "coef")
all.equal(cf1, cf2)
all.equal(cf1, cf3)
}
}
Run the code above in your browser using DataLab