Skip to content

Add estimate_dist() with primarycensored support#1317

Open
sbfnk wants to merge 130 commits intomainfrom
claude/estimate-dist-primarycensored-019U6v1DGjxbeXVpt1eCe7U2
Open

Add estimate_dist() with primarycensored support#1317
sbfnk wants to merge 130 commits intomainfrom
claude/estimate-dist-primarycensored-019U6v1DGjxbeXVpt1eCe7U2

Conversation

@sbfnk
Copy link
Copy Markdown
Contributor

@sbfnk sbfnk commented Feb 20, 2026

Description

This PR closes #350.

Adds estimate_dist() for fitting delay distributions using primarycensored's interval-censored likelihood. Replaces the deprecated estimate_delay().

Changes:

  • New estimate_dist() function supporting lognormal, gamma, and weibull distributions
  • Vendors primarycensored Stan functions into inst/stan/primarycensored/ for pre-compilation
  • Deprecates estimate_delay() with a warning pointing to the new function
  • Adds tests for the new function

Related: #1268 (vendored Stan files enable future discretised_pmf work, not included here).

Initial submission checklist

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

After the initial Pull Request

  • I have reviewed Checks for this PR and addressed any issues as far as I am able.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added estimate_dist() function for fitting epidemiological delay distributions using MCMC-based Bayesian inference with proper handling of interval censoring and truncation.
  • Deprecations

    • Deprecated estimate_delay() in favour of estimate_dist(), which provides improved support for censoring and truncation scenarios.
  • Documentation

    • Added comprehensive vignette and documentation for fitting delay distributions with worked examples and interpretation guidance.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 20, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b87b94cb-0a6d-4674-8003-c032ad562a4e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Adds a new exported function estimate_dist with Stan‑based primary‑censored interval‑censoring support, vendors new Stan functions and a Stan model, updates registration and docs, and deprecates estimate_delay.

Changes

Cohort / File(s) Summary
Core R implementation
R/estimate_dist.R, R/estimate_delay.R
Adds estimate_dist() (implementation, helpers .prepare_delay_intervals, .extract_to_dist_spec, priors, Stan integration); marks estimate_delay() as deprecated and forwards calls with a lifecycle warning.
Stan models & functions
inst/stan/estimate_dist.stan, inst/stan/functions/primarycensored.stan
Adds new Stan model estimate_dist.stan and comprehensive primarycensored functions (analytical and numerical likelihoods, truncation handling, ODE fallback, many distribution lcdf/lpdf helpers).
Registration & build
NAMESPACE, R/stan.R, R/stanmodels.R
Exports estimate_dist, registers "estimate_dist" in epinow2_stan_model allowed values, and loads the corresponding Stan module.
Documentation & website
man/estimate_dist.Rd, man/estimate_delay.Rd, man/dot-*.Rd, man/epinow2_stan_model.Rd, _pkgdown.yml, NEWS.md
Adds user docs for estimate_dist, updates estimate_delay docs to deprecate and point to estimate_dist, documents internal helpers, updates Stan model docs and pkgdown reference, and records changes in NEWS.
Tests
tests/testthat/test-estimate_dist.R
Adds tests validating lognormal/gamma parameter recovery, data frame input handling, error cases, max_value behaviour and deprecation warning for estimate_delay.

Possibly related issues

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarises the main change: adding a new estimate_dist() function with primarycensored support, which is the primary objective of this PR.
Linked Issues check ✅ Passed The PR successfully addresses all coding objectives from issue #350: implements estimate_dist() as a generalised replacement for estimate_delay(), vendors primarycensored Stan functions, supports lognormal/gamma distributions with proper censoring handling, and includes comprehensive tests.
Out of Scope Changes check ✅ Passed All changes are within scope. The PR includes the new estimate_dist() function, deprecation of estimate_delay(), Stan vendoring, documentation updates, and tests—all directly aligned with issue #350 objectives. No extraneous changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/estimate-dist-primarycensored-019U6v1DGjxbeXVpt1eCe7U2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sbfnk sbfnk force-pushed the claude/estimate-dist-primarycensored-019U6v1DGjxbeXVpt1eCe7U2 branch from 52612b5 to 73be744 Compare February 20, 2026 10:04
sbfnk and others added 4 commits February 20, 2026 10:05
Co-Authored-By: sbfnk_bot
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
Co-Authored-By: sbfnk_bot
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
- Move primarycensored Stan functions to inst/stan/primarycensored/
- Update estimate_dist.stan to include vendored functions
- Add estimate_dist to pre-compiled stanmodels
- Simplify R code to use pre-compiled model instead of runtime compilation
- Fix tests to check dist_spec structure correctly

