CounterfactualResult#

class impulso.results.CounterfactualResult(*, idata, var_names)[source]#

Bases: VARResultBase

Historical counterfactual paths alongside the actual data.

The posterior-predictive Dataset carries “counterfactual” (chain, draw, time, variable) and “actual” (time, variable) over the same returned window. Counterfactual draws are built from the realised structural shocks — edited, never re-drawn — so their spread reflects parameter and identification uncertainty only.

Parameters:
  • idata (InferenceData)

  • var_names (list[str])

idata#

InferenceData-schema container with counterfactual draws + actual path.

var_names#

Names of variables.

Type:

list[str]

actual()[source]#

The observed path over the returned window.

Returns:

DataFrame shaped like median().

Return type:

DataFrame

difference()[source]#

Posterior median effect of the edits: actual - counterfactual.

The actual path is constant across draws, so actual - median(counterfactual) equals median(actual - counterfactual) exactly.

Returns:

DataFrame shaped like median().

Return type:

DataFrame

hdi(prob=0.89)[source]#

HDI for the counterfactual path.

Parameters:

prob (float) – Probability mass for the HDI. Default 0.89.

Returns:

HDIResult whose lower / upper DataFrames mirror median().

Return type:

HDIResult

median()[source]#

Posterior median counterfactual path.

Returns:

DataFrame indexed by the returned window’s DatetimeIndex with one column per variable.

Return type:

DataFrame

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

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

plot()[source]#

Plot actual vs counterfactual paths with HDI bands.

Return type:

Figure

to_dataframe()[source]#

Counterfactual posterior median as a DataFrame (passthrough to median()).

Return type:

DataFrame