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 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.
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.Lazy lifecycle: construction only validates inputs and builds design matrices — nothing is sampled. Call
fit()to draw posterior samples (andsample_prior_predictive()for prior predictive checks); read methods such asplot(),summary(), andeffect_summary()require the corresponding draw group.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, ... } ... ), ... ).fit() >>> 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
Construct the model graph without sampling anything.
PrePostNEGD.effect_summary(*[, group, ...])Generate a decision-ready summary of causal effects for PrePostNEGD.
PrePostNEGD.fit(**kwargs)Run the posterior phase and populate
result.PrePostNEGD.generate_report(*[, ...])Generate a self-contained HTML report for this experiment.
Validate the input data and model formula for correctness.
PrePostNEGD.plot(*[, group, round_to, ...])Plot the pre-post non-equivalent group design results.
PrePostNEGD.print_coefficients([round_to])Ask the model to print its posterior coefficients.
PrePostNEGD.sample_prior_predictive(**kwargs)Run the optional prior phase and populate
prior_result.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
has_prior_predictiveWhether the prior phase has run (draws, and bundle where kept).
idataReturn fitted DataTree when the model backend supports it.
is_builtWhether the model graph / fit design exists (no draws implied).
is_configureddesign matrices are ready.
is_fittedWhether posterior draws and the posterior result bundle exist.
modelThe underlying model instance.
prior_resultPrior-group result bundle; raises before prior sampling.
resultPosterior-group result bundle; raises before
fit().supports_bayessupports_olssupports_pymc_forecastlabelsdata- __init__(data, formula, group_variable_name, pretreatment_variable_name, model=None)[source]#
- Parameters:
data (DataFrameLike)
formula (str)
group_variable_name (str)
pretreatment_variable_name (str)
model (PyMCModel | None)
- Return type:
None
- classmethod __new__(*args, **kwargs)#