Last active
August 29, 2015 14:15
-
-
Save MarkEdmondson1234/9d020cabf5338f3df93f to your computer and use it in GitHub Desktop.
CausalImpact in Shiny
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
## in server.r of a shiny app | |
casualImpactData <- reactive({ | |
## only if we have the data ready | |
validate( | |
need(chartData(), "Need data") | |
) | |
data <- chartData() | |
## from user input in ui.r | |
start <- input$range_date[1] | |
end <- input$range_date[2] | |
event <- input$event_date | |
season <- as.numeric(input$season) | |
## setting up the necessary data for CausalImpact | |
pre.period <- as.Date(c(start, event)) | |
post.period <- as.Date(c(event + 1, end)) | |
## doing the CausalImpact call and creating the model data | |
CausalImpact(data, pre.period, post.period, model.args = list(nseasons = season)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment