% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/assoc.R
\name{assoc_lag}
\alias{assoc_lag}
\title{Cox regression lag sensitivity analysis}
\usage{
assoc_lag(
  data,
  outcome_col,
  time_col,
  exposure_col,
  lag_years = c(1, 2),
  covariates = NULL,
  base = TRUE,
  strata = NULL,
  conf_level = 0.95
)
}
\arguments{
\item{data}{(data.frame or data.table) Analysis dataset.}

\item{outcome_col}{(character) Event indicator column (0/1 or logical).}

\item{time_col}{(character) Follow-up time column (numeric, e.g. years).}

\item{exposure_col}{(character) One or more exposure variable names.}

\item{lag_years}{(numeric) One or more lag periods in the same units as
\code{time_col}. Default: \code{c(1, 2)}. Use \code{0} to include the
unfiltered full-cohort result as a reference.}

\item{covariates}{(character or NULL) Covariates for the Fully adjusted
model. When \code{NULL}, only Unadjusted (and Age and sex adjusted if
\code{base = TRUE}) are run.}

\item{base}{(logical) Auto-detect age and sex and include an Age and sex
adjusted model. Default: \code{TRUE}.}

\item{strata}{(character or NULL) Optional stratification variable passed to
\code{survival::strata()}.}

\item{conf_level}{(numeric) Confidence level for HR intervals.
Default: \code{0.95}.}
}
\value{
A \code{data.table} with one row per lag \eqn{\times} exposure
\eqn{\times} term \eqn{\times} model combination, containing all columns
produced by \code{\link{assoc_coxph}} plus:
\describe{
\item{\code{lag_years}}{The lag period applied (numeric).}
\item{\code{n_excluded}}{Number of participants excluded because their
follow-up time was less than \code{lag_years}.}
}
\code{lag_years} and \code{n_excluded} are placed immediately after
\code{model} in the column order.
}
\description{
Runs Cox proportional hazards models at one or more lag periods to assess
whether associations are robust to the exclusion of early events. For each
lag, participants whose follow-up time is less than \code{lag_years} are
removed from the analysis dataset; follow-up time is kept on its original
scale (not shifted). This mirrors the approach used in UK Biobank sensitivity
analyses to address reverse causation and detection bias.
}
\details{
Setting \code{lag_years = 0} (or including \code{0} in the vector) runs the
model on the full unfiltered cohort, providing a reference against which
lagged results can be compared.

The same three adjustment models produced by \code{\link{assoc_coxph}} are
available here (\strong{Unadjusted}, \strong{Age and sex adjusted},
\strong{Fully adjusted}).
}
\examples{
dt <- ops_toy(scenario = "association", n = 500)
dt <- dt[dm_timing != 1L]

res <- assoc_lag(
  data         = dt,
  outcome_col  = "dm_status",
  time_col     = "dm_followup_years",
  exposure_col = "p20116_i0",
  lag_years    = c(0, 1, 2),
  covariates   = c("bmi_cat", "tdi_cat"),
  base         = FALSE
)
res[, .(lag_years, n, n_excluded, HR, CI_lower, CI_upper, p_value)]
}