Co-Authored-By: sbfnk_bot
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
Co-Authored-By: sbfnk_bot
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
@sbfnk sbfnk force-pushed the claude/estimate-dist-primarycensored-019U6v1DGjxbeXVpt1eCe7U2 branch from 73be744 to 87d3308 Compare February 20, 2026 10:05
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
@sbfnk sbfnk force-pushed the claude/estimate-dist-primarycensored-019U6v1DGjxbeXVpt1eCe7U2 branch from 65835d3 to e6d1979 Compare February 20, 2026 11:07
Comment thread inst/stan/estimate_dist.stan Outdated
Comment thread inst/stan/estimate_dist.stan
sbfnk and others added 2 commits February 20, 2026 11:28
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
…ored-019U6v1DGjxbeXVpt1eCe7U2' into claude/estimate-dist-primarycensored-019U6v1DGjxbeXVpt1eCe7U2
seabbs

This comment was marked as outdated.

sbfnk and others added 2 commits February 20, 2026 14:01
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
Comment thread inst/stan/functions/primarycensored.stan Outdated
sbfnk and others added 6 commits February 20, 2026 17:01
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
…ored-019U6v1DGjxbeXVpt1eCe7U2' into claude/estimate-dist-primarycensored-019U6v1DGjxbeXVpt1eCe7U2
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
Comment thread tests/testthat/test-estimate_dist.R Outdated
sbfnk and others added 4 commits February 24, 2026 08:18
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
…ored-019U6v1DGjxbeXVpt1eCe7U2' into claude/estimate-dist-primarycensored-019U6v1DGjxbeXVpt1eCe7U2
Co-authored-by: sbfnk-bot <242615673+sbfnk-bot@users.noreply.github.com>
Shape and rate parameters in the gamma distribution are correlated
and poorly identified individually. The mean (shape/rate) is
recoverable, so the test now checks that instead.
Comment thread tests/testthat/test-estimate_dist.R Outdated
seabbs-bot and others added 4 commits April 2, 2026 16:14
Co-Authored-By: Sam Abbott <contact@samabbott.co.uk>
Co-Authored-By: Sam Abbott <contact@samabbott.co.uk>
Co-Authored-By: Sam Abbott <contact@samabbott.co.uk>
Use primarycensored::pcd_stan_dist_id for distribution ID lookup
instead of hard-coded switch. Add default priors for normal and
exp. Suppress noisy Stan warnings in tests.

Co-Authored-By: Sam Abbott <contact@samabbott.co.uk>
seabbs
seabbs previously approved these changes Apr 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Main branch estimate_dist benchmark failed (likely due to interface changes).

@sbfnk sbfnk added this pull request to the merge queue Apr 14, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
tests/testthat/test-estimate_dist.R (1)

264-274: Add an error pattern for consistency.

This test lacks an error message pattern, unlike the other validation tests. Adding a pattern ensures the test catches the correct error rather than any error.

