Centralized feature scaling and parameter unscaling routines used by NMAR estimation engines to ensure consistent, numerically stable behavior.
Provide an engine-agnostic API for standardizing design matrices and auxiliary moments before solving.
Return a minimal scaling recipe (nmar_scaling_recipe) used to
unscale coefficients and covariance matrices after solving.
Z_un (response model matrix with intercept),
optional X_un (auxiliary model matrix, no intercept),
optional named mu_x_un (auxiliary means on the original scale),
and a logical standardize flag.
Scaled matrices Z, X, and mu_x, plus an
nmar_scaling_recipe used later for unscaling.
Before solving: call validate_and_apply_nmar_scaling() (engine-level)
or prepare_nmar_scaling() (low-level) to obtain scaled matrices
and recipe.
Solve in the scaled space.
After solving: call unscale_coefficients() to unscale coefficients
and their covariance matrices.
Store the nmar_scaling_recipe in results for diagnostics and reproducibility.
The intercept column is never scaled.
Columns with near-zero variance are centered but assigned
sd = 1 so that the corresponding parameter is not inflated by
division by a very small standard deviation.
Engines may use design-weighted scaling via the weights and
weight_mask arguments.