| lgspline_cox | R Documentation |
Convenience wrapper that calls lgspline with the correct
family, weight, dispersion, score, and unconstrained-fit functions for
Cox proportional hazards regression. All standard lgspline arguments
(knots, penalties, constraints, parallel, etc.) are passed through.
lgspline_cox(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 = cox_family()
unconstrained_fit_fxn = unconstrained_fit_cox
glm_weight_function = cox_glm_weight_function
qp_score_function = cox_qp_score_function
dispersion_function = cox_dispersion_function
schur_correction_function = cox_schur_correction
need_dispersion_for_estimation = FALSE
estimate_dispersion = FALSE
standardize_response = FALSE
A formula interface is needed, e.g. lgspline_cox(t, y, ...) won't work,
unlike for ordinary lgspline.
An object of class "lgspline".
## Cox PH 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_cox(
time ~ spl(age_std),
data = lung,
status = event,
opt = FALSE,
K = 1
)
print(summary(fit))
plot(fit,
show_formulas = TRUE,
custom_response_lab = 'HR',
custom_predictor_lab = 'Standardized Age',
ylim = c(0, 5))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.