
Estimate a single outcome linear mixed model and extract statistics
Source:R/lmm_helpers.R
single_lmm.RdFits a linear mixed model to a single vertex outcome using lme4::lmer() and
extracts fixed effects and model fit statistics. This function
is called repeatedly across all cortical vertices during vertex-wise
analysis in the run_vw_lmm2() pipeline.
Arguments
- imp
A data.frame containing the phenotype dataset (in verywise format).
- y
A numeric vector of outcome values representing a single vertex from the super-subject matrix.
- y_name
String with the outcome name (as specified in the formula)
- model_formula
A model formula object. This should specify a linear mixed model
lme4syntax. Example:vw_thickness ~ age * sex + site + (1|participant_id).- REML
Logical specifying whether to optimize the REML criterion (as opposed to the log-likelihood). Default: TRUE. Use
REML = FALSEif you intend to do model comparison (using AIC output).- lmm_control
Optional list (of correct class, resulting from
lme4::lmerControl()containing control parameters to be passed tolme4::lmer()(e.g. optimizer choice, convergence criteria, see the?lmerControldocumentation for details. Default: (uses default settings).- weights
Optional string or numeric vector of weights for the linear mixed model. You can use this argument to specify inverse-probability weights. If this is a string, the function look for a column with that name in the phenotype data. Note that these are not normalized or standardized in any way. Default:
NULL(no weights).
Value
A named list with one of two shapes:
On error:
errorcharacter(1). The error message produced bylme4::refit().
On success:
statsA
data.framewith columnsterm(character),qhat(numeric, fixed-effect estimate), andse(numeric, standard error), one row per fixed-effect term.residNamed numeric vector of model residuals from
stats::residuals(), used downstream for smoothness estimation.model_fitUnnamed numeric vector of length 5 containing, in order:
is_singular(0/1),AIC,ICC,R2_marginal,R2_conditional.warningcharactervector of any warning or message strings captured during refitting. Zero-length if none occurred. Singular-fit boundary warnings are suppressed from this vector when singularity is already flagged inmodel_fit.
See also
run_vw_lmm2() for the main interface.