Skip to content

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

Closed

Description

@ambtnhlr

Hi DARTH team,

I just noticed what looks like an indexing issue in gen_wcc(method = "Simpson1/3"). I'm not sure whether it has been fixed somewhere already, so apologies if this is a duplicate.

The weights come out as 1/3, 2/3, 4/3, 2/3, …, 1/3 instead of 1/3, 4/3, 2/3, 4/3, …, 1/3, so they sum to n − 2/3 rather than n:

w <- gen_wcc(4, "Simpson1/3")
w                  # 1/3 2/3 4/3 2/3 1/3
sum(w)             # 3.33; integral of 1 over [0, 4] should be 4
sum(w * (0:4)^2)   # 17.33; should be 21.33

I think it's because v_cycles holds 1-based positions, so position 2 is t = 1, which should get 4/3. Indexing by time seems to fix it:

v_t   <- 0:n_cycles
v_wcc <- ifelse(v_t %% 2 == 1, 4/3, 2/3)
v_wcc[c(1, n_cycles + 1)] <- 1/3

The documentation ("odd and even entries with 4/3 and 2/3") matches the code, so it may be worth rewording too, e.g. "entries at odd times (t = 1, 3, …) get 4/3", since odd positions in a 1-based R vector are even times.

In the time-independent Sick-Sicker tutorial, this lowers QALYs by about 0.33 per strategy, though ICERs only move about 0.2%. (With 75 cycles the number of intervals is also odd, so Simpson's 1/3 rule doesn't strictly apply there.)

If this is incorrect, I apologize, kindly ignore. Have a great day, thanks for the great tutorial!

Activity

  1. feralaes commented on Nov 10, 2026

    @feralaes
    Contributor

    Thank you so much for this careful report, and you're right. gen_wcc()
    assigned Simpson's weights by 1-based vector position instead of by time, so
    the vector was 1/3, 2/3, 4/3, … instead of 1/3, 4/3, 2/3, …. Lauren Steimle
    independently reported the same issue by email, and we've credited you both
    in NEWS.md.

    This is fixed in v0.3.0 (#3, release notes):

    • Weights are now indexed by time t = 0, …, n.
    • Since the tutorial uses 75 (odd) cycles, as you pointed out, the last
      three cycles now use Simpson's 3/8 rule. Polynomials up to degree three are
      still integrated exactly, and the weights sum to n.
    • The PSA wrapper now uses the same corrected function instead of
      darthtools::gen_wcc(), which has the same bug. A darthtools fix is in
      progress.
    • We reworded the documentation in the way you suggested, and added unit
      tests, including your example.

    In the base case, QALYs increase by about 0.32 per strategy and ICERs change
    by about 0.4%. The frontier and dominance results don't change. The before/after
    table is in NEWS.md, and manuscript/README.md records the erratum for the
    published article's code.

    Thanks again for taking the time to dig into this!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions