% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/derive.R
\name{derive_followup}
\alias{derive_followup}
\title{Compute follow-up end date and follow-up time for survival analysis}
\usage{
derive_followup(
  data,
  name,
  event_col,
  baseline_col,
  censor_date,
  death_col = NULL,
  lost_col = NULL
)
}
\arguments{
\item{data}{(data.frame or data.table) UKB phenotype data.}

\item{name}{(character) Output column prefix, e.g. \code{"outcome"} produces
\code{outcome_followup_end} and \code{outcome_followup_years}.}

\item{event_col}{(character) Name of the outcome event date column
(e.g. \code{"outcome_date"}).}

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

\item{censor_date}{(Date or character) Scalar administrative censoring date,
e.g. \code{as.Date("2022-06-01")}.  A character string in
\code{"YYYY-MM-DD"} format is also accepted.}

\item{death_col}{(character or NULL) Name of the death date column
(UKB field 40000).  \code{NULL} (default) triggers auto-detection via
the \code{\link{extract_ls}} cache; pass \code{FALSE} to explicitly
disable death as a competing end-point.}

\item{lost_col}{(character or NULL) Name of the lost-to-follow-up date
column (UKB field 191).  \code{NULL} (default) triggers auto-detection;
pass \code{FALSE} to explicitly disable.}
}
\value{
The input \code{data} with two new columns added in-place:
\code{{name}_followup_end} (IDate) and \code{{name}_followup_years}
(numeric).
}
\description{
Adds two columns to \code{data}:
\itemize{
\item \code{{name}_followup_end} (IDate) - the earliest of the outcome
event date, death date, lost-to-follow-up date, and the administrative
censoring date.
\item \code{{name}_followup_years} (numeric) - time in years from
\code{baseline_col} to \code{{name}_followup_end}.
}
}
\details{
\strong{data.table pass-by-reference}: when the input is a
\code{data.table}, new columns are added in-place via \code{:=}.
}
\examples{
\donttest{
dt <- ops_toy(n = 100)
derive_hes(dt, name = "htn", icd10 = "I10")
derive_followup(dt,
  name         = "htn_hes",
  event_col    = "htn_hes_date",
  baseline_col = "p53_i0",
  censor_date  = as.Date("2022-06-01"),
  death_col    = "p40000_i0",
  lost_col     = FALSE)
}
}
