% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/derive.R
\name{derive_age}
\alias{derive_age}
\title{Compute age at event for one or more UKB outcomes}
\usage{
derive_age(
  data,
  name,
  baseline_col,
  age_col,
  date_cols = NULL,
  status_cols = NULL
)
}
\arguments{
\item{data}{(data.frame or data.table) UKB phenotype data.}

\item{name}{(character) One or more output prefixes, e.g.
\code{c("disease", "disease_icd10", "outcome")}. Each produces \code{age_at_{name}}.}

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

\item{age_col}{(character) Name of the age-at-baseline column
(e.g. \code{"age_recruitment"}).}

\item{date_cols}{(character or NULL) Named character vector mapping each
name to its event date column, e.g.
\code{c(disease = "disease_date", outcome = "outcome_date")}. \code{NULL} (default)
triggers auto-detection as \code{{name}_date}.}

\item{status_cols}{(character or NULL) Named character vector mapping each
name to its status column. \code{NULL} (default) triggers auto-detection.}
}
\value{
The input \code{data} with one new \code{age_at_{name}} column
per entry in \code{name}, added in-place.
}
\description{
For each name in \code{name}, adds one column \code{age_at_{name}} (numeric,
years) computed as:
\deqn{age\_at\_event = age\_col + (event\_date - baseline\_date) / 365.25}
}
\details{
The value is \code{NA} for participants who did not experience the event
(status is \code{FALSE} / \code{0}) or who lack an event date.

\strong{Auto-detection per name} (when \code{date_cols} / \code{status_cols}
are \code{NULL}):
\itemize{
\item \code{date_col}   - looked up as \code{{name}_date}.
\item \code{status_col} - looked up first as \code{{name}_status}, then
as \code{{name}} (logical column); if neither exists all rows with a
non-\code{NA} date are treated as cases.
}

\strong{data.table pass-by-reference}: new columns are added in-place.
}
\examples{
dt <- ops_toy(scenario = "association", n = 100)
derive_age(dt, name = "dm", baseline_col = "p53_i0", age_col = "p21022")
}
