-
Notifications
You must be signed in to change notification settings - Fork 3
/
examples.R
40 lines (30 loc) · 1.03 KB
/
examples.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
library(randomForestSRC)
library(gbm)
library(survivalmodels)
library(survival)
library(pec)
library(riskRegression)
library(satpred); satpredtheme()
## Implemented methods
### rfsrc.satpred: random survival forest
### gbm.satpred: gradient boosted trees
### deepsurv.satpred: survival neural network
## Survival forest
### Cross-validation
params_rfsrc <- expand.grid(mtry = c(4, 5, 6), nodesize = c(5, 10,15), ntree=c(800, 1000, 1200))
tuned_rfsrc <- modtune(Surv(time, status) ~ ., train_df, param_grid = params_rfsrc
, modfun = rfsrc.satpred, parallelize = TRUE, seed = 8888
)
plot(tuned_rfsrc)
### Fit model
fit_rfsrc <- modfit(tuned_rfsrc, return_data = FALSE)
### Individual survival curves
scurves_rfsrc <- get_indivsurv(fit_rfsrc, train_df)
plot(scurves_rfsrc)
### Concordance score
concord_rfsrc <- get_survconcord(fit_rfsrc)
print(concord_rfsrc)
### Permutation variable importance
vimp_rfsrc <- get_varimp(fit_rfsrc, type = "perm", newdata = train_df, nrep = 20, modelname = "rfsrc")
plot(vimp_rfsrc)
### Predictive performance