@@ -606,7 +606,10 @@ gen_proposal_poisson <- function(y, X, e, b0 = 0, B0 = 100, t.max = 20) {
606606 d <- ncol(X)
607607
608608 beta_new <- matrix(c(log(mean(y/e)),rnorm(d - 1)/10), nrow = d)
609-
609+ if(is.nan(beta_new[1])){
610+ beta.new[1]<- log(mean(y)/mean(e))
611+ }
612+
610613 XtXi <- lapply(seq_len(N), function(i) tcrossprod(X[i,]))
611614 B0.inv <- solve(B0)
612615 for (t in seq_len(t.max)) {
@@ -919,7 +922,7 @@ b0=rep(0,d)
919922B0=diag(100,d)
920923
921924pri_alpha <- data.frame(shape = 2, rate = 0.5)
922- c_alpha=0.1
925+ c_alpha=0.3
923926
924927M <- 50000L / mcmcspeedup
925928
@@ -970,7 +973,7 @@ sampler.
970973
971974## Section 8.2.3: Evaluating MCMC samplers
972975
973- ### Example 8.10 Verifying the correctness of the full conditional MCMC samper
976+ ### Example 8.10 Verifying the correctness of the full conditional MCMC sampler
974977
975978To check the MCMC algorithm for correctness, we extend the sampler by adding sampling the data from the prior as a further sampling step.
976979
@@ -1392,11 +1395,11 @@ if (pdfplots) {
13921395}
13931396par(mfrow = c(1, 2), mar = c(2.5, 2.5, 1.5, .1), mgp = c(1.5, .5, 0), lwd = 1.5)
13941397
1395- M <- 300000 / (10 * mcmcspeedup)
1398+ M <- 1000000 / (10 * mcmcspeedup)
13961399set.seed(1234)
13971400res_check_full <- negbin_check_cba(X, e, b0, B0, pri_alpha, c_alpha,
13981401 full_gibbs = TRUE, M = M)
1399- h=300
1402+ h=1000
14001403thin=seq(from=1, to=M,by=h)
14011404
14021405mu1=exp(res_check_full$beta_post[,1])
@@ -1461,10 +1464,9 @@ qqplot(log(ov2_prior),log(ov2), xlab = "Prior",xlim=c(0,10), ylim=c(0,10),
14611464 ylab = "Posterior", main = "Overdispersion for X=1")
14621465abline(a = 0, b = 1)
14631466text(5,0.1, paste0('KS-test: p-value= ', round(ks2$p.value,4)))
1464-
14651467```
14661468
1467- We next run the ivalid partially marginalised Gibbs sampler.
1469+ We next run the invalid partially marginalised Gibbs sampler.
14681470
14691471``` {r, echo = -c(1:3)}
14701472if (pdfplots) {
@@ -1495,7 +1497,6 @@ qqplot(log(ov2_prior),log(ov2), xlab = "Prior",xlim=c(0,10), ylim=c(0,10),
14951497 ylab = "Posterior", main = "Overdispersion for X=1")
14961498abline(a = 0, b = 1)
14971499text(5,0.1, paste0('KS-test: p-value= ', round(ks2$p.value,4)))
1498-
14991500```
15001501Also for the partially marginalised Gibbs sampler both p-values are larger than
150115020.05 and hence we fail to detect that this sampler is wrong.
@@ -1506,7 +1507,16 @@ versus the heterogeneity parameter $\alpha$
15061507if (pdfplots) {
15071508 pdf("8-2_7.pdf", width = 8, height = 4)
15081509}
1509- par(mfrow = c(2,3), mar = c(2.5, 2.5, 1.5, .1), mgp = c(1.5, .5, 0), lwd = 1.5)
1510+ par(mfrow = c(3,3), mar = c(2.5, 2.5, 1.5, .1), mgp = c(1.5, .5, 0), lwd = 1.5)
1511+
1512+ plot(res_check_full$beta_post[thin,1],res_check_full$beta_post[thin,2],
1513+ xlab="beta1", ylab="beta2",main="full",xlim=c(-1,2),
1514+ ylim=c(0.5,3.5))
1515+ plot(res_partial$beta_post[thin,1],res_partial$beta_post[thin,2],
1516+ xlab="beta1", ylab="beta2",main="correct partial",xlim=c(-1,2), ylim=c(0.5,3.5))
1517+ plot(res_check_partial$beta_post[thin,1],res_check_partial$beta_post[thin,2],
1518+ xlab="beta1", ylab="beta2",main="incorrect partial",xlim=c(-1,2),
1519+ ylim=c(0.5,3.5))
15101520
15111521plot(res_check_full$beta_post[thin,1],res_check_full$alpha_post[thin],
15121522 xlab="beta1", ylab="alpha",main="full",xlim=c(-1,2), ylim=c(0,1.4))
@@ -1516,11 +1526,11 @@ plot(res_check_partial$beta_post[thin,1],res_check_partial$alpha_post[thin],
15161526 xlab="beta1", ylab="alpha",main="incorrect partial",xlim=c(-1,2), ylim=c(0,1.4))
15171527
15181528plot(res_check_full$beta_post[thin,2],res_check_full$alpha_post[thin],
1519- xlab="beta2", ylab="alpha",xlim=c(0.5,3.5), ylim=c(0,1.4))
1529+ xlab="beta2", ylab="alpha",main="full", xlim=c(0.5,3.5), ylim=c(0,1.4))
15201530plot(res_partial$beta_post[thin,2],res_partial$alpha_post[thin],
1521- xlab="beta2", ylab="alpha",xlim=c(0.5,3.5), ylim=c(0,1.4))
1531+ xlab="beta2", ylab="alpha",main="correct partial", xlim=c(0.5,3.5), ylim=c(0,1.4))
15221532plot(res_check_partial$beta_post[thin,2],res_check_partial$alpha_post[thin],
1523- xlab="beta2", ylab="alpha",xlim=c(0.5,3.5), ylim=c(0,1.4))
1533+ xlab="beta2", ylab="alpha",main="incorrect partial", xlim=c(0.5,3.5), ylim=c(0,1.4))
15241534```
15251535# Section 8.3: Beyond i.i.d. Gaussian error distributions
15261536
0 commit comments