EnsembleMixedModel#
- class mmer.EnsembleMixedModel(models)[source]#
Bases:
objectEnsemble Wrapper for Independently Fitted Mixed-Effects Models.
Aggregates multiple independently fitted MixedModel instances to quantify epistemic uncertainty (model uncertainty) in predictions, group effects, and variance components.
- Parameters:
models (list of MixedModel) – The collection of previously fitted MixedModel instances.
- Variables:
models (list of MixedModel) – The collection of previously fitted MixedModel instances.
n_models (int) – The number of sub-models in the ensemble.
n_responses (int) – The number of response variables.
n_groups (int) – The number of grouping factors.
- predict(X, groups=None)[source]#
Aggregate predictions across all ensemble models, incorporating personalized random effects if known.
This method works identically to MixedModel.predict, but it evaluates the test data against every individual model in the ensemble. It then aggregates the point predictions to form the expected value, and computes the standard deviation across models to quantify epistemic uncertainty.
- Parameters:
X (ndarray of shape (n_samples, n_features)) – The fixed-effects design matrix.
groups (ndarray of shape (n_samples, n_groups), optional) – The categorical grouping factors. If provided, models will attempt a dictionary lookup to add their individually learned Best Linear Unbiased Predictors (BLUPs) to the prediction.
- Returns:
An estimate object containing: - value: The expected (mean) prediction across the ensemble. - std: The epistemic standard deviation representing model disagreement.
- Return type:
Estimate
- property R: Estimate#
The expected residual covariance matrix and its epistemic standard deviation.
- property G: list[Estimate]#
The expected covariance matrix and epistemic standard deviation for each group.
- infer(X, y, groups)[source]#
Compute the posterior estimates of residuals and random effects across the entire ensemble.
Unlike predict, which uses historically learned BLUPs, this method assumes the true outcomes
yare known. It passes the dataset through each base model’s infer engine to calculate the exact structural residuals and optimal random effects. It then aggregates these properties across the ensemble to quantify both the expected analytical posteriors and their epistemic uncertainties.- Parameters:
X (ndarray of shape (n_samples, n_features)) – The fixed-effects design matrix.
y (ndarray of shape (n_samples, n_responses)) – The true continuous response matrix.
groups (ndarray of shape (n_samples, n_groups)) – The categorical grouping factors.
- Returns:
A unified container holding the aggregated residuals, total random effects, and specific group BLUPs. Every numeric property inside this result is an Estimate object containing both the expected value and the epistemic std deviation.
- Return type:
InferenceResult
- marginal_cov(slope_covariates=None)[source]#
Compute the expected unconditional marginal covariance matrix.
- Parameters:
slope_covariates (list of np.ndarray or None, optional) – A list specifying the covariates (excluding the intercept) for each grouping factor.
- Returns:
An estimate object containing the expected covariance matrix and its epistemic standard deviation.
- Return type:
Estimate
- marginal_corr(slope_covariates=None)[source]#
Compute the expected unconditional marginal correlation matrix.
- Parameters:
slope_covariates (list of np.ndarray or None, optional) – A list specifying the covariates (excluding the intercept) for each grouping factor.
- Returns:
An estimate object containing the expected correlation matrix and its epistemic standard deviation.
- Return type:
Estimate