Last active
July 8, 2019 21:56
-
-
Save rasmusab/cd84b63d13c8280ec91cdf576c8a0f52 to your computer and use it in GitHub Desktop.
UseR 2019 tutorial - Get up to speed with Bayes test script
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
# 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) |
@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
Thank you Rasmus, my script is working with graphs plotting fine but i understand what am running can you please explain what we are trying to achieve even if there is a document to study.