Created
October 12, 2021 18:33
-
-
Save madilk/0ca4ad7d955226f0245398222aedf025 to your computer and use it in GitHub Desktop.
Causal impact package example for campaign data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
options(scipen = 100) | |
install.packages("CausalImpact") | |
library(CausalImpact) | |
##YT video on running it in R : https://www.youtube.com/watch?v=H64ucBjgY6w | |
View(causaldata) | |
#convert data to time series | |
campaign_mkt <- ts(causaldata$sales) | |
non_campaign_mkt_1 <- ts(causaldata$sales_non_campaign_mkt_1) | |
non_campaign_mkt_2 <- ts(causaldata$sales_non_campaign_mkt_2) | |
##correlation check | |
corrcheck <- cbind(campaign_mkt,non_campaign_mkt_1, non_campaign_mkt_2) | |
correlation <- window(corrcheck,start=1, end=319) | |
cor(correlation) | |
pre.period <- as.Date(c("2019-01-01" , "2019-11-20")) | |
post.period <- as.Date(c("2019-11-21" , "2019-12-03")) | |
time.point <- seq.Date(as.Date("2019-01-01"), by=1, length.out=337) | |
causalimpact <- zoo(cbind(campaign_mkt,non_campaign_mkt_1,non_campaign_mkt_2),time.point) | |
impact <- CausalImpact(causalimpact,pre.period, post.period) | |
plot(impact) | |
summary(impact) | |
summary(impact,"report") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment