build_cox_formula: Build Cox Model Formula

View source: R/Cox_estimation_helpers.R

build_cox_formulaR Documentation

Build Cox Model Formula

Description

Constructs a Cox model formula from variable names, optionally adjusted for additional covariates.

Usage

build_cox_formula(
  outcome.name,
  event.name,
  treat.name,
  adjust_covariates = NULL
)

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 as strata() and pspline() may be used directly, e.g. adjust_covariates = "strata(x1)" produces a stratified Cox model rather than including x1 as 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")
build_cox_formula("time_months", "event", "treat",
                  adjust_covariates = c("strata(site)", "age"))

forestsearch documentation built on Nov. 15, 2026, 9:06 a.m.