Fit survival models to estimate exposure-specific hazards for G-computation approach
Source:R/fit_models.R
fit_model_0.Rd
fit_model_0()
fits a Cox model to estimate risk for unexposed
individuals on the original time scale. Includes all individuals, censoring
exposed individuals at their time of exposure. By default, model is adjusted for by
<covariates>
, included as simple linear terms.
fit_model_1()
fits a Cox model to estimate risk for exposed individuals on
the time scale of time since exposure. Includes exposed individuals who
remain at risk tau
days after exposure. Individuals are additionally
censored at censor_time
days after exposure to avoid extrapolation beyond
the time period of interest. By default, model is adjusted for
<covariates>
, included as simple linear terms, and exposure time is included as a
natural cubic spline with 4 degrees of freedom.
Usage
fit_model_0(
data,
outcome_time,
outcome_status,
exposure,
exposure_time,
covariates,
formula_0 = NULL
)
fit_model_1(
data,
outcome_time,
outcome_status,
exposure,
exposure_time,
covariates,
tau,
censor_time = NULL,
formula_1 = NULL
)
Arguments
- data
A data frame with one row per individual containing the columns named in
outcome_time
,outcome_status
,exposure
,exposure_time
, and any variables listed incovariates
.- outcome_time
Name of the time-to-event/censoring variable. Time should be measured from a given time origin (e.g. study start, enrollment, or age) for all individuals.
- outcome_status
Name of the event indicator. The underlying column should be numeric (
1
= event,0
= censored).- exposure
Name of the exposure indicator. The underlying column should be numeric (
1
= exposed during follow-up,0
= never exposed during follow-up).- exposure_time
Name of the time to exposure, measured from the chosen time origin; use
NA
if not exposed. Time must be measured in the same units (e.g. days) as that used foroutcome_time
.- covariates
Character vector of covariates to adjust for when fitting the hazard models. These covariates should include all known confounders of exposure and censoring measured at the chosen time origin.
- formula_0
Optional right hand side of the formula for model 0. By default, uses
covariates
.- tau
Non-negative numeric value specifying the time after exposure that should be excluded from the risk evaluation period. This argument is primarily intended for vaccination exposures, where it is common to exclude the time after vaccination when immunity is still building. Time must be measured in the same units as that used for
outcome_time
andexposure_time
and should reflect the biological understanding of when vaccine-induced immunity develops (usually 1-2 weeks). For non-vaccine exposures,tau
can be set to 0 (no delay period).- censor_time
Time after exposure at which exposed individuals are censored during model fitting to prevent extrapolation. By default, no censoring is applied.
- formula_1
Optional right hand side of the formula for model 1. By default, uses
covariates
plus natural spline of vaccination day (4 df). DefaultNULL
Value
A fitted coxph
object with additional component $data
containing
the analysis dataset used for fitting:
For
fit_model_0()
: includes the survival tuple(Y
,event
) and covariates adjusted for in model, whereY
is the time from time origin to first of endpoint, censoring or exposure time (for exposed individuals).For
fit_model_1()
: includes the survival tuple(T1
,event
),<exposure_time>
, and covariates adjusted for in model, whereT1
is the time from exposure to endpoint or censoring, with additional censoring bycensor_time
. Only includes exposed individuals at risktau
days after exposure.