RegressionKink#
- class causalpy.experiments.regression_kink.RegressionKink[source]#
A class to analyse regression kink 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.kink_point (
float) – A scalar value at which the kink occurs.model (
PyMCModel|None) – A PyMC model. Defaults toLinearRegression.running_variable_name (
str) – The name of the running variable column.epsilon (
float) – A small scalar for evaluating the causal impact above/below the kink.bandwidth (
float) – Data outside of the bandwidth (relative to the kink) is not used to fit the model.
Notes
Lazy lifecycle
Construction only validates input and builds design matrices — nothing is sampled. Call
fit()to run posterior inference (it returnsself, so construction and fitting chain in one expression), and optionallysample_prior_predictive()first for prior predictive checks (plot(group="prior"),effect_summary(group="prior")). Results live onexp.result/exp.prior_result.Estimate extraction
The class predicts the conditional expectation at
kink_point - epsilon,kink_point, andkink_point + epsilon. It forms finite-difference slopes on the left and right and stores their difference asgradient_change. This is a local prediction contrast on derivatives, not a population-standardized effect.Examples
>>> import causalpy as cp >>> df = cp.load_data("rd") >>> kink = 0.5 >>> result = cp.RegressionKink( ... df, ... formula=f"y ~ 1 + x + I((x - {kink}) * treated)", ... kink_point=kink, ... model=cp.pymc_models.LinearRegression( ... sample_kwargs={"random_seed": 42, "progressbar": False} ... ), ... ).fit()
Methods
Construct the model graph without sampling anything.
RegressionKink.effect_summary(*[, group, ...])Generate a decision-ready summary of causal effects for Regression Kink.
RegressionKink.fit(**kwargs)Run the posterior phase and populate
result.RegressionKink.generate_report(*[, ...])Generate a self-contained HTML report for this experiment.
Validate the input data and model formula for correctness.
RegressionKink.plot(*[, group, round_to, ...])Plot the regression kink results.
RegressionKink.print_coefficients([round_to])Ask the model to print its posterior coefficients.
RegressionKink.sample_prior_predictive(**kwargs)Run the optional prior phase and populate
prior_result.RegressionKink.set_maketables_options(*[, ...])Set optional maketables rendering options for this experiment.
RegressionKink.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, kink_point, model=None, running_variable_name='x', epsilon=0.001, bandwidth=inf)[source]#
- classmethod __new__(*args, **kwargs)#