Constructs a Cox model formula from variable names, optionally adjusted for additional covariates.
Arguments
- outcome.name
Character. Name of outcome variable.
- event.name
Character. Name of event indicator variable.
- treat.name
Character. Name of treatment variable.
- adjust_covariates
This option is implemented but has not been tested against the manuscript analyses or the simulation studies of León and Anderson (2026a, 2026b), which use the unadjusted treatment-only fits. Character vector or
NULL. Additional model terms appended to the right-hand side after the treatment term. Terms are pasted verbatim, so survival modelling functions such asstrata()andpspline()may be used directly, e.g.adjust_covariates = "strata(x1)"produces a stratified Cox model rather than includingx1as a linear covariate.NULL(default) reproduces the unadjusted, treatment-only formula.
Value
An R formula object for Cox regression. When adjust_covariates
is supplied, the treatment term is always placed first on the
right-hand side.
Examples
build_cox_formula("time_months", "event", "treat")
#> Surv(time_months, event) ~ treat
#> <environment: 0x64d868718a80>
build_cox_formula("time_months", "event", "treat",
adjust_covariates = c("strata(site)", "age"))
#> Surv(time_months, event) ~ treat + strata(site) + age
#> <environment: 0x64d866f0cd40>