Skip to content

Instantly share code, notes, and snippets.

@carlislerainey
Last active March 22, 2024 15:01
Show Gist options
  • Save carlislerainey/a715d07bc32df60271501cd98f8455fd to your computer and use it in GitHub Desktop.
Save carlislerainey/a715d07bc32df60271501cd98f8455fd to your computer and use it in GitHub Desktop.
# load packages
library(rstan)
library(bayesplot)
# make a stan model
fancy_stan_model <- "
generated quantities {
int<lower=0, upper=1> y_sim = bernoulli_rng(0.5);
}
"
# compile the Stan model
compiled_fancy_stan_model <- stan_model(model_code = fancy_stan_model)
# fit the model
fit <- sampling(compiled_fancy_stan_model,
iter = 2000,
warmup = 500,
chains = 4,
seed = 123,
algorithm = "Fixed_param")
# summarize the results
posterior <- extract(fit)$y_sim
table(posterior)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment