add intro to mcmc techniques for Bayesian inference#837
add intro to mcmc techniques for Bayesian inference#837github-actions[bot] wants to merge 22 commits into
Conversation
Adapts content from Dobson & Barnett 4e Chapter 13. Covers Monte Carlo integration, the Metropolis-Hastings algorithm, the Gibbs sampler, burn-in, convergence diagnostics (trace plots, ACF, Gelman-Rubin), and posterior inference from MCMC samples, with worked R examples using the Bernoulli model. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Claude finished @d-morrison's task in 3m 41s —— View job Code Review — PR #837: Intro to MCMC Techniques
SummaryThe new Critical1.
Every occurrence of Significant2.
The trace plot chunk should be restructured as: :::{#exm-trace-plot}
## Trace plot for MH chain
:::{#fig-trace-mh}
```{r}
#| code-fold: show
library(ggplot2)
burnin <- 500L
df_chain <- data.frame(iteration = seq_along(mh_chain), pi = mh_chain)
ggplot(df_chain, aes(x = iteration, y = pi)) +
geom_line(linewidth = 0.2, alpha = 0.7) +
geom_vline(xintercept = burnin, linetype = "dashed", colour = "red") +
labs(x = "Iteration", y = expression(pi)) +
theme_bw()MH chain trace plot; dashed line marks end of burn-in. ::: The length of the burn-in period is chosen by inspection of trace plots JAGS (Just Another Gibbs Sampler) automates this approach for a wide class of models; and removes the blank line that preceded the JAGS section. This integration is correct: the section heading is in the parent (not the subfile), satisfying the subfile convention. No issues here beyond the forward reference noted in item 4 above. VerdictThis PR should not be merged in its current state due to the undefined |
|
@claude address review comments |
|
👀 Picked up by workflow run #26543221524. R/Quarto/renv setup runs first (~3-5 min); Claude itself responds after that. |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@claude review |
|
👀 Picked up by workflow run #26553161091. R/Quarto/renv setup runs first (~3-5 min); Claude itself responds after that. |
|
Claude finished @d-morrison's task in 2m 37s —— View job Code Review — PR #837 (re-review after fixes)
What Was FixedCommit
Remaining IssuesSignificant 1. Trace plot figure has no caption and no div wrapper The
The trace plot currently renders as an unlabeled, uncaptioned plot inside an example div — not suitable for a textbook. The chunk at :::{#fig-trace-mh}
```{r}
#| code-fold: show
burnin <- 500L
df_chain <- data.frame(iteration = seq_along(mh_chain), pi = mh_chain)
ggplot(df_chain, aes(x = iteration, y = pi)) +
geom_line(linewidth = 0.2, alpha = 0.7) +
geom_vline(xintercept = burnin, linetype = "dashed", colour = "red") +
labs(x = "Iteration", y = expression(pi)) +
theme_bw()MH chain trace plot; dashed line marks end of burn-in. |
|
@claude iterate |
|
👀 Picked up by workflow run #26641130635. R/Quarto/renv setup runs first (~3-5 min); Claude itself responds after that. |
|
Claude finished @d-morrison's task in 2m 11s —— View job Code Review — PR #837 (post-iterate, round 3)
What Was Fixed by the Iterate CommitsCommits
One Remaining Minor Nit
Structural Note (no action required)
VerdictAll critical and significant issues from prior reviews are resolved. The only remaining item is the low-priority |
|
@claude address review comments, even nits; also why doesn't https://d-morrison.github.io/rme/pr-preview/pr-837/chapters/intro-bayes.html#sec-mcmc:~:text=a%20Bernoulli%20model)-,We%20implement%20the,-MH%20algorithm%20for have an exercise number? also fix all broken crossrefs; note in ai instructions, cross-chapter crossrefs need to handled differently from within-chapter crossrefs |
|
👀 Picked up by workflow run #26988088244. R/Quarto/renv setup runs first (~3-5 min); Claude itself responds after that. |
|
@claude also adapt the rest of the content from dobson |
|
Claude finished @d-morrison's task in 4m 26s —— View job Code Review — PR #837 (round 6)
What's New in This Round
All fixes from rounds 1–5 are intact. Five issues remain — one of them rendering-critical. Critical1.
The term $D(\bar{\vth})$ rewards fit, while $p_D$ penalizesSignificant2. Forward reference to
3. Forward reference to
4. "Recall the Beta-Bernoulli model" without a cross-chapter link (
The Beta-Bernoulli model with these exact numbers is now formally introduced in Recall the Beta-Bernoulli model of
[Example B](intro-bayes.qmd#exm-beta-bernoulli),
with $n = 91$ observations and $r = 55$ successes.Moderate (carry-forward from round 5)5. Missing citation for JAGS claim ( No citation. CLAUDE.md: "Factual claims must have a specific citation." Should add 6. Three occurrences of 7. Inside the definition: \mathrm{DIC} &\eqdef D(\bar{\vth}) + 2\,p_D = \overline{D} + p_D.Distribution/operator names use Minor8. Two raw-LaTeX usages:
New Files — No Issues
VerdictOne rendering-critical bug remains ( |
…0527-185948 Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Replace the skeleton framing in the example-analyses appendix with three original, self-contained worked analyses fit in JAGS (simulated data, known truth, posterior recovery): - Bayesian logistic regression: recover intercept/slope and the odds ratio from simulated binary data. - Bayesian exponential survival regression: right-censored survival via the zeros trick, recovering the log hazard ratio. - Bayesian random-intercept model: recover the overall mean and the between/within-group SDs, highlighting credible intervals for the variance component. Bayesian model averaging remains conceptual (it spans a collection of models) and now points to the DIC section and the predictor-selection chapter. Examples render numbered now that #895 (exm numbering) is in main. JAGS verified locally after fixing the jags-terminal symlink. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
|
Claude finished @d-morrison's task in 5m 2s —— View job Code Review — PR #837 (round 7)
What's New Since Round 6Commit None of the seven round-6 findings were addressed by these commits — they remain open. Carry-forward: Critical1.
The term $D(\bar{\vth})$ rewards fit, while $p_D$ penalizesCarry-forward: Significant2. Forward reference
3. Forward reference Inside
4. "Recall the Beta-Bernoulli model" needs cross-chapter link (
Recall the Beta-Bernoulli model of
[Example B](intro-bayes.qmd#exm-beta-bernoulli),
with $n = 91$ observations and $r = 55$ successes.Carry-forward: Moderate5. Missing citation for JAGS claim ( CLAUDE.md: "Factual claims must have a specific citation." Add Carry-forward: Minor nits6. Used in three places in 7. \mathrm{DIC} &\eqdef D(\bar{\vth}) + 2\,p_D = \overline{D} + p_D.Distribution/operator names use 8. Two raw-LaTeX usages:
New content — no issuesThe three new JAGS examples in VerdictSeven issues carry forward from round 6 (all still present), with issue 1 ( |
|
@claude address reviews |
|
👀 Picked up by workflow run #27047682804. R/Quarto/renv setup runs first (~3-5 min); Claude itself responds after that. |
- Replace undefined \dev macro with D in DIC prose (mcmc-methods.qmd)
- Use \operatorname{DIC} instead of \mathrm{DIC} in equation
- Remove forward reference @exm-normal-credible-vs-confidence (intro-bayes.qmd)
- Remove forward reference @sec-bayes-conjugate from normal-normal section
- Use cross-chapter link for Beta-Bernoulli example (_sec-mcmc.qmd)
- Add citation for JAGS claim [@dobson4e, Chapter 13]
- Use \logit macro and \tp{\vxi} for transpose (bayesian-examples.qmd)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
71e38f1 to
683a5b6
Compare
|
Claude finished @d-morrison's task in 2m 51s —— View job Code Review — PR #837 (round 8)
What Was Fixed Since Round 7All seven round-7 findings were addressed:
One Remaining Nit
And once in
The codebase defines VerdictAll critical, significant, and moderate issues from all prior rounds are resolved. The only remaining item is the low-priority |
…0527-185948 Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Replace the conceptual-only model-averaging section with a worked, base-R example: enumerate all subsets of three predictors (one irrelevant), weight models by the BIC approximation to the posterior model probability [@schwarz1978estimating], and report posterior inclusion probabilities and a model-averaged slope. Recovers high inclusion for the true predictors, low for the irrelevant one, and a model-averaged slope near the true value. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
…' into claude/issue-836-20260527-185948 Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
|
Claude finished @d-morrison's task in 2m 41s —— View job Code Review — PR #837 (round 9)
What's New Since Round 8Commit Carry-forward: Nit1. Still unresolved from round 8. Raw
And once in
No New issue from the BMA addition2.
New content — no issues
VerdictTwo items remain: the carry-forward |
- Bump latex-macros to pick up the new \hR macro (d-morrison/macros#63) and replace the four raw \hat{R} / \hat R occurrences with \hR (Gelman-Rubin statistic) in _sec-mcmc.qmd and bayesian-examples.qmd. - \mathrm{BIC} -> \operatorname{BIC} in the BMA example, matching the book convention for criterion names (as done for \operatorname{DIC}). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
|
Claude finished @d-morrison's task in 2m 34s —— View job Code Review — PR #837 (round 10)
What Was Fixed Since Round 9Commit
No Remaining IssuesA scan of all changed files for lingering raw-LaTeX operator names ( VerdictAll critical, significant, moderate, and minor issues from rounds 1–9 are resolved. The PR is ready to merge. |
|
Claude finished @d-morrison's task in 3m 59s —— View job Code Review — PR #837 (round 11)
What Was Fixed Since Round 10The merge commit
One Nit
VerdictAll critical, significant, and moderate issues from all prior rounds are resolved. The only remaining item is the low-priority redundant |
Built to branch |
Draft PR opened by
@claudeto address #836.Triggered by workflow run.
Addresses #836.