Skip to contents

Add (or override) an estimator in the method registry. The fit closure receives (formula, data, ...) and returns a list with raw (the backend fit), coef, vcov, loglik, n, n_events, kind and backend, and optionally ratio_type ("HR", "TR" or "OR": how sest_tidy() reads an exponentiated coefficient) and aux_pars (the names of baseline parameters, which get no ratio).

Usage

sest_register(name, kind, backend, fit, note = "")

Arguments

name

Character key, e.g. "weibull".

kind

Character family: "parametric", "spline", "nonparametric", "cox", "frailty", "competing", "recurrent", "cure" or "interval". Survival curves, restricted means, scores and contrasts are computed for flexsurv, Cox (survival::coxph()) and Kaplan-Meier (survival::survfit()) backend objects, whatever the kind; for other backend objects they are refused.

backend

Character name of the backend package the fit closure needs (checked via requireNamespace() before the fit runs).

fit

A function (formula, data, ...) returning the normalised list.

note

Character one-line description (shown by sest_methods()).

Value

Invisibly, the method name.

See also

sest_methods() to list what is registered.

Other method-registry: sest_contract(), sest_methods(), sest_validate_method()

Examples

# An exponential model from survival::survreg(): an accelerated failure
# time model, so exp(coefficient) is a time ratio; the intercept is a
# baseline parameter.
sest_register("exp_survreg", "parametric", "survival",
  fit = function(formula, data, ...) {
    raw <- survival::survreg(formula, data = data, dist = "exponential", ...)
    list(raw = raw, coef = stats::coef(raw), vcov = stats::vcov(raw),
         loglik = as.numeric(stats::logLik(raw)),
         n = nrow(data), n_events = sum(data$status == 2),
         kind = "parametric", backend = "survival",
         ratio_type = "TR", aux_pars = "(Intercept)")
  })
fit <- survestimand(survival::Surv(time, status) ~ age, survival::lung,
                    method = "exp_survreg")
sest_tidy(fit)
#>          term component   estimate   std_error ratio_type     ratio  conf_low
#> 1 (Intercept) auxiliary  7.1396608 0.580709594       <NA>        NA        NA
#> 2         age covariate -0.0174867 0.009093293         TR 0.9826653 0.9653069
#>   conf_high
#> 1        NA
#> 2  1.000336