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, 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 or sklearn model. Defaults toWeightedSumFitter.min_donor_correlation (
float) – Minimum acceptable Pearson correlation between each control unit and treated unit in the pre-treatment period. Control units below this threshold trigger aUserWarning. Defaults to0.0(warn on negatively correlated donors).**kwargs (
Any) – Additional keyword arguments forwarded toBaseExperiment.
Notes
Estimate extraction
The model learns control-unit weights from pre-intervention outcomes and applies them to post-intervention controls to construct a synthetic untreated trajectory. Pointwise impact is the observed treated outcome minus this synthetic counterfactual, and cumulative impact is its running sum. Bayesian backends subtract the posterior conditional expectation
murather than noisy posterior-predictive drawsy_hat; OLS subtracts its weighted point prediction.Examples
>>> 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, ... } ... ), ... )
Methods
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)Fit the underlying model.
SyntheticControl.generate_report(*[, ...])Generate a self-contained HTML report for this experiment.
SyntheticControl.get_plot_data([hdi_prob, ...])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(*[, round_to, ...])Plot the synthetic control results for a specific treated unit.
SyntheticControl.print_coefficients([round_to])Ask the model to print its coefficients.
SyntheticControl.set_maketables_options(*[, ...])Set optional maketables rendering options for this experiment.
SyntheticControl.summary([round_to])Print summary of main results and model coefficients.
Attributes
datapostData from on or after the treatment time (inclusive).
datapreData from before the treatment time (exclusive).
idataReturn fitted InferenceData when the model backend supports it.
supports_bayessupports_olssupports_pymc_forecastlabelsdata- __init__(data, treatment_time, control_units, treated_units, model=None, min_donor_correlation=0.0, **kwargs)[source]#
- classmethod __new__(*args, **kwargs)#