PrePostNEGD#

class causalpy.experiments.prepostnegd.PrePostNEGD[source]#

A class to analyse data from pretest/posttest designs.

Parameters:
  • data (NativeDataFrame) – Any eager dataframe Narwhals supports, such as pandas, Polars, or PyArrow. Converted to pandas internally.

  • formula (str) – A statistical model formula.

  • group_variable_name (str) – Name of the column in data for the group variable; should be either binary or boolean.

  • pretreatment_variable_name (str) – Name of the column in data for the pretreatment variable.

  • model (PyMCModel | None) – A PyMC model. Defaults to LinearRegression.

Notes

Estimate extraction

The reported causal_impact is 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

PrePostNEGD.algorithm()

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.generate_report(*[, ...])

Generate a self-contained HTML report for this experiment.

PrePostNEGD.input_validation()

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

idata

Return fitted DataTree when the model backend supports it.

supports_bayes

supports_ols

supports_pymc_forecast

labels

data

__init__(data, formula, group_variable_name, pretreatment_variable_name, model=None)[source]#
Parameters:
Return type:

None

classmethod __new__(*args, **kwargs)#