1
$\begingroup$

I want to train on a period that isn't immediately preceding the prediction period. You can do this using the default causal model but I'm not sure how with a custom model.

Straight from the documentation example:

set.seed(1)
x1 <- 100 + arima.sim(model = list(ar = 0.999), n = 100)
y <- 1.2 * x1 + rnorm(100)
y[71:100] <- y[71:100] + 10
data <- cbind(y, x1)

post.period <- c(71, 100)
post.period.response <- y[(post.period[1]) : post.period[2]]
y[post.period[1] : post.period[2]] <- NA
ss <- AddLocalLevel(list(), y)
bsts.model <- bsts(y ~ x1, ss, niter = 2000, data=y)

impact <- CausalImpact(bsts.model = bsts.model,
                       post.period.response = post.period.response)

If you change:

post.period.response <- y[(post.period[1]) : post.period[2]]

to: post.period.response <- y[(post.period[1]+10) : post.period[2]]

you will get this error (source: https://github.com/google/CausalImpact/blob/master/R/impact_inference.R#L472):

Error: cf.period.start not less than or equal to post.period[1]

I want to train the model on period of y[1:(post.period[1]-1)] and predict on period of y[(post.period[1]+10):100]. How can I do that?

$\endgroup$
1
  • $\begingroup$ I wanted something similar: a gap between post-period and the end of the data. Here's a pull request that addresses your issue and mine: github.com/google/CausalImpact/pull/51. $\endgroup$
    – lcfrs
    Commented Jul 25, 2021 at 17:39

1 Answer 1

2
$\begingroup$

Having a gap between pre- and post-period is currently not supported when providing a custom BSTS model, it only works - as you write - when using the default model. It wouldn't be too hard to implement this feature, but it would require a change in the CausalImpact() interface.

With the current version, there is also no straight-forward workaround, unfortunately. Removing all data points between pre- and post-period would work for a very limited set of models (no trend, no AR component, etc.); but in such a case, there would be no need to fit a custom BSTS model in the first place...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.