EXAMPLE 1 model { z[1] <- 1; z[1] ~ dbern(p[1]); p[1] <- 1/th[1]; th[1] ~ dexp(1) I(x[1],); th1 <- th[1]-x[1] x[2] ~ dexp(th[2]); th[2] ~ dexp(1) # Likelihood terms for models LL[1] <- log(1/th[1]); LL[2] <- log(th[2])-th[2]*x[2] # prior ordinates for models pr.ord[1] <- -th[1]; pr.ord[2]<- -th[2] # pseudo-prior ordinates for models g.ord[1] <- (r[1]-1)*log(th[1]-x[1])-s[1]*(th[1]-x[1])+r[1]*log(s[1])-loggam(r[1]) g.ord[2] <- (r[2]-1)*log(th[2])-s[2]*th[2]+r[2]*log(s[2])-loggam(r[2]) # Combining likelihoods, priors and importance samples L[1]<-LL[1]+ pr.ord[1]-g.ord[1]+log(0.5); L[2]<-LL[2]+ pr.ord[2]-g.ord[2]+log(0.5) # Scaling against largest likelihood maxL<-ranked(L[],2); SL[1]<- L[1]-maxL; SL[2]<- L[2]-maxL # exponentiating and normalizing expSL[1] <- exp(SL[1]); expSL[2]<- exp(SL[2]); # model weights w[1]<- expSL[1]/sum(expSL[]); w[2]<-expSL[2]/sum(expSL[]) B12 <- w[1]/w[2]} Data (x=0.2) # r[1] and s[1] based on sampled th1 list(x=c(0.2,0.2),r=c(0.631,2),s=c(1.356,1.2)) Data for x=0.9 list(x=c(0.9,0.9),r=c(0.83,2),s=c(1.27,1.9)) Inits list(th=c(2,2)) EXAMPLE 2 model {x[1]~dbin(p[1],10); p[1]~dbeta(1,1) x[2]~dbin(p[2],10); p[2]~dbeta(30,30) # Likelihood terms for models LL[1]<-logfact(10)-logfact(10-x[1]) -logfact(x[1])+x[1]*log(p[1])+(10-x[1])*log(1-p[1]) LL[2]<-logfact(10)-logfact(10-x[2]) -logfact(x[2])+x[2]*log(p[2])+(10-x[2])*log(1-p[2]) # prior ordinates for models LP[1]<-loggam(2)-loggam(1)-loggam(1)+0*log(p[1])+0*log(1 -p[1]) LP[2]<-loggam(60)-loggam(30)-loggam(30)+29*log(p[2]) +29*log(1-p[2]) # importance sample ordinates for models IMP[1]<-loggam(12.1)-loggam(2)-loggam(10.1)+1*log(p[1])+9.1*log(1-p[1]) IMP[2]<-loggam(70.8)-loggam(31.3)-loggam(39.5)+30.3*log(p[2])+38.5*log(1-p[2]) # Combining likelihoods, priors and importance samples L[1]<-LL[1]+LP[1]+log(0.5)-IMP[1]; L[2]<-LL[2]+LP[2]+log(0.5)-IMP[2] # Scaling with the largest likelihood, and protecting for underflow maxL<-ranked(L[],2); SL[1]<-max(L[1]-maxL,-700); SL[2]<-max(L[2]-maxL,-700) # exponentiating and normalizing expSL[1]<- exp(SL[1]); expSL[2]<- exp(SL[2]); # model weights w[1]<-expSL[1]/sum(expSL[]); w[2]<-expSL[2]/sum(expSL[])} Data list(x=c(1,1)).