# Load required packages ---------------------------------------------------
library(CausalImpact)
library(purrr)

# Generate dataset CausalImpact -----------------------------------
set.seed(1234)
x1 <- 100 + arima.sim(model = list(ar = 0.9), n = 100)
x2 <- 100 + arima.sim(model = list(ar = 0.8), n = 100)
y <- 75 * x1 + 25 * x2 + rnorm(100, sd=1000)
y[51:100] <- y[51:100] - 2000
data <- cbind(y, x1, x2)
plot(data, main="Data CausalImpact")

pre.period <- c(1, 50)
post.period <- c(51, 100)


# Run CausalImpact
impact <- CausalImpact(data, pre.period, post.period)

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