I'm trying to do survival analysis using decision trees in rpart, similar to here: Using a survival tree from the 'rpart' package in R to predict new observations . To compare the decision tree survival model to other models, such as Cox regression, I'd like to use cross-validation to get Dxy and compare the c-index. When I try to use validate.rpart with an rpart fit that includes a Surv object I get an error. Borrowing the example from the previous question:
library(rms)
# Make Data:
set.seed(4)
dat = data.frame(X1 = sample(x = c(1,2,3,4,5), size = 100, replace=T))
dat$t = rexp(100, rate=dat$X1)
dat$t = dat$t / max(dat$t)
dat$e = rbinom(n = 100, size = 1, prob = 1-dat$t )
# Survival Fit:
sfit = survfit(Surv(t, event = e) ~ 1, data=dat)
plot(sfit)
# Tree Fit:
require(rpart)
tfit = rpart(formula = Surv(t, event = e) ~ X1 , data = dat, model=TRUE, control=rpart.control(minsplit=30, cp=0.01))
plot(tfit); text(tfit)
validate(tfit)
The error:
Error in unclass(x)[i, , drop = FALSE] :
(subscript) logical subscript too long
Any idea for a workaround for this problem? Is there any other way to get the c-index from an rpart survival model?