♻️ Proposed fix
   expect_error(
-    estimate_dist(linelist, dist = "weibull")
+    estimate_dist(linelist, dist = "weibull"),
+    "Unsupported distribution"
   )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/testthat/test-estimate_dist.R` around lines 264 - 274, The test calls
estimate_dist(linelist, dist = "weibull") but uses expect_error without a
pattern; update the assertion to include a regexp that matches the specific
error message thrown by estimate_dist for unsupported distributions (e.g. match
the phrase used in estimate_dist like "unsupported distribution" or the exact
error text it emits) so the test asserts the correct error is raised rather than
any error.
inst/dev/benchmark-estimate-dist.R (1)

21-23: Consider making the benchmark fully reproducible.

The seed list at line 23 uses sample() without a prior set.seed(), so re-running the script produces different seeds each time. This may be intentional for stochastic benchmarking, but if reproducibility across runs is desired, move line 26's set.seed(12345) before line 23.

♻️ Proposed fix for full reproducibility
 ## Configuration
+set.seed(12345)
 n_iter <- 5
 seeds <- sample(.Machine$integer.max, n_iter)
 
 ## Simulate censored delay data
-set.seed(12345)
 n_obs <- 400
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@inst/dev/benchmark-estimate-dist.R` around lines 21 - 23, The script
generates stochastic seeds with seeds <- sample(.Machine$integer.max, n_iter)
but does not set a RNG seed first; to make the benchmark fully reproducible,
call set.seed(12345) (or another chosen constant) before computing seeds (i.e.,
move the existing set.seed(12345) so it runs prior to the seeds <- sample(...)
line) so n_iter and seeds are deterministically generated across runs.
inst/stan/estimate_dist.stan (1)

29-30: Update the dist_id comment to reflect all supported distributions.

The comment states "1=lognormal, 2=gamma" but the R code also supports normal and exponential distributions via primarycensored::pcd_stan_dist_id(). Consider updating the comment to match the actual supported set or simply reference the primarycensored documentation.

