#Load the data n<-10 x<-c(1,2,3,4,5,6,7,8,9,10) y<-c(6,7,8,4,9,11,12,14,15,19) #Call WinBUGS: library(R2WinBUGS) modelfile<-"C:/Users/bjreich.ST/Desktop/junk/BUGSmodel.txt" dat<-list("n","x","y") vars2keep<-list("sigma","alpha","beta") inits<-function(){list(tau=1, alpha=rnorm(1))} output<-bugs( model.file=file.path(modelfile), data=dat, inits = inits, parameters.to.save = vars2keep, n.chains=2, n.iter=10000, n.burnin=1000, n.thin=10, debug=TRUE, DIC=TRUE ) #Analyze the MCMC output # Check convergence plot(output) # Plot the posterior of sigma samples<-output$sims.matrix #samples is a matrix with all the MCMC samples. #each variable is a column hist(samples[,1],main="Posterior of sigma") #the first column is sigma #Print the posterior means and standard deviations print(round(output$mean,3)) print(round(output$sd,3))