SyntheticControl#

class causalpy.experiments.synthetic_control.SyntheticControl[source]#

The class for the synthetic control experiment.

Parameters:
  • data (DataFrame) – A pandas dataframe

  • treatment_time (int | float | Timestamp) – The time when treatment occurred, should be in reference to the data index

  • control_units (list[str]) – A list of control units to be used in the experiment

  • treated_units (list[str]) – A list of treated units to be used in the experiment

  • model (PyMCModel | RegressorMixin | None) – A PyMC model

Example

>>> import causalpy as cp
>>> df = cp.load_data("sc")
>>> treatment_time = 70
>>> seed = 42
>>> result = cp.SyntheticControl(
...     df,
...     treatment_time,
...     control_units=["a", "b", "c", "d", "e", "f", "g"],
...     treated_units=["actual"],
...     model=cp.pymc_models.WeightedSumFitter(
...         sample_kwargs={
...             "target_accept": 0.95,
...             "random_seed": seed,
...             "progressbar": False,
...         }
...     ),
... )

Notes

For Bayesian models, the causal impact is calculated using the posterior expectation (mu) rather than the posterior predictive (y_hat). This means the impact and its uncertainty represent the systematic causal effect, excluding observation-level noise. The uncertainty bands in the plots reflect parameter uncertainty and counterfactual prediction uncertainty, but not individual observation variability.

Methods

SyntheticControl.__init__(data, ...[, model])

SyntheticControl.algorithm()

Run the experiment algorithm: fit model, predict, and calculate causal impact.

SyntheticControl.effect_summary(*[, window, ...])

Generate a decision-ready summary of causal effects for Synthetic Control.

SyntheticControl.fit(*args, **kwargs)

SyntheticControl.get_plot_data(*args, **kwargs)

Recover the data of an experiment along with the prediction and causal impact information.

SyntheticControl.get_plot_data_bayesian([...])

Recover the data of the PrePostFit experiment along with the prediction and causal impact information.

SyntheticControl.get_plot_data_ols()

Recover the data of the experiment along with the prediction and causal impact information.

SyntheticControl.input_validation(data, ...)

Validate the input data and model formula for correctness

SyntheticControl.plot(*args, **kwargs)

Plot the model.

SyntheticControl.print_coefficients([round_to])

Ask the model to print its coefficients.

SyntheticControl.summary([round_to])

Print summary of main results and model coefficients.

Attributes

datapost

Data from on or after the treatment time (inclusive).

datapre

Data from before the treatment time (exclusive).

idata

Return the InferenceData object of the model.

supports_bayes

supports_ols

labels

__init__(data, treatment_time, control_units, treated_units, model=None, **kwargs)[source]#
Parameters:
Return type:

None

classmethod __new__(*args, **kwargs)#