📝 Proposed comment update
-  // Distribution ID: 1=lognormal, 2=gamma
+  // Distribution ID: see primarycensored::pcd_stan_dist_id()
+  // Supported: lognormal, gamma, normal, exp
   int<lower=1> dist_id;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@inst/stan/estimate_dist.stan` around lines 29 - 30, The comment for the
dist_id variable declaration in the Stan file does not document all supported
distributions. Update the comment above the int<lower=1> dist_id parameter to
include all four supported distribution types (lognormal, gamma, normal, and
exponential) with their corresponding ID values, or alternatively reference the
primarycensored::pcd_stan_dist_id() documentation to keep the comment concise
and maintainable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/render-estimate-dist.yaml:
- Around line 10-12: Concurrency group currently uses github.head_ref which is
empty for non-pull_request events; update the concurrency.group expression to
fallback to github.ref when github.head_ref is empty so non-PR triggers have
distinct groups (use the GitHub Actions expression fallback pattern with
github.head_ref || github.ref), keeping cancel-in-progress behavior unchanged.

In `@R/estimate_dist.R`:
- Around line 269-280: The switch handling for init_params in estimate_dist.R
only sets "lognormal" and "gamma", leaving init_params NULL for "normal" and
"exp" and causing pmax/pmin to fail; update the switch(dist, ...) to include MoM
initialisations: for "normal" set init_params to c(mean = wmean, sd =
sqrt(wvar)), and for "exp" set init_params to the exponential parameter using
MoM (rate = 1 / wmean or the parameterization your model uses) so init_params
matches the parameter ordering expected by stan_data; keep the existing clamping
to stan_data$params_lower and stan_data$params_upper and return init_fn <-
function() list(params = init_params) as before.

---

Nitpick comments:
In `@inst/dev/benchmark-estimate-dist.R`:
- Around line 21-23: The script generates stochastic seeds with seeds <-
sample(.Machine$integer.max, n_iter) but does not set a RNG seed first; to make
the benchmark fully reproducible, call set.seed(12345) (or another chosen
constant) before computing seeds (i.e., move the existing set.seed(12345) so it
runs prior to the seeds <- sample(...) line) so n_iter and seeds are
deterministically generated across runs.

In `@inst/stan/estimate_dist.stan`:
- Around line 29-30: The comment for the dist_id variable declaration in the
Stan file does not document all supported distributions. Update the comment
above the int<lower=1> dist_id parameter to include all four supported
distribution types (lognormal, gamma, normal, and exponential) with their
corresponding ID values, or alternatively reference the
primarycensored::pcd_stan_dist_id() documentation to keep the comment concise
and maintainable.

In `@tests/testthat/test-estimate_dist.R`:
- Around line 264-274: The test calls estimate_dist(linelist, dist = "weibull")
but uses expect_error without a pattern; update the assertion to include a
regexp that matches the specific error message thrown by estimate_dist for
unsupported distributions (e.g. match the phrase used in estimate_dist like
"unsupported distribution" or the exact error text it emits) so the test asserts
the correct error is raised rather than any error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 00c3eff2-a91f-40cc-9765-00cc3f09c910

📥 Commits

Reviewing files that changed from the base of the PR and between 99cf54d and 80a53a3.

⛔ Files ignored due to path filters (4)
  • vignettes/estimate-dist-plot-delays-1.png is excluded by !**/*.png
  • vignettes/estimate-dist-prior-predictive-1.png is excluded by !**/*.png
  • vignettes/estimate-dist-recovery-density-1.png is excluded by !**/*.png
  • vignettes/estimate-dist-recovery-params-1.png is excluded by !**/*.png
📒 Files selected for processing (25)
  • .github/workflows/check-primarycensored.yaml
  • .github/workflows/render-estimate-dist.yaml
  • .github/workflows/stan-model-benchmark.yaml
  • NAMESPACE
  • NEWS.md
  • R/dist_spec.R
  • R/estimate_delay.R
  • R/estimate_dist.R
  • R/get.R
  • R/summarise.R
  • _pkgdown.yml
  • inst/dev/benchmark-estimate-dist.R
  • inst/dev/vendor-primarycensored.R
  • inst/stan/estimate_dist.stan
  • man/dot-get_dist_id.Rd
  • man/dot-get_param_names.Rd
  • man/dot-prepare_linelist_data.Rd
  • man/estimate_delay.Rd
  • man/estimate_dist.Rd
  • man/get_parameters.Rd
  • man/summary.estimate_dist.Rd
  • tests/testthat/test-estimate_dist.R
  • vignettes/estimate-dist.Rmd
  • vignettes/estimate-dist.Rmd.orig
  • vignettes/library.bib
✅ Files skipped from review due to trivial changes (10)
  • man/dot-get_dist_id.Rd
  • man/get_parameters.Rd
  • man/dot-get_param_names.Rd
  • vignettes/library.bib
  • man/summary.estimate_dist.Rd
  • man/dot-prepare_linelist_data.Rd
  • man/estimate_delay.Rd
  • vignettes/estimate-dist.Rmd.orig
  • vignettes/estimate-dist.Rmd
  • man/estimate_dist.Rd
🚧 Files skipped from review as they are similar to previous changes (3)
  • R/estimate_delay.R
  • NAMESPACE
  • _pkgdown.yml

Comment thread .github/workflows/render-estimate-dist.yaml
Comment thread R/estimate_dist.R Outdated
@sbfnk sbfnk removed this pull request from the merge queue due to a manual request Apr 14, 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 80a53a3 is merged into main:

  • ✔️default: 23.7s -> 23.7s [-5.31%, +4.86%]
  • ✔️no_delays: 23.7s -> 23.6s [-8.31%, +6.91%]
  • ✔️random_walk: 9.25s -> 9.52s [-3.75%, +9.59%]
  • ✔️stationary: 14.9s -> 12.4s [-58.12%, +24.36%]
  • ✔️uncertain: 36.2s -> 46.2s [-46.5%, +102%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Co-authored-by: Sam Abbott <contact@samabbott.co.uk>
Co-authored-by: epiforecasts-workflows[bot] <epiforecasts-workflows[bot]@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

estimate_infections

Table: Benchmarking results (mean time in seconds). |operation | branch| main| % change| range| trend| |:--------------------|-------:|-------:|--------:|----------:|---------:| |infections | 4.3| 4.4| -1| (-29, 38)| no change| |reports | 4.2| 4.3| -1| (-27, 36)| no change| |delays | 11| 3.5| 207| (122, 353)| slowdown| |report lp | 2.9| 2.9| 0| (-27, 39)| no change| |R0 | 1.3| 1.3| 0| (-28, 36)| no change| |update gp | 1| 1| 0| (-26, 41)| no change| |gt | 0.46| 0.46| 1| (-25, 37)| no change| |day of the week | 0.43| 0.43| 2| (-26, 41)| no change| |truncation | 0.29| 0.29| 1| (-28, 38)| no change| |param lp | 0.24| 0.25| -2| (-28, 37)| no change| |truncate | 0.21| 0.21| 2| (-23, 41)| no change| |delays lp | 0.1| 0.11| -2| (-26, 39)| no change| |rt lp | 0.098| 0.099| 0| (-29, 38)| no change| |gp lp | 0.094| 0.095| 0| (-31, 37)| no change| |generated quantities | 0.0082| 0.0078| 5| (-4, 19)| no change| |assign max | 5.4e-07| 5.8e-07| -6| (-43, 66)| no change|

Main branch estimate_dist benchmark failed (likely due to interface changes).

@github-actions
Copy link
Copy Markdown
Contributor

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

  • ✔️default: 22.6s -> 22.8s [-6.25%, +7.27%]
  • ✔️no_delays: 24.2s -> 25s [-15.59%, +22.42%]
  • ✔️random_walk: 14.5s -> 9.97s [-79.47%, +16.97%]
  • ✔️stationary: 12.4s -> 15.1s [-19.26%, +64.48%]
  • ✔️uncertain: 48.4s -> 1.2m [-18.47%, +115.5%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Co-authored-by: github-merge-queue <118344674+github-merge-queue@users.noreply.github.com>
Co-authored-by: Sam Abbott <contact@samabbott.co.uk>
Co-authored-by: sbfnk <sebastian.funk@lshtm.ac.uk>
Co-authored-by: epiforecasts-workflows[bot] <243357408+epiforecasts-workflows[bot]@users.noreply.github.com>
Co-authored-by: Sebastian Funk - robot edition <242615673+sbfnk-bot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

estimate_infections

Table: Benchmarking results (mean time in seconds). |operation | branch| main| % change| range| trend| |:--------------------|------:|-------:|--------:|----------:|---------:| |infections | 4.1| 4| 7| (-38, 94)| no change| |reports | 4| 3.9| 6| (-38, 87)| no change| |delays | 10| 3.2| 223| (89, 479)| slowdown| |report lp | 3| 2.8| 8| (-37, 93)| no change| |R0 | 1.2| 1.2| 5| (-38, 88)| no change| |update gp | 1| 0.97| 8| (-36, 87)| no change| |day of the week | 0.45| 0.44| 5| (-38, 89)| no change| |gt | 0.46| 0.43| 11| (-37, 106)| no change| |truncation | 0.29| 0.28| 8| (-38, 95)| no change| |param lp | 0.27| 0.25| 12| (-36, 101)| no change| |truncate | 0.21| 0.2| 8| (-39, 88)| no change| |delays lp | 0.13| 0.12| 16| (-32, 115)| no change| |rt lp | 0.1| 0.097| 11| (-39, 90)| no change| |gp lp | 0.088| 0.087| 4| (-42, 85)| no change| |generated quantities | 0.0073| 0.0072| 2| (-7, 9)| no change| |assign max | 6e-07| 6.2e-07| -2| (-45, 45)| no change|

Main branch estimate_dist benchmark failed (likely due to interface changes).

@github-actions
Copy link
Copy Markdown
Contributor

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

  • ✔️default: 23.3s -> 23.8s [-9.28%, +13.64%]
  • ✔️no_delays: 26.1s -> 25.8s [-7.51%, +5.47%]
  • ✔️random_walk: 13.2s -> 24.2s [-153.42%, +321.08%]
  • ✔️stationary: 12.5s -> 12.8s [-19.96%, +24.79%]
  • ❗🐌uncertain: 36.6s -> 1.19m [+81.39%, +108.9%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Co-authored-by: epiforecasts-workflows[bot] <epiforecasts-workflows[bot]@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

estimate_infections

Table: Benchmarking results (mean time in seconds). |operation | branch| main| % change| range| trend| |:--------------------|-------:|-------:|--------:|----------:|---------:| |infections | 4.4| 4.1| 8| (-21, 41)| no change| |reports | 4.3| 4.1| 6| (-21, 36)| no change| |delays | 11| 3.4| 230| (143, 322)| slowdown| |report lp | 3.3| 3| 11| (-19, 58)| no change| |R0 | 1.4| 1.3| 8| (-18, 40)| no change| |update gp | 1.2| 1| 14| (-14, 51)| no change| |gt | 0.51| 0.47| 12| (-16, 47)| no change| |day of the week | 0.47| 0.43| 11| (-17, 61)| no change| |truncation | 0.31| 0.29| 8| (-20, 39)| no change| |param lp | 0.29| 0.27| 11| (-17, 43)| no change| |truncate | 0.24| 0.21| 18| (-8, 54)| no change| |delays lp | 0.12| 0.11| 8| (-19, 44)| no change| |rt lp | 0.12| 0.11| 13| (-20, 67)| no change| |gp lp | 0.11| 0.1| 5| (-26, 39)| no change| |generated quantities | 0.0076| 0.007| 9| (-8, 23)| no change| |assign max | 5.2e-07| 4.9e-07| 10| (-46, 103)| no change|

Main branch estimate_dist benchmark failed (likely due to interface changes).

@seabbs-bot
Copy link
Copy Markdown
Collaborator

Update since last review pass

Bringing reviewers up to speed on what changed when #1356 merged in (plus subsequent lint cleanup on this branch).

Distribution constructors & estimate_dist()

  • Exported Exp(), Weibull(), and Normal() constructors.
  • estimate_dist() now accepts lognormal / gamma / normal / exp / weibull with default priors and explicit MoM init for each (no more silent NULL fallthrough on normal/exp/weibull).
  • init_params wrapped in as.array() so single-parameter (exp) inits become array[1] rather than scalar.
  • Init hardened: wvar clamped to sqrt(.Machine$double.eps) for constant delays; non-finite candidates replaced with bounded safe defaults inside Stan-declared bounds. wmean is intentionally not clamped so normal retains negative-mean support.
  • dist argument validated before priors so an unsupported distribution surfaces "Unsupported distribution" rather than a priors NULL assertion.

R/dist_spec.R

  • Added @importFrom stats pweibull (fixes the Distributions Rd Exp(mean = 4) example failing under as-cran).
  • Exp's lower_bounds map gained mean = 0 so Exp(mean = …) validates.
  • Dropped the unsupported mean, sd args from Weibull() (the (mean, sd) → (shape, scale) inverse wasn't implemented).
  • convert_to_natural if/else-if chain refactored to a switch(), plus assorted indentation fixes.

Verbose gating

  • All four cli::cli_inform calls in estimate_dist() (pdate_upr/sdate_upr/obs_date defaults plus the obs_time_threshold Inf-assignment notice) now run under if (verbose).

Vignette / docs

  • vignettes/estimate-dist.Rmd.orig: meanlog guidance re-phrased in terms of the median, with the explicit mean correction exp(meanlog + sdlog^2 / 2).
  • vignettes/library.bib: bioRxivmedRxiv for the matching DOI.
  • vignettes/estimate-dist.Rmd rendered build no longer leaks "built under R version" warnings (setup chunk now warning = FALSE, message = FALSE).
  • man/dot-extract_to_dist_spec.Rd and man/dot-prepare_linelist_data.Rd regenerated with full @param/@return blocks; man/estimate_dist.Rd lists weibull in usage and limitations.
  • _pkgdown.yml: registered the delays vignette in the articles index (was missing → pkgdown red).

Tests

  • Explicit seed = 12345 on every stan_opts() in tests/testthat/test-estimate_dist.R for deterministic MCMC runs.
  • Recovery tests added for normal, exp, weibull.
  • correctly handles constant delays without non-finite init gated on skip_integration().
  • Snapshots refreshed for simulate-infections and simulate-secondary (the merge had reverted the prior refresh).

Workflows / dev scripts

  • .github/workflows/check-primarycensored.yaml: peter-evans/create-pull-request now mints an App token via tibdex/github-app-token@v2 (secrets.APP_ID / APP_PRIVATE_KEY) so the auto-PR triggers downstream CI under the bot identity, matching update-r-multiverse.yaml.
  • .github/workflows/stan-model-benchmark.yaml: comment creation gated on the existence of real benchmark output files.
  • .github/workflows/render-estimate-dist.yaml: concurrency key now ${{ github.head_ref || github.ref }}.
  • inst/dev/benchmark-estimate-dist.R: set.seed() now runs before the sample() it seeds.
  • inst/dev/vendor-primarycensored.R: vendor call wrapped in invisible().

NEWS

  • Entries added for estimate_dist(), the new Exp/Weibull/Normal constructors, and the estimate_delay() deprecation.

Lint

  • Fifteen pre-existing indentation_linter findings in files now in the PR diff (R/checks.R, R/create.R, R/dist_spec.R, R/extract.R, R/fit.R, R/plot.R, R/preprocessing.R, R/simulate_infections.R, R/simulate_secondary.R, R/summarise.R) corrected so lint-changed-files is green.

CI as of 5c76881c — full R-CMD-check matrix (5/5), R-CMD-as-cran-check, test-coverage, pkgdown, codecov all SUCCESS on the previous tip; lint-changed-files queued for this commit.

This is an automated comment summarising bot-merged work; please ping @seabbs for any questions.

@github-actions
Copy link
Copy Markdown
Contributor

estimate_infections

Table: Benchmarking results (mean time in seconds). |operation | branch| main| % change| range| trend| |:--------------------|-------:|-------:|--------:|---------:|---------:| |infections | 4.1| 4.3| -2| (-53, 34)| no change| |reports | 4| 4.2| -1| (-52, 36)| no change| |delays | 10| 3.5| 205| (49, 321)| slowdown| |report lp | 3.1| 3.1| 3| (-50, 42)| no change| |R0 | 1.3| 1.4| -1| (-50, 40)| no change| |update gp | 1.1| 1.1| 3| (-50, 41)| no change| |gt | 0.47| 0.48| 2| (-50, 42)| no change| |day of the week | 0.44| 0.45| 1| (-50, 41)| no change| |truncation | 0.29| 0.3| -1| (-52, 37)| no change| |param lp | 0.26| 0.28| -2| (-52, 35)| no change| |truncate | 0.21| 0.22| 0| (-53, 37)| no change| |delays lp | 0.12| 0.13| -1| (-53, 40)| no change| |rt lp | 0.12| 0.12| 4| (-52, 50)| no change| |gp lp | 0.099| 0.11| -2| (-51, 55)| no change| |generated quantities | 0.007| 0.0067| 5| (0, 10)| no change| |assign max | 4.7e-07| 4.6e-07| 5| (-44, 78)| no change|

Main branch estimate_dist benchmark failed (likely due to interface changes).

Copy link
Copy Markdown
Contributor

@seabbs seabbs left a comment

Choose a reason for hiding this comment

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

I think this is ready for review now @sbfnk. Note that we likely need a new issue for adding uncertain pmfs to this vignette and also for allowing convolving delays to retain uncertainty.

@github-actions
Copy link
Copy Markdown
Contributor

Main branch estimate_dist benchmark failed (likely due to interface changes).

@github-actions
Copy link
Copy Markdown
Contributor

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

  • ✔️default: 23.5s -> 23.6s [-5.94%, +6.44%]
  • ✔️no_delays: 26.4s -> 26.2s [-10.91%, +9.96%]
  • ✔️random_walk: 27.2s -> 11.3s [-153.04%, +36.15%]
  • ✔️stationary: 13.4s -> 13.1s [-12.39%, +7.81%]
  • ❗🐌uncertain: 37.4s -> 1.13m [+63.4%, +98.89%]
    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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

estimate_delays -> estimate_dist

4 participants