#example of generating a sample from the joint posterior distribution of #a normal model with uninformative prior #we simulate a sample of size 1000 from a N(0,2) yy_rnorm(1000,0,sqrt(4)) draw_function(w=1,NN,yy){ if (w == 1) postscript("/home/biostats/fdominic/course/babymcmc.ps") par(mfrow=c(2,1)) mu_rep(NA,NN) sigmasqr_rep(NA,NN) nn_length(yy) ss_var(yy) ybar_mean(yy) mu[1]_0 #initial values sigmasqr[1]_2 for(m in 2:NN){ AA_(nn-1)/2 BB_.5*(nn-1)*ss sigmasqr[m]_1/(rgamma(1,AA)/BB) mu[m]_rnorm(1,ybar, sqrt(sigmasqr[m]/nn)) } hist(mu,density=-1,yaxt="n",ylab="",xlab="mu",cex=2,nclass=50) hist(sqrt(sigmasqr),density=-1,yaxt="n",ylab="",xlab="sigma",cex=2,nclass=50) par(oma=c(0,0,0,0)) par(mfrow=c(1,1)) if (w == 1) dev.off()}