View source: R/weibull_helpers.R
| lgspline_weibull | R Documentation |
Convenience wrapper that calls lgspline with the correct
family, weight, dispersion, score, and unconstrained-fit functions for
Weibull accelerated failure time regression. All standard lgspline
arguments (knots, penalties, constraints, parallel, etc.) are passed
through.
lgspline_weibull(formula, data, status, ...)
formula |
Formula specifying the model. The response should be
survival time; |
data |
Data frame. |
status |
Integer vector of event indicators (1 = event,
0 = censored), same length as the number of rows in |
... |
Additional arguments passed to |
Internally sets:
family = weibull_family()
unconstrained_fit_fxn = unconstrained_fit_weibull
glm_weight_function = weibull_glm_weight_function
qp_score_function = weibull_qp_score_function
dispersion_function = weibull_dispersion_function
schur_correction_function = weibull_schur_correction
need_dispersion_for_estimation = TRUE
estimate_dispersion = TRUE
standardize_response = FALSE
A formula interface is needed, e.g. lgspline_weibull(t, y, ...) won't work,
unlike for ordinary lgspline.
An object of class "lgspline".
lgspline_cox for Cox proportional hazards,
weibull_family, unconstrained_fit_weibull
## Weibull AFT with a nonlinear age effect on lung cancer survival
if(requireNamespace("survival", quietly = TRUE)) {
library(survival)
set.seed(1234)
lung <- na.omit(lung[, c("time", "status", "age")])
lung$age_std <- std(lung$age)
## survival codes status as 1 = censored, 2 = dead
event <- as.integer(lung$status == 2)
## Spline on age
fit <- lgspline_weibull(
time ~ spl(age_std),
data = lung,
status = event,
K = 1,
opt = FALSE,
wiggle_penalty = 1e-4,
flat_ridge_penalty = 1
)
print(summary(fit))
plot(fit,
show_formulas = TRUE,
custom_response_lab = 'Survival Time',
custom_predictor_lab = 'Standardized Age')
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.