below the 'upload file' has a conditinoal panel for select the BSTS model or default.
if on default, then no change.
Using a custom model
Instead of using the default model constructed by the CausalImpact package, we can use the bsts package to specify our own model. This provides the greatest degree of flexibility.
Before constructing a custom model, we set the observed data in the post-treatment period to NA, reflecting the fact that the counterfactual response is unobserved after the intervention. We keep a copy of the actual observed response in the variable post.period.response.
post.period <- c(71, 100)
post.period.response <- y[post.period[1] : post.period[2]]
y[post.period[1] : post.period[2]] <- NA
We next set up and estimate a time-series model using the bsts package. Here is a simple example:
ss <- AddLocalLevel(list(), y)
bsts.model <- bsts(y ~ x1, ss, niter = 1000)
Finally, we call CausalImpact(). Instead of providing input data, we simply pass in the fitted model object (bsts.model). We also need to provide the actual observed response. This is needed so that the package can compute the difference between predicted response (stored in bsts.model) and actual observed response (stored in post.period.response).
impact <- CausalImpact(bsts.model = bsts.model,
post.period.response = post.period.response)
The results can be inspected in the usual way:
Before constructing a custom model, we set the observed data in the post-treatment period to NA, reflecting the fact that the counterfactual response is unobserved after the intervention. We keep a copy of the actual observed response in the variable post.period.response.
post.period <- c(71, 100) post.period.response <- y[post.period[1] : post.period[2]] y[post.period[1] : post.period[2]] <- NA We next set up and estimate a time-series model using the bsts package. Here is a simple example:
ss <- AddLocalLevel(list(), y) bsts.model <- bsts(y ~ x1, ss, niter = 1000) Finally, we call CausalImpact(). Instead of providing input data, we simply pass in the fitted model object (bsts.model). We also need to provide the actual observed response. This is needed so that the package can compute the difference between predicted response (stored in bsts.model) and actual observed response (stored in post.period.response).
impact <- CausalImpact(bsts.model = bsts.model, post.period.response = post.period.response) The results can be inspected in the usual way:
plot(impact) summary(impact) summary(impact, "report")