google / CausalImpact

An R package for causal inference in time series
Apache License 2.0
1.71k stars 254 forks source link

Data Structuring for Seasonality and Variable Control #76

Closed dachosen1 closed 1 month ago

dachosen1 commented 1 month ago

I’m trying to understand how to best structure data to account for seasonality or control for other variables using causal impact.

For example, consider a case where I’m conducting an analysis to measure the impact of an economic policy on GDP, but I want to control for inflation.

Is the below the correct way to structure the data? Does the order of the columns matter?

library(CausalImpact)

gdp<- rnorm(100)
inflation <- rnorm(100)

data <- cbind(gdp, inflation)

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

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