# Nested sampling for normal variance and 1/exponential(1) prior # Likelihood L=function(u){dnorm(5,sd=1/sqrt(u))} # N=15000 j=N/2 X=rep(1,j+1) Z=0 # Step 1 thetas=rexp(N) exc=order(L(thetas))[1] low=(L(thetas))[exc] prevo=thetas[exc] X[2]=exp(-1/N) Z=Z+low*(X[1]-X[2]) for (i in 3:j){ repet=T if (prevo<1/25){ while(repet){ thet=prevo+qexp((runif(1)-pexp(prevo))/(1-pexp(prevo))) repet=(L(thet)