#---------------------------------------------------- # Model involving a Binomial distribution with # a Poisson distributed n and a Beta distributed p # # GdA 23/2/2015 #---------------------------------------------------- library(rjags) #------------ model ---------------------------- model = "temp_model.bug" write(" model { n ~ dpois(10) p ~ dbeta(20, 10) x ~ dbin(p, n) y <- x*n*p } ", model) jm <- jags.model(model, n.chains = 3) # define the model chain <- coda.samples(jm, c('n', 'p', 'x', 'y'), n.iter=10000) # sampling print(summary(chain)) plot(chain)