Skip to content

Added ranger survival c.f. issue #3 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion survival-analysis/README.Rmd
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ library(rpart)
library(pec)
library(ipred)
library(randomForestSRC)
library(ranger)
library(mboost)
library(tidymodels)
library(cli)
@@ -388,6 +389,34 @@ although these values do not bracket the observed times:
summary(train_dat$time)
```

### `ranger:::`[`ranger`](https://rdrr.io/cran/ranger/man/ranger.html)

```{r, ranger_fit}
library(ranger)
ranger_mod <- ranger(Surv(time, status) ~ X1 + X2, data = train_dat, num.trees = 1000)
```

The `predict` function generates an object with class `"ranger.prediction"`.

```{r, ranger_pred}
ranger_pred = predict(ranger_mod, test_pred)
str(ranger_pred)
```

The `unique.death.times` slot has the unique death times:

```{r, }
all(sort(unique(train_dat$time)) == ranger_pred$unique.death.times)
```

The `survival` slot contains a matrix of predicted survival curves, with a row for each test case and a column for each death time. The `chf` slot is the same for the cumulative hazard function:

```{r, ranger_surv}
ranger_pred$survival[, 1:5]
ranger_pred$chf[, 1:5]
```


# Model Prediction Scorecard

In most cases, the open circle means that this type of prediction is facilitated _indirectly_. For example, using "tricks" related to `survfit()`, methods in the `pec` package, or other means.
@@ -409,7 +438,8 @@ pred_types <-
"`ipred`", "`bagging`", yep, kinda, nope,
"`party`", "`ctree`", yep, kinda, nope,
"`party`", "`cforest`", yep, kinda, nope,
"`randomForestSRC`", "`rfsrc`", yep, kinda, nope
"`randomForestSRC`", "`rfsrc`", yep, kinda, nope,
"`ranger`", "`ranger`", kinda, yep, nope
)

pred_types %>%
70 changes: 70 additions & 0 deletions survival-analysis/README.md
Original file line number Diff line number Diff line change
@@ -659,6 +659,69 @@ summary(train_dat$time)
0.44 2.83 4.89 5.55 7.38 20.19
```

### `ranger:::`[`ranger`](https://rdrr.io/cran/ranger/man/ranger.html)


```r
library(ranger)
ranger_mod <- ranger(Surv(time, status) ~ X1 + X2, data = train_dat, num.trees = 1000)
```

The `predict` function generates an object with class `"ranger.prediction"`.


```r
ranger_pred = predict(ranger_mod, test_pred)
str(ranger_pred)
```

```
List of 7
$ num.trees : num 1000
$ num.independent.variables: num 2
$ unique.death.times : num [1:200] 0.435 0.537 0.549 0.603 0.635 ...
$ num.samples : int 2
$ treetype : chr "Survival"
$ chf : num [1:2, 1:200] 0 0.172 0 0.172 0 ...
$ survival : num [1:2, 1:200] 1 0.842 1 0.842 1 ...
- attr(*, "class")= chr "ranger.prediction"
```

The `unique.death.times` slot has the unique death times:


```r
all(sort(unique(train_dat$time)) == ranger_pred$unique.death.times)
```

```
[1] TRUE
```

The `survival` slot contains a matrix of predicted survival curves, with a row for each test case and a column for each death time. The `chf` slot is the same for the cumulative hazard function:


```r
ranger_pred$survival[, 1:5]
```

```
[,1] [,2] [,3] [,4] [,5]
[1,] 1.000 1.000 1.000 1.000 1.000
[2,] 0.842 0.842 0.842 0.842 0.842
```

```r
ranger_pred$chf[, 1:5]
```

```
[,1] [,2] [,3] [,4] [,5]
[1,] 0.000 0.000 0.000 0.000 0.000
[2,] 0.172 0.172 0.172 0.172 0.172
```


# Model Prediction Scorecard

In most cases, the open circle means that this type of prediction is facilitated _indirectly_. For example, using "tricks" related to `survfit()`, methods in the `pec` package, or other means.
@@ -744,6 +807,13 @@ In most cases, the open circle means that this type of prediction is facilitated
<td style="text-align:left;"> ◯ </td>
<td style="text-align:left;"> x </td>
</tr>
<tr>
<td style="text-align:left;"> `ranger` </td>
<td style="text-align:left;"> `ranger` </td>
<td style="text-align:left;"> ◯ </td>
<td style="text-align:left;"> ✓ </td>
<td style="text-align:left;"> x </td>
</tr>
</tbody>
</table>