# NOT RUN {
#--- Get the data
data(GBSG2)
#numeric coding of character variables
GBSG2$horTh1<- as.numeric(GBSG2$horTh)
GBSG2$tgrade1<- as.numeric(GBSG2$tgrade)
GBSG2$menostat1<- as.numeric(GBSG2$menostat)
#Add subject id
GBSG2$subjid<- 1:nrow(GBSG2)
#--- Run SurvCART() with time-to-event distribution: exponential, censoring distribution: None
out<- SurvCART(data=GBSG2, patid="subjid", censorvar="cens", timevar="time",
gvars=c('horTh1', 'age', 'menostat1', 'tsize', 'tgrade1', 'pnodes', 'progrec', 'estrec'),
tgvars=c(0,1,0,1,0,1, 1,1),
event.ind=1, alpha=0.05, minsplit=80, minbucket=40, print=TRUE)
#--- Plot tree
par(xpd = TRUE)
plot(out, compress = TRUE)
text(out, use.n = TRUE)
#Plot KM plot for sub-groups identified by tree
KMPlot(out, xscale=365.25, type=1)
KMPlot(out, xscale=365.25, type=2, overlay=FALSE, mfrow=c(2,2), xlab="Year", ylab="Survival prob.")
#--- Run SurvCART() with time-to-event distribution: weibull censoring distribution: None
out2<- SurvCART(data=GBSG2, patid="subjid", censorvar="cens", timevar="time",
gvars=c('horTh1', 'age', 'menostat1', 'tsize', 'tgrade1', 'pnodes', 'progrec', 'estrec'),
tgvars=c(0,1,0,1,0,1, 1,1),
time.dist="weibull", event.ind=1, alpha=0.05, minsplit=80, minbucket=40, print=TRUE)
#--- Run SurvCART() with time-to-event distribution: weibull censoring distribution: exponential
out<- SurvCART(data=GBSG2, patid="subjid", censorvar="cens", timevar="time",
gvars=c('horTh1', 'age', 'menostat1', 'tsize', 'tgrade1', 'pnodes', 'progrec', 'estrec'),
tgvars=c(0,1,0,1,0,1, 1,1),
time.dist="weibull", cens.dist="exponential", event.ind=1,
alpha=0.05, minsplit=80, minbucket=40, print=TRUE)
# }
Run the code above in your browser using DataLab