PrePostNEGD#
- class causalpy.experiments.prepostnegd.PrePostNEGD[source]#
A class to analyse data from pretest/posttest designs.
- Parameters:
data (
DataFrame) – A pandas dataframe.formula (
str) – A statistical model formula.group_variable_name (
str) – Name of the column indatafor the group variable; should be either binary or boolean.pretreatment_variable_name (
str) – Name of the column indatafor the pretreatment variable.model (
PyMCModel|None) – A PyMC model. Defaults toLinearRegression.**kwargs (
Any) – Additional keyword arguments forwarded toBaseExperiment.
Notes
Estimate extraction
The reported
causal_impactis the posterior coefficient on the treatment-group term, conditional on the pretreatment outcome and any other formula covariates. Treated and untreated prediction curves are also computed for visualization, but they do not determine the reported scalar effect. With the current additive identity-link model, the treatment coefficient equals the corresponding conditional prediction contrast.Examples
>>> import causalpy as cp >>> df = cp.load_data("anova1") >>> seed = 42 >>> result = cp.PrePostNEGD( ... df, ... formula="post ~ 1 + C(group) + pre", ... group_variable_name="group", ... pretreatment_variable_name="pre", ... model=cp.pymc_models.LinearRegression( ... sample_kwargs={ ... "target_accept": 0.95, ... "random_seed": seed, ... "progressbar": False, ... } ... ), ... ) >>> result.summary(round_to=1) ==================Pretest/posttest Nonequivalent Group Design=================== Formula: post ~ 1 + C(group) + pre Results: Causal impact = 2, $CI_{94%}$[2, 2] Model coefficients: Intercept -0.5, 94% HDI [-1, 0.2] C(group)[T.1] 2, 94% HDI [2, 2] pre 1, 94% HDI [1, 1] y_hat_sigma 0.5, 94% HDI [0.5, 0.6]
Methods
Run the experiment algorithm: fit model, predict, and calculate causal impact.
PrePostNEGD.effect_summary(*[, direction, ...])Generate a decision-ready summary of causal effects for PrePostNEGD.
PrePostNEGD.fit(*args, **kwargs)Fit the underlying model.
PrePostNEGD.generate_report(*[, ...])Generate a self-contained HTML report for this experiment.
PrePostNEGD.get_plot_data(*args, **kwargs)Recover the data of an experiment along with the prediction and causal impact information.
Validate the input data and model formula for correctness.
PrePostNEGD.plot(*[, round_to, ci_prob, ...])Plot the pre-post non-equivalent group design results.
PrePostNEGD.print_coefficients([round_to])Ask the model to print its coefficients.
PrePostNEGD.set_maketables_options(*[, hdi_prob])Set optional maketables rendering options for this experiment.
PrePostNEGD.summary([round_to])Print summary of main results and model coefficients.
Attributes
idataReturn fitted InferenceData when the model backend supports it.
supports_bayessupports_olssupports_pymc_forecastlabelsdata- __init__(data, formula, group_variable_name, pretreatment_variable_name, model=None, **kwargs)[source]#
- classmethod __new__(*args, **kwargs)#