Skip to contents

Thin wrapper around CausalImpact::CausalImpact() (Brodersen et al. 2015). Fits a Bayesian structural time-series counterfactual to a single-series treatment using the pre-intervention window and reports the post-intervention causal effect with credible intervals.

Usage

morie_causal_impact(
  data,
  pre_period,
  post_period,
  model_args = NULL,
  alpha = 0.05
)

Arguments

data

A data frame, matrix, or zoo object whose first column is the outcome and remaining columns are concurrent covariate predictors.

pre_period

Integer length-2 vector giving the start and end row indices (or time indices for zoo) of the pre-intervention window.

post_period

Integer length-2 vector giving the start and end row indices of the post-intervention window.

model_args

Optional named list passed to CausalImpact::CausalImpact()'s model.args argument (e.g. list(niter = 1000L)).

alpha

Posterior credible-interval coverage (default 0.05, meaning 95 percent intervals).

Value

Named list with elements average_effect, cumulative_effect, ci_lower, ci_upper, posterior_prob_causal, and summary (the upstream CausalImpact summary matrix), plus the original impact object.

Details

Hard-errors if CausalImpact is not installed – the upstream Kalman-filter + slab-and-spike machinery has no compact inline equivalent. The wrapper is documented as an extender so that downstream rmorie callers have a stable morie_* entry point to the package.

References

Brodersen KH, Gallusser F, Koehler J, Remy N, Scott SL (2015). Inferring causal impact using Bayesian structural time-series models. Annals of Applied Statistics, 9(1):247-274.