bayespecon.diagnostics.ModelComparison¶
-
class bayespecon.diagnostics.ModelComparison(models, labels=
None, method='bridge', **kwargs)[source]¶ Compare a collection of fitted Bayesian models.
Object-oriented wrapper around
bayes_factor_compare_models(),post_prob(), andarviz.compare(). Marginal likelihoods are computed once on first access and cached, so repeated calls tobayes_factors(),posterior_probabilities(), etc. reuse the same estimates.- Parameters:¶
- models : list, tuple, or dict¶
Fitted model objects (each with
inference_dataand, for bridge sampling,pymc_model). Adictis interpreted as{label: model}; otherwise passlabelsexplicitly.- labels : list of str, optional¶
Display labels. Required when
modelsis a list/tuple and no__name__-style label is available; auto-generated when omitted.- method : {"bridge", "bic"}, default "bridge"¶
Marginal-likelihood estimator. See
bayes_factor_compare_models().- **kwargs¶
Forwarded to
bayes_factor_compare_models()(e.g.repetitions,maxiterfor bridge sampling).
Examples
>>> cmp = ModelComparison({"OLS": ols, "SAR": sar, "SDM": sdm}) >>> cmp.log_marginal_likelihoods OLS -123.4 SAR -120.1 SDM -119.8 Name: log_ml, dtype: float64 >>> cmp.bayes_factors # pairwise BF matrix >>> cmp.posterior_probabilities() >>> cmp.loo_comparison() # arviz.compare on LOOMethods
__init__(models[, labels, method])loo_comparison(**kwargs)Compare models by LOO via
arviz.compare().posterior_probabilities([prior_prob])Posterior model probabilities given the estimated marginal likelihoods.
Attributes
Pairwise Bayes factors \(BF_{ij} = ML_i / ML_j\).
Per-model diagnostics from the marginal-likelihood estimator.
Model labels in the order supplied.
Estimated \(\log p(y \mid M_k)\) for each model.
- property bayes_factors : pandas.DataFrame[source]¶
Pairwise Bayes factors \(BF_{ij} = ML_i / ML_j\).
- property diagnostics : dict | None[source]¶
Per-model diagnostics from the marginal-likelihood estimator.
- property log_marginal_likelihoods : pandas.Series[source]¶
Estimated \(\log p(y \mid M_k)\) for each model.
- loo_comparison(**kwargs)[source]¶
Compare models by LOO via
arviz.compare().Each model must have a
log_likelihoodgroup in itsinference_data. Extra keyword arguments are forwarded toarviz.compare().
-
posterior_probabilities(prior_prob=
None)[source]¶ Posterior model probabilities given the estimated marginal likelihoods.