-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomForestSRC.qmd
86 lines (48 loc) · 1.18 KB
/
randomForestSRC.qmd
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
title: "randomForestSRC"
format: html
---
## randomForestSRC 笔记
此处记录一个较为详细的随机生存森林分析的流程。
包括模型的构建结果解读,对应的KM曲线绘制,time-dependent ROC曲线,校准曲线,决策曲线等。
### 首先是加载所需要的R包
```{r, include=FALSE}
library(randomForestSRC)
library(vip)
```
2231个样本,41个变量的数据集。
```{r}
data(peakVO2)
```
```{r}
set.seed(42)
split_index <- caret::createDataPartition(peakVO2$ttodead,
p = 0.8,
list = FALSE
)
df_train <- peakVO2[split_index, ]
df_test <- peakVO2[-split_index, ]
```
*并行设置:*
```{r}
```
### 模型构建和结果解读
```{r}
obj <- randomForestSRC::rfsrc(Surv(ttodead, died)~., df_train,
ntree = 1000,
nodesize = 5,
nsplit = 50,
importance = TRUE)
print(obj)
```
*interpret: *
### 模型评价
C-index
```{r}
get.cindex(obj$yvar[,1], obj$yvar[,2], obj$predicted.oob)
```
### 重要变量筛选
重要变量。
```{r}
vip::vip(object = obj)
```