Skip to content

Instantly share code, notes, and snippets.

Last active May 2, 2023 17:16
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Test script for "Introduction to Bayesian data analysis with R"
# Prior to the tutorial make sure that the script below runs without error on your R installation.
# What you need is a working installation of JAGS:
# and the rjags R package that can be installed from R by running
# install.packages("rjags")
# Generating some fake data
y <- rbinom(30, size = 1, prob = 0.2015)
# Fitting a simple binomial model using JAGS
model_string <- "model {
for(i in 1:length(y)) {
y[i] ~ dbern(theta)
theta ~ dunif(0, 1)
jags_model <- jags.model(textConnection(model_string), data = list(y = y))
mcmc_samples <- coda.samples(jags_model, variable.names = "theta", n.iter = 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment