Skip to content

Correct Jacobian for the initial Rt prior - #1478

Merged
sbfnk merged 4 commits into
mainfrom
fix-rt-prior-jacobian
Jul 22, 2026
Merged

Correct Jacobian for the initial Rt prior#1478
sbfnk merged 4 commits into
mainfrom
fix-rt-prior-jacobian

Conversation

@sbfnk-bot

Copy link
Copy Markdown
Collaborator

Description

This PR closes #1475.

Since #1396 the user's prior on the initial reproduction number is applied to the derived initial Rt, R[1], in init_priors_lp(). R_mean is declared real<lower = 0>, so Stan already adds log(R_mean) for the lower-bound transform, and the hand-written target += log(R[1]) then double-counts it, leaving a spurious +log(R_mean) in the target. The prior is shifted upwards by exp(sdlog^2) — a LogNormal(mean = 2, sd = 1) prior behaves as if its mean were 2.5.

The correction relative to the sampled parameter is log(R[1]) - log(R_mean). This PR makes that change, corrects the derivation in the GP implementation vignette (which assumed the internal parameter was sampled on the log scale), and adds a prior-recovery regression test.

A prior-only fit recovers the requested prior after the change:

median R[1]
requested LogNormal(mean = 2, sd = 1) 1.789
before 2.234
after 1.799

Initial submission checklist

  • My PR is based on a package issue and I have explicitly linked it.
  • I have tested my changes locally.
  • I have added or updated unit tests where necessary.
  • I have updated the documentation if required and rebuilt docs if yes.
  • I have followed the established coding standards (and checked using lintr::lint_package()).
  • I have added a news item linked to this PR.

Co-authored-by: sbfnk <sebastian.funk@lshtm.ac.uk>
@sbfnk-bot
sbfnk-bot requested a review from sbfnk July 16, 2026 12:21
@sbfnk
sbfnk marked this pull request as ready for review July 16, 2026 12:25
Co-authored-by: sbfnk <sebastian.funk@lshtm.ac.uk>
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution sbfnk 🚀! Your synthetic_recovery markdown is ready for download 👉 here 👈!
(The artifact expires on 2026-07-27T08:18:26Z. You can re-generate it by re-running the workflow here.)

sbfnk
sbfnk previously approved these changes Jul 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 7e9c085 is merged into main:

  • ✔️estimate_dist: 628ms -> 635ms [-1%, +3.21%]
  • ✔️estimate_infections_gp: 23.8s -> 13.9s [-131.03%, +48.03%]
  • ✔️estimate_infections_rw: 12.1s -> 6.41s [-153.81%, +59.49%]
  • ✔️estimate_secondary: 1.42s -> 1.4s [-9.28%, +6.98%]
  • ✔️estimate_truncation: 1.31s -> 1.36s [-3.79%, +10.47%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Co-authored-by: sbfnk <sebastian.funk@lshtm.ac.uk>
@github-actions

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 1be44b4 is merged into main:

  • ✔️estimate_dist: 750ms -> 757ms [-0.69%, +2.51%]
  • ✔️estimate_infections_gp: 17.9s -> 20.5s [-35.56%, +65.12%]
  • ✔️estimate_infections_rw: 28.5s -> 11.2s [-223.34%, +102.02%]
  • ✔️estimate_secondary: 1.63s -> 1.7s [-1.22%, +10.15%]
  • ✔️estimate_truncation: 1.65s -> 1.64s [-12.98%, +12.08%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

sbfnk
sbfnk previously approved these changes Jul 16, 2026
@sbfnk
sbfnk enabled auto-merge July 16, 2026 17:51
@sbfnk
sbfnk requested a review from seabbs July 20, 2026 15:33
seabbs
seabbs previously approved these changes Jul 22, 2026

@seabbs seabbs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@sbfnk
sbfnk dismissed stale reviews from seabbs and themself via 629739c July 22, 2026 08:06
@sbfnk-bot sbfnk-bot added llm-reviewed Reviewed by the wait-for-review loop and removed claude-reviewed labels Jul 22, 2026
@sbfnk
sbfnk disabled auto-merge July 22, 2026 08:46
@sbfnk
sbfnk merged commit eb3de85 into main Jul 22, 2026
15 checks passed
@sbfnk
sbfnk deleted the fix-rt-prior-jacobian branch July 22, 2026 08:46
@github-actions

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 629739c is merged into main:

  • ✔️estimate_dist: 539ms -> 534ms [-1.91%, +0.13%]
  • ✔️estimate_infections_gp: 11.3s -> 11s [-11.19%, +5.35%]
  • ✔️estimate_infections_rw: 5.53s -> 5.2s [-14.53%, +2.92%]
  • ❗🐌estimate_secondary: 1.09s -> 1.2s [+4.03%, +16.98%]
  • ✔️estimate_truncation: 1.08s -> 1.11s [-5.43%, +12.22%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llm-reviewed Reviewed by the wait-for-review loop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rt prior is applied with the wrong Jacobian and comes out biased upwards

3 participants