Skip to content

Fix Simpson's 1/3 within-cycle correction weights (v0.3.0) - #3

Merged
feralaes merged 9 commits into
mainfrom
fix/gen-wcc-simpson
Nov 10, 2026
Merged

feralaes merged 9 commits into
mainfrom
fix/gen-wcc-simpson

Conversation

@feralaes

Copy link
Copy Markdown
Contributor

Summary

gen_wcc(method = "Simpson1/3") assigned Simpson's 4/3 and 2/3 weights by position in the 1-based R vector instead of by time t = 0, …, n. It returned 1/3, 2/3, 4/3, …, 1/3 instead of 1/3, 4/3, 2/3, …, 1/3, so the weights summed to n − 2/3 instead of n. This PR fixes the bug, makes the PSA use the same corrected function, and adds tests, CI and reproducibility infrastructure for release v0.3.0.

Closes #2. Also reported independently by Lauren N. Steimle (Georgia Tech) by email.

Changes

Bug fixes

  • Index Simpson weights by time. For an odd number of cycles (the tutorial uses 75), use Simpson's 3/8 rule over the last three cycles, so polynomials up to degree three are still integrated exactly.
  • Validate n_cycles.
  • The PSA wrapper now uses the local, corrected gen_wcc() instead of darthtools::gen_wcc(), which has the same bug in darthtools ≤ 0.4.0.
  • Fix swapped cost and QALY discount rates in calculate_ce_out(). No effect while both rates are 3%.
  • Scale Strategy A state costs by cycle_length. No effect with annual cycles.

Cleanup: remove a stray dead copy of rate_to_prob(), and replace deprecated ggplot2 arguments.

Infrastructure: testthat tests (11 tests, 112 expectations), a GitHub Actions workflow (tests plus the full analysis on Ubuntu and macOS), renv.lock, DESCRIPTION (version 0.3.0) and CITATION.cff.

Docs: add NEWS.md and manuscript/README.md (erratum note; the manuscript sources are unchanged), and revise the README, including correcting the Zenodo DOIs.

Impact on base-case results

Strategy QALYs v0.2.1 → v0.3.0 Costs v0.2.1 → v0.3.0 ICER v0.2.1 → v0.3.0
Standard of care 20.71 → 21.03 $151,580 → $152,282 —
Strategy B 22.18 → 22.50 $259,100 → $260,222 $72,988 → $73,279
Strategy AB 23.14 → 23.46 $378,875 → $380,378 $125,764 → $125,302
Strategy A 21.50 → 21.83 $284,805 → $285,889 Dominated

The efficient frontier and the dominance of Strategy A are unchanged.

Verification

  • testthat::test_dir("tests/testthat"): 112 expectations, 0 failures.
  • source("analysis/cSTM_time_indep.R") runs end to end under renv, and the PSA wrapper reproduces the script's base case exactly.
  • CI on this PR.

gen_wcc(method = "Simpson1/3") assigned the 4/3 and 2/3 weights by
position in the 1-based R vector instead of by time t = 0, ..., n,
returning 1/3, 2/3, 4/3, ..., 1/3 instead of 1/3, 4/3, 2/3, ..., 1/3.
The weights summed to n - 2/3 instead of n.

- Index Simpson weights by time.
- For an odd number of cycles (the tutorial uses 75), apply Simpson's
  3/8 rule over the last three cycles so cubics are still integrated
  exactly and the weights sum to n.
- Validate n_cycles (single positive integer; >= 2 for Simpson).
- Use the corrected local gen_wcc() in the PSA wrapper instead of
  darthtools::gen_wcc(), which has the same bug in darthtools <= 0.4.0.
- Fix swapped cost/QALY discount rates in calculate_ce_out() (no effect
  with equal 3% rates).
- Scale Strategy A state costs by cycle_length in the analysis script
  (no effect with annual cycles).

Base-case QALYs increase by ~0.32 per strategy; ICERs change by ~0.4%;
the efficient frontier and dominance results are unchanged.

Reported by Lauren N. Steimle and @ambtnhlr.
Closes #2
- Remove a stray, unnamed copy of rate_to_prob() from R/Functions.R.
- Use linewidth instead of size in geom_line() (ggplot2 >= 3.4.0).
- Use after_stat(density) instead of ..density.. in the PSA histogram.
- Add missing final newline to R/Functions.R.
- test-gen_wcc.R: exact Simpson weights for odd and even n, exact
  integration of polynomials of degree 0-3, half-cycle and none methods,
  input validation, and the examples from the bug reports.
- test-base-case.R: regression test of base-case costs, QALYs, ICERs and
  dominance, and consistency between the analysis script and the PSA
  wrapper.
- DESCRIPTION: project version (0.3.0) and dependencies.
- renv.lock: pinned package versions (R 4.5.3); restore with renv::restore().
- CITATION.cff: software and preferred article citation with all authors.
- GitHub Actions: run the tests and the full analysis on Ubuntu and macOS.
- NEWS.md: changelog with before/after results of the WCC fix and
  acknowledgements; entries for previous releases.
- README: correction notice, quick start with renv, repository structure,
  dependency notes, contributing guidelines, CI and license badges; fix
  typos and the Zenodo DOIs (the cited DOI was the v0.1.1 version DOI).
- manuscript/README.md: document the erratum in the archival manuscript
  sources.
@netlify

netlify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for testcohort ready!

Name Link
🔨 Latest commit c68c67a
🔍 Latest deploy log https://app.netlify.com/projects/testcohort/deploys/6af304522cddf2e6004d775b
😎 Deploy Preview https://deploy-preview-3--testcohort.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

…ource

CRAN only provides macOS binaries for the latest package versions; older
versions pinned in renv.lock (e.g., data.table 1.18.2.1) are compiled from
source and need libintl from gettext.
Credit both reporters in the gen_wcc() documentation, NEWS.md, a new
README Acknowledgements section, and the manuscript erratum note.
The gettext install ran 'sudo Rscript' in the project root, so .Rprofile
activated renv as root and left a root-owned lock that made renv::restore()
hang until the 6-hour limit. Run it with --vanilla from the runner's temp
directory, cap jobs at 60 minutes, and cancel superseded runs.
@feralaes
feralaes merged commit b9c9196 into main Nov 10, 2026
6 checks passed
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.

Bug report: gen_wcc() Simpson's 1/3 weights

1 participant