Created
May 25, 2022 09:07
-
-
Save gmodena/0b8b19629ac90eaffcc629921afd84f6 to your computer and use it in GitHub Desktop.
rstan-changepoint.R
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
# this installs the stand compiler and R bindings | |
install.packages("rstan") | |
library(rstan) | |
# Generate sample data | |
x1 <- rnorm(41, mean=15, sd=1.5) | |
x2 <- rnorm(79, mean=17, sd=1.1) | |
x <- c(x1, x2) | |
# fit a stan model | |
# changepoint.stan can be obtained from https://github.com/gmodena/bayesian-changepoint/blob/master/changepoint.stan | |
fit <- stan( | |
file = "changepoint.stan", | |
data = list(D = x, N=length(x)), | |
chains = 4, | |
warmup = 1000, | |
iter = 10000, | |
cores = 4, | |
refresh = 500 | |
) | |
print(fit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment