% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/assoc.R
\name{assoc_linear}
\alias{assoc_linear}
\alias{assoc_lm}
\title{Linear regression association analysis}
\usage{
assoc_linear(
  data,
  outcome_col,
  exposure_col,
  covariates = NULL,
  base = TRUE,
  conf_level = 0.95
)

assoc_lm(
  data,
  outcome_col,
  exposure_col,
  covariates = NULL,
  base = TRUE,
  conf_level = 0.95
)
}
\arguments{
\item{data}{(data.frame or data.table) Analysis dataset.}

\item{outcome_col}{(character) Name of the continuous numeric outcome column.}

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

\item{covariates}{(character or NULL) Covariate column names for the
\strong{Fully adjusted} model. Default: \code{NULL}.}

\item{base}{(logical) Include \strong{Unadjusted} and \strong{Age and sex
adjusted} models. Default: \code{TRUE}.}

\item{conf_level}{(numeric) Confidence level. Default: \code{0.95}.}
}
\value{
A \code{data.table} with one row per exposure \eqn{\times} term
\eqn{\times} model combination, and columns:
\describe{
\item{\code{exposure}}{Exposure variable name.}
\item{\code{term}}{Coefficient name (e.g. \code{"bmi_categoryObese"}).}
\item{\code{model}}{Ordered factor: \code{Unadjusted} <
\code{Age and sex adjusted} < \code{Fully adjusted}.}
\item{\code{n}}{Participants in model (after NA removal).}
\item{\code{beta}}{Regression coefficient (\eqn{\beta}).}
\item{\code{se}}{Standard error of \eqn{\beta}.}
\item{\code{CI_lower}}{Lower confidence bound.}
\item{\code{CI_upper}}{Upper confidence bound.}
\item{\code{p_value}}{t-test p-value.}
\item{\code{beta_label}}{Formatted string, e.g.
\code{"0.23 (0.05-0.41)"}.}
}
}
\description{
Fits one or more linear regression models for each exposure variable and
returns a tidy result table. By default, two standard adjustment models are
always included:
}
\details{
\itemize{
\item \strong{Unadjusted} - no covariates (crude).
\item \strong{Age and sex adjusted} - age + sex auto-detected from the
data via UKB field IDs (21022 and 31). Skipped with a warning if either
column cannot be found.
\item \strong{Fully adjusted} - the covariates supplied via the
\code{covariates} argument. Only run when \code{covariates} is non-NULL.
}

\strong{Outcome}: intended for continuous numeric variables. Passing a
binary (0/1) or logical column is permitted (linear probability model) but
will trigger a warning recommending \code{\link{assoc_logistic}} instead.

\strong{CI method}: based on the t-distribution via \code{confint.lm()},
which is exact under the normal linear model assumption. There is no
\code{ci_method} argument (unlike \code{\link{assoc_logistic}}) as profile
likelihood does not apply to \code{lm}.

\strong{SE column}: the standard error of \eqn{\beta} is included to
support downstream meta-analysis and GWAS-style summary statistics.
}
\examples{
dt <- ops_toy(scenario = "association", n = 500)

res <- assoc_linear(
  data         = dt,
  outcome_col  = "p21001_i0",
  exposure_col = "p20116_i0",
  covariates   = c("bmi_cat", "tdi_cat"),
  base         = FALSE
)
}
