Skip to contents

`survex::explain_survival()` wants a function that returns an N by T matrix of survival probabilities, one row per subject and one column per time. A tidymodels censored-regression workflow returns a nested tibble instead (`predict(type = "survival", eval_time = times)`). This unnests it and checks the shape, so it can be used as `predict_survival_function`: pass a function of `(model, newdata, times)` that calls `adapter_tidymodels_survex(model, newdata, times)`.

Usage

adapter_tidymodels_survex(workflow, new_data, times)

Arguments

workflow

A fitted tidymodels workflow (or any object whose `predict()` method accepts `new_data`, `type = "survival"` and `eval_time`).

new_data

Data frame of subjects.

times

Numeric vector of evaluation times (finite, non-negative, increasing; duplicates are not allowed). The columns of the result follow this order.

Value

A numeric matrix with `nrow(new_data)` rows and `length(times)` columns, column names the times as text. Values are probabilities between 0 and 1; a time a model cannot predict is an error, not `NA`.

See also

[explain_survival()]