EvidenceComparison#

class impulso.evidence.EvidenceComparison(*, evidences, reference)[source]#

Bases: ImpulsoBaseModel

Bayes factors and posterior model probabilities across named model evidences.

Built by compare_evidence. The reference model is the denominator of every Bayes factor unless a different one is named per call.

Parameters:
evidences#

Named ModelEvidence objects, in the order they were compared.

Type:

dict[str, ModelEvidence]

reference#

Key of the default denominator model.

Type:

str

bayes_factor(model, against=None)[source]#

Bayes factor of model against another model.

Saturates rather than overflowing: a log difference beyond about 709 returns inf (or 0.0 below -709). Quote log_bayes_factor or log10_bayes_factor when the ratio is that large.

Parameters:
  • model (str) – Name of the numerator model.

  • against (str | None) – Name of the denominator model. Defaults to reference.

Returns:

BF(model, against).

Return type:

float

property best: str#

Name of the model with the highest log marginal likelihood.

log10_bayes_factor(model, against=None)[source]#

Base-10 log Bayes factor — the unit Kass and Raftery (1995) tabulate.

Parameters:
  • model (str) – Name of the numerator model.

  • against (str | None) – Name of the denominator model. Defaults to reference.

Returns:

log10 BF(model, against).

Return type:

float

log_bayes_factor(model, against=None)[source]#

Log Bayes factor of model against another model.

Parameters:
  • model (str) – Name of the numerator model.

  • against (str | None) – Name of the denominator model. Defaults to reference.

Returns:

log ML(model) - log ML(against). Positive favours model.

Raises:

KeyError – If either name is not part of the comparison.

Return type:

float

model_config = {'arbitrary_types_allowed': True, 'frozen': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

posterior_probabilities()[source]#

Posterior model probabilities under equal prior model weights.

Computed by a max-shifted softmax over the log marginal likelihoods, so the result is stable however far apart the models are.

Returns:

Model name to posterior probability; the values sum to one.

Return type:

dict[str, float]

to_dataframe(reference=None)[source]#

Tabulate the comparison, one row per model in comparison order.

Parameters:

reference (str | None) – Denominator for the Bayes-factor columns. Defaults to reference.

Returns:

DataFrame indexed by model name (index.name is “model”) with columns log_marginal_likelihood, log_bayes_factor, log10_bayes_factor, bayes_factor, posterior_probability, n_obs, n_vars, n_lags and volatility. The reference row has a log Bayes factor of exactly 0.0. volatility is object dtype so a homoscedastic model reads as None rather than as a missing value.

Return type:

DataFrame