# How to use a custom model in CausalImpact where preperiod.start is not right after preperiod.end?

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
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?

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.