Skip to content

Fit the needle-sharing negative binomial model with glmmTMB - #1505

Merged
dem-extra1 merged 5 commits into
mainfrom
claude/project-thread-yn1t83
Nov 20, 2026
Merged

dem-extra1 merged 5 commits into
mainfrom
claude/project-thread-yn1t83

Conversation

@dem-extra1

@dem-extra1 dem-extra1 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Requested by Ezra · project thread

Why

The Quarto Publish run on main failed in the fit-nb-model chunk of the count regression chapter:

Error in `glm.fitter()`: ! NA/NaN/Inf in 'x'
 1. \-MASS::glm.nb(...)
Quitting from count-regression.qmd [fit-nb-model]

The previous run on the same chapter code (44258776156) passed: #1495 changed only a workflow file. So the failure is not from a content change. MASS::glm.nb() never converges on these data:

  • The live page already shows Warning while fitting theta: alternation limit reached and Theta 0.0475, which is not the MLE.
  • Run locally, glm.nb() swings between theta ≈ 0.1 and theta ≈ 10^5 and fails or stops at the alternation limit. It also does this when started at the MLE: the IRLS step for the coefficients at theta ≈ 0.1 does not converge in 25 iterations. Whether it errors or just warns depends on floating-point details, which is why CI flips between the two.
  • A direct optim() fit of the NB log-likelihood and glmmTMB(family = nbinom2) agree: theta-hat ≈ 0.091, log-likelihood −116.5 (n = 109).

What changed

  • chapters/exr-needle-sharing-extensions.qmd: fit glm1_nb with glmmTMB::glmmTMB(family = glmmTMB::nbinom2). This is the same package the section already uses for the ZIP and ZINB fits. A ::: notes aside explains why glm.nb() is not used, and notes that nbinom2's variance matches @eq-nb-reg-var.
  • Show the NB coefficient table with parameters() |> print_md(), the same way as the ZIP/ZINB tables. Drop equatiomatic::extract_eq(glm1_nb) because it has no glmmTMB method. The intro sentence now links #def-nb-reg and says the model uses the Poisson model's covariates.
  • Comparison table: use fixef(glm1_nb)$cond and summary(glm1_nb)$coefficients$cond.
  • Comparison prose: the old text said the coefficients "remain comparable". The fitted values show that only the homelessness coefficient does (Poisson 1.80, NB 2.02). sex, ethnOther and others shift or change sign. NB SEs are about 4 to 9 times the Poisson SEs. The prose now says that.
  • Term links for the defined terms in the new prose (rme, sds, pds, mds and mcs definitions).
  • references.bib: add brooks2017glmmTMB (The R Journal 9(2):378–400, from citation("glmmTMB")).

Temporary: .github/workflows/preview.yml

This branch also carries #1507's commit, which is not yet on main. It drops libnode109 from the preview build's apt list, because Ubuntu 26.04 runners no longer ship it. Without it, this PR's preview build stops at apt. #1507's own build in turn fails on the glm.nb crash this PR fixes, so the two PRs are tested together here. Once #1507 merges to main, this file drops out of this PR's diff.

Checks

  • lintr::lint() on the changed .qmd: no lints.
  • Spelling on the changed file: no new words. slidebreak and ZINB are flagged on lines this PR did not touch.
  • I could not render the full chapter here: renv::restore() needs GitHub remotes (pharmaverse/cards, rmb, …) that the cloud session cannot reach. Instead I rendered a cut-down page to HTML. It had the chapter's data-loading code, def-nb-reg, and the edited subfile. It rendered cleanly: citations resolved, @eq-nb-reg-var resolved, and the tables printed the values above. The PR preview build is the full-chapter render check.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FWgYrGaqBPMWkVzew6UErH

MASS::glm.nb() never converges on the needle-sharing data: the live page
shows "alternation limit reached", and the Quarto Publish run 44260089362
on main stopped with "NA/NaN/Inf in 'x'" in the fit-nb-model chunk.
glmmTMB(family = nbinom2) maximizes the likelihood directly and reaches
the maximum likelihood estimate (theta about 0.091, log-likelihood -116.5),
matching a direct optim() fit.

Also show the NB coefficient table with parameters(), drop the
equatiomatic call (it has no glmmTMB method), cite glmmTMB, and reword
the comparison prose to match the fitted values: the homelessness
coefficient changes little, several adjustment coefficients shift or
change sign, and the NB standard errors are several times the Poisson ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FWgYrGaqBPMWkVzew6UErH
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

