Skip to content

Fix gen_wcc() Simpson's 1/3 weights; add unit tests and R CMD check CI (v0.4.1) - #16

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

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

Conversation

@feralaes

Copy link
Copy Markdown
Contributor

Summary

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. 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 (even n) or n − 1/3 (odd n) instead of n. This PR fixes it and releases darthtools 0.4.1.

The bug was reported independently by Lauren N. Steimle (Georgia Institute of Technology) and by GitHub user ambtnhlr (DARTH-git/cohort-modeling-tutorial-intro#2). It was fixed in the intro tutorial in v0.3.0; this PR applies the same fix here.

Changes

  • Fix: Simpson weights are now indexed by time. For an odd number of cycles, the last three cycles use Simpson's 3/8 rule, so polynomials up to degree three are still integrated exactly and the weights sum to n.
  • Input validation: n_cycles must be a single positive integer (and ≥ 2 for Simpson's rule). Previously, n_cycles = 7.5 was silently truncated.
  • Tests: the package's first testthat (3rd edition) tests, which cover exact weight vectors, exact integration of t^k for k = 0–3, the reported examples, the other methods and input errors (106 expectations).
  • CI: a new R-CMD-check workflow on macOS, Windows and Ubuntu (R release) and Ubuntu (R oldrel-1).
  • Pre-existing check warnings fixed so CI can pass with warnings treated as errors: surv_prob() no longer calls require("MASS") (MASS is now in Imports), coef/vcov are imported from stats, and the surv_prob(B) and plot_trace_microsim(v_n_states) arguments are documented.
  • Version bump to 0.4.1, with a NEWS entry.

Impact for users

Results computed with gen_wcc(method = "Simpson1/3") will change slightly. In the intro tutorial's base case, QALYs rise about 0.32 per strategy and ICERs move about 0.4%, with no change in dominance or conclusions.

Checks

  • devtools::test(): 106 passing, 0 failing.
  • devtools::check() locally (macOS, R 4.5.3): 0 errors, 0 warnings, 1 note ("unable to verify current time", which comes from the local machine).

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.

- Weights are now assigned by time.
- For an odd number of cycles, apply the composite Simpson's 1/3 rule over
  the first n - 3 cycles and Simpson's 3/8 rule over the last three, so
  polynomials up to degree three are integrated exactly.
- Validate that n_cycles is a single positive integer (and >= 2 for Simpson).

Reported independently by Lauren N. Steimle and by GitHub user ambtnhlr
(DARTH-git/cohort-modeling-tutorial-intro#2).

Documentation regenerated with roxygen2 8.0.0.
Tests check the exact weight vectors, exact integration of polynomials up to degree three for even and odd n, the reported examples, the half-cycle and none methods, and input validation.
- surv_prob(): drop require("MASS"); MASS (already used via MASS::mvrnorm) is now in Imports.
- Import coef() and vcov() from stats.
- Document surv_prob(B) and plot_trace_microsim(v_n_states).
Checks on macOS, Windows and Ubuntu (R release) and Ubuntu (R oldrel-1) using r-lib/actions.
@feralaes
feralaes merged commit 03abf7b into main Nov 10, 2026
4 checks passed
@feralaes
feralaes deleted the fix/gen-wcc-simpson branch November 10, 2026 18:00
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.

1 participant