% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/derive.R
\name{derive_timing}
\alias{derive_timing}
\title{Classify disease timing relative to UKB baseline assessment}
\usage{
derive_timing(data, name, baseline_col, status_col = NULL, date_col = NULL)
}
\arguments{
\item{data}{(data.frame or data.table) UKB phenotype data.}

\item{name}{(character) Output column prefix.  The new column is named
\code{{name}_timing}.  Also used to derive default \code{status_col}
and \code{date_col} when those are \code{NULL}.}

\item{baseline_col}{(character) Name of the baseline date column in
\code{data} (e.g. \code{"date_baseline"} or \code{"p53_i0"}).}

\item{status_col}{(character or NULL) Name of the logical disease flag.
\code{NULL} = \code{paste0(name, "_status")}.}

\item{date_col}{(character or NULL) Name of the disease date column
(\code{IDate} or \code{Date}).
\code{NULL} = \code{paste0(name, "_date")}.}
}
\value{
The input \code{data} with one new integer column
\code{{name}_timing} (0/1/2/\code{NA}) added in-place.
Always returns a \code{data.table}.
}
\description{
Assigns each participant an integer timing category based on whether their
disease date falls before or after the baseline visit date:
}
\details{
\describe{
\item{\code{0}}{No disease (\code{status_col} is \code{FALSE}).}
\item{\code{1}}{Prevalent - disease date on or before baseline.}
\item{\code{2}}{Incident - disease date strictly after baseline.}
\item{\code{NA}}{Case with missing date; timing cannot be determined.}
}

Call once per timing variable needed (e.g. once for the combined case,
once per individual source).
}
\examples{
\donttest{
dt <- ops_toy(n = 100)
derive_hes(dt, name = "htn", icd10 = "I10")
derive_timing(dt, name = "htn_hes",
              status_col   = "htn_hes",
              date_col     = "htn_hes_date",
              baseline_col = "p53_i0")
}
}
