Skip to contents

Fit the M-MOM structural model from predictions and error covariances.

Usage

fit_mmom(
  data_list,
  preliminary_moment_control = list(correction = "minimum", alpha = NULL),
  final_moment_control = list(correction = "minimum", alpha = NULL),
  backend = c("auto", "r", "rcpp")
)

Arguments

data_list

Either a list of per-person lists with fields outcome, predictors, err_x, err_y, and err_xy, or a matrix-style list with those same named fields. See Details for their dimensions.

preliminary_moment_control

Correction controls with correction ("minimum", "none", "custom", or "step_up"), alpha for custom correction, and optional step_up search settings described below.

final_moment_control

Controls for the final moment; same format as preliminary_moment_control. Each stage can use a different policy.

backend

Computation backend: "auto", "r", or "rcpp".

Value

An S7 class_mmom_fit object. Numerical failures use the same class.

Details

Inputs must be likelihood-only predictions with additive sampling-error covariances, not BLUPs with posterior covariances. Observed error-free variables have zero error variance and covariance. Matrix-style inputs may instead supply an outcome vector, predictor matrix, an error array (predictor by predictor by observation), an outcome-error variance vector, and an outcome/predictor-error covariance matrix.

Standard errors use the final modified predictor moment on both sides of the covariance expression, matching the manuscript and primary simulation. The covariance meat uses preliminary coefficients and squared inverse case-variance weights. Inference assumes the model-based normal-error covariance and conditions on fitted first-stage quantities. Measurement- model parameter uncertainty is not propagated. Reported intervals are normal-based 95% intervals. correction = "none" disables regularization, not measurement-error subtraction.

Step-up (M-MOMS): select the preliminary alpha, then recompute weights and select the final alpha. Each search starts at q + 2, where q is the number of predictor columns excluding the intercept. The upper bound is N when the determinant root exceeds 1 + 1/N, and N * lambda - 1 otherwise. A missing root or an upper bound below the minimum leaves only the minimum candidate. The default grid has nine equally spaced candidates, evaluated in ascending order only until the first pass. A passing minimum stops that stage immediately. Refine between the first passing candidate and its preceding failing candidate by at most 12 bisections, stopping at an alpha gap of 0.005. This finds the smallest passing alpha evaluated, not a global optimum.

A candidate must produce a usable complete fit. Its corrected predictor block (excluding the structural intercept) must have minimum eigenvalue at least sqrt(.Machine$double.eps), ratio of minimum corrected eigenvalue to maximum observed eigenvalue at least 0.05, and condition number at most 1e5. Following the research algorithm, preliminary moments are divided by N; final weighted moments are unnormalized sums. These are numerical search criteria, not guarantees of inferential validity or invariance to predictor scaling. If no candidate passes, retain the minimum-alpha fit, including its numerical failure if any, and explicitly mark the fallback. A returned fit need not meet the conditioning criteria.

The optional step_up list in either control accepts coarse_grid_size, search_tolerance, max_refinements, min_eigenvalue, min_relative_eigenvalue, max_condition_number, and candidate_alphas. Defaults are the values above and NULL for candidate_alphas. An explicit candidate vector is sorted, deduplicated, clipped to the search bounds, and augmented with the minimum; bisection still applies unless disabled. repair() accepts these settings in step_up_control. Requested policies remain in the saved controls; selected constants are alpha_prelim and alpha_final in diagnostics. diagnostics$step_up records each stage's bounds, selected candidate, all candidate checks, settings, and fallback. Candidate histories contain only evaluated points; unused larger grid values are omitted. Moment/root caching and early stopping preserve selected alphas, estimates, SEs, and complete-fit eligibility checks. Refitting and bootstrapping rerun selection on each new dataset.

Examples

data(repair_example)
growth <- lme4::lmer(score ~ day + (day | person), repair_example$repeated)
analysis <- repair_data(re("day") ~ practice, growth, repair_example$people, "person")
# Advanced interface: retain the entire joint error covariance.
manual <- fit_mmom(list(
  outcome = analysis@outcome, predictors = analysis@predictors,
  err_x = analysis@err_x, err_y = analysis@err_y, err_xy = analysis@err_xy
), backend = "r")
manual@converged
#> [1] TRUE
manual@coefficients
#>          term   estimate        se     zstat         pval     ci_low    ci_high
#> 1 (Intercept) -0.7895289 0.1147252 -6.881913 5.905407e-12 -1.0143862 -0.5646716
#> 2    practice  0.1754854 0.0214190  8.192979 2.548385e-16  0.1335049  0.2174659