check-term-links flagged unlinked first uses of defined terms on the
changed lines. Link them to their definitions in rme, sds, pds, mds and
mcs; the quoted R warning and error keep an allow pragma with the reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FWgYrGaqBPMWkVzew6UErH
ubuntu-latest now runs Ubuntu 26.04 (resolute), which no longer ships
libnode109, so gha@v3's default apt list stops the preview build before
any render: "Package 'libnode109' has no installation candidate"
(rme#1505's build, run 44714570873). Pass gha's default list without
libnode109; libnode-dev depends on libnode127 on resolute and on
libnode109 on noble, so V8 still gets its runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FWgYrGaqBPMWkVzew6UErH

Copy link
Copy Markdown
Collaborator Author

CI status on f5018e3, the first head:

  • check-term-links: fixed in 05ebbad. The changed lines now link their defined terms. I re-ran it locally with mds, pds and sds as term sources and it came back clean.
  • build / build: not caused by this PR. The apt step failed with Package 'libnode109' has no installation candidate, because ubuntu-latest is now Ubuntu 26.04 and gha@v3's default apt list still names libnode109. The fix is in #1507. This PR's preview build can't run until that merges.
  • link-checker: not caused by this PR. The three failures are network errors reaching web.stanford.edu/class/stats191 and stats202. Those links are in other chapters, not in this diff.

Posted by Claude Code (AI agent) --- not written by a human.


Generated by Claude Code

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Temporary: once #1507 merges to main, this change drops out of the diff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FWgYrGaqBPMWkVzew6UErH
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Collaborator Author

A correction to the review on 3a7741c: #1507 has not merged. The preview.yml change is therefore part of this PR's diff against main right now. It's here on purpose, for now. #1507's build fails on the glm.nb crash that this PR fixes (job), and this PR's build fails at apt without #1507. So this branch tests the two together. The PR body now says so.

Merge order: this PR first, then #1507. Once #1507 is on main, the workflow file drops out of this diff. Merging this PR first brings the same commit to main, and #1507 then has nothing left to add.


Posted by Claude Code (AI agent) --- not written by a human.


Generated by Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

Claude finished review — View run


The new head, 35557e9, differs from the last reviewed commit only by a routine merge of origin/main. Git's automatic merge of its parents gives the same result, and the one commit it brings in (c38684d, the check-citation-authors caller from gha#2150) is already on main. The PR's own content is unchanged: the needle-sharing glmmTMB swap in chapters/exr-needle-sharing-extensions.qmd and the new brooks2017glmmTMB entry in references.bib. This confirms the 2026-11-20 review of 3a7741c, Ready for merge. That verdict still stands.

I did not render the chapter or run the fit. The numeric prose claims remain unchecked.

What I checked

  • Scope: the saved PR diff touches .github/workflows/preview.yml, chapters/exr-needle-sharing-extensions.qmd and references.bib.
  • Workflow change: the preview.yml hunk is the apt-packages: override that drops libnode109. It matches the fix already merged to main as Drop libnode109 from the preview build's apt packages #1507. It shows up in the saved diff only because that fix reached this branch through merges of main. The PR adds no workflow changes of its own, so I raise no finding under the CLAUDE.md rule that workflow changes go in separate PRs.
  • Math and macros: the new merge commit adds no math, so I did no macro check.

Suggestions (non-blocking, carried over)

  • chapters/exr-needle-sharing-extensions.qmd:51-59: the prose says the homelessness coefficient "changes little", some adjustment coefficients "change sign", and the standard errors are "several times" the Poisson ones. Please confirm these against the table in the PR preview.
  • chapters/exr-needle-sharing-extensions.qmd:34: the glm.nb() "alternation limit reached" claim has no citation or reproducible output.
  • chapters/exr-needle-sharing-extensions.qmd:34 and :56:
    • The "coefficients" link goes to mds/linear-algebra-vectors.html#def-linear-combination, which defines a linear combination, not a regression coefficient.
    • The "converge" and "sequence" links go to definitions of convergence of a mathematical sequence. That fits the convergence of an iterative fitting algorithm only loosely.

Verdict

Ready for merge

Structured Review Data (JSON)
{
  "schema_version": "1.1",
  "reviewer": "claude",
  "commit_sha": "35557e9a1c1c83aa0a3236a3cb891cab14685668",
  "verdict": "CLEAN",
  "findings": [],
  "detailed_assessment": "Head 35557e9 is a merge of origin/main matching git's automatic merge; the chapters/exr-needle-sharing-extensions.qmd glmmTMB change and its references.bib entry are unchanged since the last review.",
  "holistic_assessment": "The PR is a small, coherent model-fitting swap; remaining risk is only that hard-coded numeric prose may not match rendered coefficients, which stays an unverified non-blocking suggestion."
}

Reviewed commit: 35557e9

@github-actions

Copy link
Copy Markdown
Contributor

💰 Cost: $0.2589 (review) — run

Copy link
Copy Markdown
Collaborator Author

Replies to the non-blocking suggestions in the review of 35557e9:

  • Numeric prose: checked against the rendered comparison table.

    • Homelessness goes from 1.799 to 2.022.
    • sexF (0.88 to −0.35) and ethnOther (0.036 to −1.94) change sign.
    • NB SE / Poisson SE runs from 3.8 (hivstat) to 8.7 (intercept).

    The prose matches.

  • "alternation limit reached": this is reproducible output. The published page on main printed this warning before this PR, and Quarto Publish run 44260089362 shows the error form. The aside documents why the code doesn't call glm.nb(), so a rendered call isn't needed.

  • Link targets: def-linear-combination is where mds defines the coefficients of a linear combination, which is what the linear predictor's coefficients are. def-convergent-sequence and def-sequence fit too, because the prose describes a sequence of iterates that does not converge. None of the notes sites defines "regression coefficient" or "algorithm convergence" more narrowly. I'm leaving these as they are.


Posted by Claude Code (AI agent) --- not written by a human.


Generated by Claude Code

Copy link
Copy Markdown
Collaborator Author

Cross-model review (OpenCode Go free tier; the paid Go models hit their weekly limit):

  • Round 1 (iceman-contributor-free) was NOT_CLEAN. It flagged parameters() / print_md() as unqualified, which could fail with "could not find function". That's a false positive. The unchanged ZIP and ZINB chunks on main already call parameters(exponentiate = TRUE) |> print_md() unqualified, and the full-site render of this chapter content passed in run 44717052863.
  • Round 2 had that context and came back CLEAN, on the same diff (head 35557e9).

beam-free returned empty answers on both rounds.

Annotation dispositions for head 35557e9:

  • link-checker, web.stanford.edu/class/stats191 and .../stats202/intro.html network errors: false positives. Stanford's host refused the runner, on lines this PR does not touch.
  • link-checker, any 5xx from epiresearch.org or github.com: false positive. A transient server error on lines this PR does not touch.
  • review / claude-review notices ("SUBMODULES_TOKEN is empty", "PR edits workflow files; restored .github/workflows/ from the default branch"): routine notices. The only submodule is public, and the restore is gha's safety step for workflow-editing PRs.

Posted by Claude Code (AI agent) --- not written by a human.


Generated by Claude Code

Copy link
Copy Markdown
Collaborator Author

build / build on 35557e9 hit the 45-minute job limit (job) without reaching the render. It spent the whole time in the apt install. The Azure Ubuntu mirror was serving packages at a crawl: cmake (14 MB) took 5 minutes, libgraphblas7 (31 MB) took 10, and libnode127 (16.5 MB) took 4. The same apt list installed in under a minute on this PR's earlier build. This is a runner-side mirror slowdown, not this PR's change, so I re-ran the failed job.


Posted by Claude Code (AI agent) --- not written by a human.


Generated by Claude Code

@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.2
🚀 Preview available at: https://Morrison-Lab.github.io/rme/pr-preview/pr-1505/

Built to branch gh-pages at 2026-11-20 19:04 UTC.

Copy link
Copy Markdown
Collaborator Author

Annotation dispositions for head 35557e9:

  • link-checker, https://web.stanford.edu/class/stats191 network error (chapters/index.qmd:31, chapters/Linear-models-overview.qmd:41): false positive. Stanford's host refused the runner, on lines this PR does not touch.
  • link-checker, https://web.stanford.edu/class/stats202/intro.html network error (chapters/other-resources.qmd:150): false positive, for the same reason.
  • link-checker, https://epiresearch.org/membership/ser-careers/ 520, live and cached (_subfiles/syllabus/_sec-course-evaluations.qmd:4, 2 annotations): false positive. A transient server error on a line this PR does not touch, and the checker says it is not failing the check.
  • review / claude-review notices ("SUBMODULES_TOKEN is empty"; "PR edits workflow files; restored .github/workflows/ from the default branch"): routine. The only submodule is public, and the restore is gha's safety step for PRs that edit workflows.

The re-run build / build (attempt 2) passed and carries no annotations.


Posted by Claude Code (AI agent) --- not written by a human.


Generated by Claude Code

@dem-extra1
dem-extra1 merged commit 8b7fbb5 into main Nov 20, 2026
42 of 43 checks passed
@dem-extra1
dem-extra1 deleted the claude/project-thread-yn1t83 branch November 20, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants