Skip to content

Instantly share code, notes, and snippets.

@rasmusab
Last active July 8, 2019 21:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rasmusab/cd84b63d13c8280ec91cdf576c8a0f52 to your computer and use it in GitHub Desktop.
Save rasmusab/cd84b63d13c8280ec91cdf576c8a0f52 to your computer and use it in GitHub Desktop.
UseR 2019 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)
@rasmusab
Copy link
Author

rasmusab commented Jul 6, 2019

@serifatf The only purpose of this script is to see if you have correctly installed the three packages, nothing else :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment