Contents
LinearRegression
Gaussian linear-regression family for associate$regression()
Fits Gaussian linear models with stats::lm() for continuous outcomes.
associate$regression instantiates this family for
model = "lm", which is also what model = "auto" falls back to when the
outcome is neither a survival descriptor nor binary.
Details
The fitted model is outcome ~ predictor [* interaction] [+ covariates] on
complete cases, with case weights when the resolved frame carries a weights
column. Covariate adjustment, split.by strata and one
predictor-by-modifier interaction are all handled through the engine fit
grid rather than inside this class.
Result rows follow the "lm" association schema (schemaLm() in
associate-schemas.R): one row per predictor main and interaction
coefficient, on the identity scale (effect.scale = "identity",
test = "t"), with Wald limits from the residual-df t distribution and n
from stats::nobs().
The single artifact is prediction.grid: fitted values with standard errors
across the observed predictor range -- grid.resolution equally spaced
points for a numeric predictor, the observed levels otherwise -- holding
covariates at their reference values.
Super class
PolyGenius::RegressionFamily -> LinearRegression
Methods
Public methods
LinearRegression$new()LinearRegression$prepare.frame()LinearRegression$describe.model.terms()LinearRegression$build.formula()LinearRegression$fit.model()LinearRegression$build.summary.rows()LinearRegression$build.artifacts()LinearRegression$clone()
Method new()
Register this family under the key "lm".
Usage
LinearRegression$new()
Returns
A new LinearRegression.
Method prepare.frame()
Reduce the resolved frame to the columns this fit uses and drop rows missing any of them.
Usage
LinearRegression$prepare.frame(frame, cell, fit.specs, conf.level)
Arguments
frame — A data.table resolved from a PolyGeniusStudy, whose
roles() tags identify the outcome, predictor, interaction, covariate
and weight columns.
cell — Named list describing one fit cell. Unused; columns come
from the frame's roles.
fit.specs — Named list of extra fitting options. Unused.
conf.level — Numeric scalar in (0, 1). Unused.
Returns
Named list: data (complete-case data.frame), outcome.name,
predictor.name, predictor.label, interaction.name,
covariate.names, weights.name (NA_character_ when none) and
row.id, the retained row indices into frame.
Method describe.model.terms()
Extend the shared right-hand-side term descriptors with the continuous outcome, whose estimability fails when it has no variance.
Usage
LinearRegression$describe.model.terms(fit.data)
Arguments
fit.data — Named list returned by prepare.frame().
Returns
List of list(column, role, label) descriptors: the base class's
terms plus one with role = "outcome.continuous".
Method build.formula()
Build outcome ~ predictor [* interaction] [+ covariates]
from the original column names.
Usage
LinearRegression$build.formula(frame)
Arguments
frame — Named list returned by prepare.frame().
Returns
A formula, carrying its printable form as the
"display.formula" attribute.
Method fit.model()
Fit the model with stats::lm(), adding case weights when
prepare.frame() resolved a weights column.
Usage
LinearRegression$fit.model(formula, frame, ...)
Arguments
formula — A formula from build.formula().
frame — Named list returned by prepare.frame().
... — Further arguments passed to stats::lm().
Returns
A fitted lm object.
Method build.summary.rows()
Turn the fitted model's predictor coefficients into standard result rows on the identity scale.
Usage
LinearRegression$build.summary.rows(
fit,
fit.data,
cell,
fit.specs,
conf.level,
formula
)
Arguments
fit — A fitted lm object.
fit.data — Named list returned by prepare.frame().
cell — Named list describing one fit cell: fit.id, analysis.id,
family, outcome, predictor, interaction, stratum.
fit.specs — Named list of extra fitting options. Unused.
conf.level — Numeric scalar in (0, 1). Confidence level for
lower/upper, taken from the residual-df t distribution.
formula — Character scalar. Display formula recorded on each row.
Returns
A data.table of "lm"-schema rows, one per predictor main and
interaction coefficient. Aborts when no coefficient name matches the
predictor.
Method build.artifacts()
Build the fitted-value grid that effect plots read.
Usage
LinearRegression$build.artifacts(
fit,
fit.data,
cell,
fit.specs,
conf.level,
formula
)
Arguments
fit — A fitted lm object.
fit.data — Named list returned by prepare.frame().
cell — Named list describing one fit cell.
fit.specs — Named list of extra fitting options. Unused.
conf.level — Numeric scalar in (0, 1). Unused.
formula — Character scalar. Unused; present for interface parity.
Returns
Named list with one element, prediction.grid: a data.frame of
predictor.value, fitted.value and se alongside the fit identity
columns (analysis.id, fit.id, schema, family, outcome,
predictor, stratum).
Method clone()
The objects of this class are cloneable with this method.
Usage
LinearRegression$clone(deep = FALSE)
Arguments
deep — Whether to make a deep clone.
Examples
# Continuous outcome; this is what model = "auto" resolves to here
associate$regression(data, outcomes = bmi, predictors = PRS_BMI,
covariates = c(age, sex))
# Forced, for a 0/1 outcome that would otherwise resolve to "glm"
associate$regression(data, outcomes = affected, predictors = PRS_AD,
model = "lm")See Also
associate$regression, LogisticRegression for binary outcomes, CoxRegression and CompetingRiskRegression for survival outcomes.
Other regression-families:
CompetingRiskRegression,
CoxRegression,
KaplanMeierRegression,
LogisticRegression,
RegressionFamily