Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UseR 2018 tutorial - Get up to speed with Bayes test script
# Prior to the tutorial make sure that the script below runs without error on your R installation.
# You first need to install the follwoing packages:
# install.packages(c("rstanarm", "prophet", "CausalImpact"))
library(rstanarm)
library(prophet)
library(CausalImpact)
# This will test that rstanarm works
# Don't be alarmed if you get a warning about "divergent transitions "
fit <- stan_lm(mpg ~ wt + qsec + am, data = mtcars, prior = R2(0.75))
plot(fit, prob = 0.8)
# This tests that prophet is working
history <- data.frame(ds = seq(as.Date('2015-01-01'), as.Date('2016-01-01'), by = 'd'),
y = sin(1:366/200) + rnorm(366)/10)
m <- prophet(history)
future <- make_future_dataframe(m, periods = 365)
forecast <- predict(m, future)
plot(m, forecast)
# This tests that CausalImpact is working
# First simulating some data
x1 <- 100 + arima.sim(model = list(ar = 0.999), n = 52)
y <- 1.2 * x1 + rnorm(52)
y[41:52] <- y[41:52] + 10
data <- cbind(y, x1)
pre.period <- c(1, 40)
post.period <- c(41, 52)
# Then running CausalImpact
impact <- CausalImpact(data, pre.period, post.period)
plot(impact)
@keniatw

This comment has been minimized.

Copy link

commented May 20, 2019

Having some trouble with the installation of CausalImpact. Boom and BoomSpikeSlab are installed and running but I simply can't make bsts to install, and CausalImpact depends on it. Any new resources? I've seen some discussion about the issue for Windows users, but nothing really for Linux users...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.