Pandora-IsoMemo / CausalR

GNU General Public License v3.0
0 stars 0 forks source link

BSTS model or IMPACT model option #3

Closed policybot2020 closed 4 months ago

policybot2020 commented 1 year ago
  1. 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:

plot(impact) summary(impact) summary(impact, "report")

policybot2020 commented 4 months ago

user now can inject custom BTST code