Skip to content

Instantly share code, notes, and snippets.

@gmodena
Created May 25, 2022 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmodena/0b8b19629ac90eaffcc629921afd84f6 to your computer and use it in GitHub Desktop.
Save gmodena/0b8b19629ac90eaffcc629921afd84f6 to your computer and use it in GitHub Desktop.
rstan-changepoint.R
# 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