MixedEffectResults#
- class mmer.MixedEffectResults(model)[source]#
Bases:
objectMixedEffectRegressor fitted model results and inference interface.
Provides convenient access to fitted model components, variance estimates, and methods for prediction and random effect estimation.
- Variables:
model (MixedEffectRegressor) – The source model instance.
fe_model (RegressorMixin) – Fitted fixed effects model.
m (int) – Number of output responses.
k (int) – Number of grouping factors.
random_effect_terms (list of RandomEffectTerm) – Learned random effect states.
residual_term (ResidualTerm) – Learned residual state.
log_likelihood (list) – History of log-likelihood values during training.
- Parameters:
model (MixedEffectRegressor)
- predict(X)[source]#
Predict using fixed effects component only.
Makes predictions using only the learned fixed effects model, ignoring random effects. For predictions that include random effects, use compute_random_effects() and add the total effect to predictions.
- Parameters:
X (np.ndarray) – Covariates for prediction, shape (n, p).
- Returns:
predictions – Predicted values from fixed effects only, shape (n, m).
- Return type:
np.ndarray
Notes
Current implementation does not support random effects in prediction. To obtain predictions including random effects:
Call compute_random_effects() to get random effect estimates
Add total_effect to fixed effect predictions
Examples
>>> # Predict with fixed effects only >>> y_pred = results.predict(X_new)
>>> # Predict with both fixed and random effects >>> y_fixed = results.predict(X_new) >>> _, total_re, _ = results.compute_random_effects(X_new, y_new, groups_new) >>> y_pred_full = y_fixed + total_re
- compute_random_effects(X, y, groups)[source]#
Estimate posterior random effects for new or existing data.
- Parameters:
X (np.ndarray) – Features, shape (n, p).
y (np.ndarray) – Targets, shape (n, m).
groups (np.ndarray) – Grouping factors, shape (n, k).
- Returns:
residuals (np.ndarray) – Estimated residuals after accounting for fixed and random effects.
total_effect (np.ndarray) – Total estimated random effects.
mu (tuple of np.ndarray) – Estimated random effects for each grouping factor.
- property residual_covariance: ndarray#
Get the estimated residual covariance matrix.
- property random_effects_covariances: tuple[ndarray]#
Get the estimated covariance matrices for each random effect grouping factor.
- static cov_to_corr(cov)[source]#
Convert a covariance matrix to a correlation matrix. Protects against zero variances for numerical stability.
- Parameters:
cov (ndarray)
- Return type:
ndarray
- property residual_correlation: ndarray#
Get the estimated residual correlation matrix.
- property random_effects_correlations: tuple[ndarray]#
Get the estimated correlation matrices for each random effect grouping factor.
- get_marginal_correlation(slope_covariates=None)[source]#
Compute the total marginal correlation matrix (m x m) for a single observation profile.
- Parameters:
slope_covariates (list of np.ndarray or None, optional) – List of 1D arrays containing random slope covariates for each grouping factor. Omit the intercept (1.0) as it is automatically included.
- Returns:
corr – Total marginal correlation matrix.
- Return type:
np.ndarray
- get_marginal_covariance(slope_covariates=None)[source]#
Compute the total marginal covariance matrix (m x m) for a single observation profile.
- Parameters:
slope_covariates (list of np.ndarray or None, optional) – List of 1D arrays containing random slope covariates for each grouping factor. Omit the intercept (1.0) as it is automatically included. If a group has only a random intercept, pass None or an empty array for that group. If entirely None, assumes random intercepts only for all groups.
- Returns:
cov – Total marginal covariance matrix combining residuals and random effects.
- Return type:
np.ndarray