| fit | R Documentation |
The entry point of the survalis verb interface. fit() selects a learner by
id, passes engine arguments through spec, and returns a survalis_fit
object that the other verbs (predict(), evaluate(), tune(), interpret(),
estimate()) consume.
fit(formula, data, model, spec = list(), seed = NULL, ...)
formula |
A survival formula with a |
data |
A data frame containing the formula variables. |
model |
A learner id from |
spec |
A named list of engine arguments forwarded to the learner's
fitting routine (for example |
seed |
Optional integer seed set immediately before fitting, for learners with a stochastic training step. |
... |
Not used; engine arguments passed here give an error. Use |
An object of class c("survalis_fit", "mlsurv_model") with elements
model, learner, engine, formula, data, time, status,
model_id, and spec.
predict.survalis_fit(), evaluate(), tune(), compare(),
interpret(), estimate(), listlearners()
m <- fit(Surv(time, status) ~ age + karno + celltype, veteran,
model = "ranger", spec = list(num.trees = 200))
m
# A custom learner: an exponential AFT model from survival::survreg
expo <- list(
name = "exponential",
fit = function(formula, data, ...) survival::survreg(formula, data, dist = "exponential"),
predict = function(object, newdata, times) {
rate <- 1 / predict(object, newdata, type = "response")
exp(-outer(rate, times))
}
)
m2 <- fit(Surv(time, status) ~ age + karno, veteran, model = expo)
predict(m2, veteran[1:3, ], times = c(90, 180))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.