@@ -221,9 +221,9 @@ We now compute Chib's estimator, evaluated at the posterior median.
221221
222222``` {r}
223223allres <- list(res, res2, res3)
224- logML <- matrix(NA_real_, length(allres), length(allres[[1]] ))
224+ logML <- matrix(NA_real_, length(allres), length(res ))
225225for (i in seq_along(allres)) {
226- for (j in seq_len(length(allres[[i]] ))) {
226+ for (j in seq_len(length(res ))) {
227227 myres <- allres[[i]][[j]]
228228 beta_med <- apply(myres$betas, 2, median)
229229 sigma2_med <- median(myres$sigma2s)
@@ -251,6 +251,20 @@ names(pairwiselogML) <- names(logSD)
251251round(pairwiselogML, 2)
252252```
253253
254+ To compute model probabilities, we use the uniform and the penalty prior.
255+
256+ ``` {r}
257+ # Uniform prior:
258+ stableML <- exp(logML[3, ] - max(logML[3, ]))
259+ probs_unif <- stableML / sum(stableML)
260+
261+ # Penalty prior:
262+ tmp <- logML[3, ] - log(seq_along(stableML)) - log(seq_along(stableML) + 1)
263+ stablepost <- exp(tmp - max(tmp))
264+ probs_pen <- stablepost / sum(stablepost)
265+
266+ knitr::kable(t(round(cbind(unif = probs_unif, penalized = probs_pen), 3)))
267+ ```
254268
255269## Section 11.4.3: Bayesian testing for first-order Markov Chain models
256270
0 commit comments