隨機森林生存分析與 randomForestSRC

正如隨機森林演算法可以應用於迴歸和分類任務一樣,它也可以擴充套件到生存分析。

在下面的示例中,生存模型適合並使用來自 CRAN 的包 randomForestSRC 進行預測,評分和效能分析。

require(randomForestSRC)

set.seed(130948) #Other seeds give similar comparative results
x1   <- runif(1000)
y    <- rnorm(1000, mean = x1, sd = .3)
data <- data.frame(x1 = x1, y = y)
head(data)
         x1          y
1 0.9604353  1.3549648
2 0.3771234  0.2961592
3 0.7844242  0.6942191
4 0.9860443  1.5348900
5 0.1942237  0.4629535
6 0.7442532 -0.0672639
(modRFSRC <- rfsrc(y ~ x1, data = data, ntree=500, nodesize = 5))
                             Sample size: 1000
                     Number of trees: 500
          Minimum terminal node size: 5
       Average no. of terminal nodes: 208.258
No. of variables tried at each split: 1
              Total no. of variables: 1
                            Analysis: RF-R
                              Family: regr
                      Splitting rule: mse
                % variance explained: 32.08
                          Error rate: 0.11
x1new   <- runif(10000)
ynew    <- rnorm(10000, mean = x1new, sd = .3)
newdata <- data.frame(x1 = x1new, y = ynew)

survival.results <- predict(modRFSRC, newdata = newdata)
survival.results
  Sample size of test (predict) data: 10000
                Number of grow trees: 500
  Average no. of grow terminal nodes: 208.258
         Total no. of grow variables: 1
                            Analysis: RF-R
                              Family: regr
                % variance explained: 34.97
                 Test set error rate: 0.11