RegressionDiscontinuity#

class causalpy.experiments.regression_discontinuity.RegressionDiscontinuity[source]#

A class to analyse sharp regression discontinuity experiments.

Parameters:
  • data (DataFrame) – A pandas dataframe

  • formula (str) – A statistical model formula

  • treatment_threshold (float) – A scalar threshold value at which the treatment is applied

  • model – A PyMC model

  • running_variable_name (str) – The name of the predictor variable that the treatment threshold is based upon

  • epsilon (float) – A small scalar value which determines how far above and below the treatment threshold to evaluate the causal impact.

  • bandwidth (float) – Data outside of the bandwidth (relative to the discontinuity) is not used to fit the model.

Example

>>> import causalpy as cp
>>> df = cp.load_data("rd")
>>> seed = 42
>>> result = cp.RegressionDiscontinuity(
...     df,
...     formula="y ~ 1 + x + treated + x:treated",
...     model=cp.pymc_models.LinearRegression(
...         sample_kwargs={
...             "draws": 100,
...             "target_accept": 0.95,
...             "random_seed": seed,
...             "progressbar": False,
...         },
...     ),
...     treatment_threshold=0.5,
... )

Methods

RegressionDiscontinuity.__init__(data, ...)

RegressionDiscontinuity.bayesian_plot([round_to])

Generate plot for regression discontinuity designs.

RegressionDiscontinuity.input_validation()

Validate the input data and model formula for correctness

RegressionDiscontinuity.ols_plot([round_to])

Generate plot for regression discontinuity designs.

RegressionDiscontinuity.plot(*args, **kwargs)

Plot the model.

RegressionDiscontinuity.print_coefficients([...])

Ask the model to print its coefficients.

RegressionDiscontinuity.summary([round_to])

Print summary of main results and model coefficients

Attributes

idata

Return the InferenceData object of the model.

supports_bayes

supports_ols

__init__(data, formula, treatment_threshold, model=None, running_variable_name='x', epsilon=0.001, bandwidth=inf, **kwargs)[source]#
Parameters:
__new__(**kwargs)#