Last active
March 22, 2024 15:01
-
-
Save carlislerainey/a715d07bc32df60271501cd98f8455fd to your computer and use it in GitHub Desktop.
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
# 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