ChangePointDetection#

class causalpy.experiments.change_point_detection.ChangePointDetection[source]#

The class for detecting turning point in time series.

Parameters:
  • data (DataFrame) – A pandas dataframe

  • formula (str) – A statistical model formula

  • treatment_time_range – The time range when treatment could’ve occurred, should be in reference to the data index

  • model – A PyMC model

Example

>>> import causalpy as cp
>>> df = (
...     cp.load_data("its")
...     .assign(date=lambda x: pd.to_datetime(x["date"]))
...     .set_index("date")
... )
>>> seed = 42
>>> result = cp.ChangePointDetection(
...     df,
...     time_range=None,
...     formula="y ~ 1 + t + C(month)",
...     model=cp.pymc_models.LinearChangePointDetection(
...         cp_effect_type="level",
...         sample_kwargs={
...             "target_accept": 0.95,
...             "random_seed": seed,
...             "progressbar": False,
...         },
...     ),
... )

Methods

ChangePointDetection.__init__(data, formula)

ChangePointDetection.get_plot_data(*args, ...)

Recover the data of an experiment along with the prediction and causal impact information.

ChangePointDetection.get_plot_data_bayesian([...])

Recover the data of the experiment along with the prediction and causal impact information.

ChangePointDetection.get_plot_data_ols(...)

Abstract method for recovering plot data.

ChangePointDetection.input_validation(data, ...)

Validate the input data and model formula for correctness

ChangePointDetection.plot(*args, **kwargs)

Plot the model.

ChangePointDetection.plot_change_point()

display the posterior estimates of the change point

ChangePointDetection.print_coefficients([...])

Ask the model to print its coefficients.

ChangePointDetection.summary([round_to])

Print summary of main results and model coefficients.

Attributes

expt_type

idata

Return the InferenceData object of the model.

supports_bayes

supports_ols

__init__(data, formula, time_range=None, model=None, **kwargs)[source]#
Parameters:
Return type:

None

classmethod __new__(*args, **kwargs)#