# # This file contains the bacula example of the graphical models paper (Example 1a). # # Example file for a Bayesian analysis using MCMC for a set of 5 observations from a binomial distribution with a beta prior on the parameter p. # # author: Sebastian Hoehna # set the prior parameters alpha <- 1 # this creates a constant variable with value 1 beta <- 1 # create the stochastic variable for the parameter of the binomial distribution p ~ beta(alpha,beta) # this creates a stochastic variable drawn from a beta distribution with parameters alpha and beta # create the data vector data <- [1,1,1,0,0] # this creates a vector for (i in 1:5) { x[i] ~ bernoulli(p) # this creates a stochastic variable drawn from a bernoulli distribution with parameter p # attach/clamp the data x[i].clamp(data[i]) } # create the model from the DAG mymodel <- model(p) # create the moves/proposals that change the parameters of the model during the MCMC moves[1] <- mSlide(p, delta=0.2, weight=1.0) monitors[1] <- modelmonitor(filename= "GraphicalModels_Example_1a.log",printgen=10, separator = " ") monitors[2] <- screenmonitor(printgen=10, separator = " ", p) mymcmc <- mcmc(mymodel, monitors, moves) # If you choose more or different proposals, or different weights for the proposals, then the number of proposals changes per iteration. Currently there is only one proposal with weight 1.0. mymcmc.burnin(generations=2000,tuningInterval=100) mymcmc.run(generations=200000) result <- readTrace("GraphicalModels_Example_1a.log") result[5]