Repository navigation
v0.3.0: fix gen_wcc() Simpson weights and state-residence PSA; add tests, CI and renv - #1
Merged
Merged
Conversation
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 (the tutorial uses 75), 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). - Same implementation as cohort-modeling-tutorial-intro v0.3.0 and darthtools v0.4.1. Also: remove a stray anonymous function after gen_wcc(), and replace deprecated ggplot2 arguments (geom_line(size =) -> linewidth, ..density.. -> after_stat(density)). Reported independently by Lauren N. Steimle and by GitHub user ambtnhlr (DARTH-git/cohort-modeling-tutorial-intro#2).
- Simulation-time model: calculate_ce_out() discounted costs with d_e and QALYs with d_c. No numerical effect in the tutorial (both are 3%). - State-residence model: calculate_ce_out() used v_wcc, v_dwc and v_dwe from the global environment instead of computing them, so the PSA only worked after running the deterministic part of the analysis script. They are now computed inside the function, using the corrected gen_wcc(). - Both models: decision_model(), calculate_ce_out() and generate_epi_measures_SoC() read the strategy and state names from the global environment. They now define them themselves.
- gen_wcc(): exact weights and exact integration of polynomials up to degree three (same tests as the intro tutorial). - Base-case costs, QALYs, ICERs and dominance of both models. - The PSA wrappers apply the corrected WCC, do not depend on global objects, and do not swap discount rates. - The PSA distributions are centred on the base-case values (catches the c_trtB table erratum).
- check_sum_of_transition_array() compared each cycle's sum of transition probabilities with n_states using exact equality, so rounding error (~1e-14) in a valid array stopped the PSA at parameter set 220. Use all.equal(), as in darthtools. - analysis/cSTM_time_dep_state_residence.R combined the PSA figures with patchwork without loading it. - Add regression tests for both.
- DESCRIPTION records the project version (0.3.0) and dependencies. - CITATION.cff gives citation metadata for the code (Zenodo concept DOI 10.5281/zenodo.5338818) and the article. - renv.lock pins package versions, including MethylCapSig 1.0.1 from the CRAN archive. - CI runs the tests and both analysis scripts on Ubuntu and macOS.
- NEWS.md with a before/after table of base-case results for both models. - README: quick start with renv, repository structure, corrections, contributing, acknowledgements. - manuscript/README.md documents the WCC and c_trtB parameter-table errata; the manuscript files stay archival.
Whether three given probabilities sum exactly to 3 depends on floating-point accumulation (it did on Ubuntu x86_64 but not on macOS arm64). Add an explicit 1e-13 error instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the Simpson's 1/3 within-cycle correction (WCC) bug that was reported in the introductory tutorial (DARTH-git/cohort-modeling-tutorial-intro#2) and shared by this repository. The PR also fixes several bugs found along the way, and adds tests, CI, renv and citation metadata, matching cohort-modeling-tutorial-intro v0.3.0.
Results change slightly. Conclusions don't.
QALYs rise by about 0.32 per strategy. The efficient frontier (SoC, B, AB) and the dominance of Strategy A are unchanged. The full before/after table is in NEWS.md. The old code reproduced the published values exactly.
Bug fixes
gen_wcc()now assigns weights by time t = 0, …, n instead of by 1-based vector position. For odd n (the tutorial uses 75), it uses Simpson's 3/8 rule over the last three cycles. This is the same implementation as the intro tutorial and darthtools v0.4.1.main. It stopped at parameter set 220, becausecheck_sum_of_transition_array()used exact==on floating-point sums. It now usesall.equal(), as darthtools does. The script also used patchwork without loading it. Both analysis scripts now run end to end.calculate_ce_out()swapped the cost and QALY discount rates. The analysis scripts were fixed in 2024; the PSA function wasn't. This has no effect at 3%/3%.calculate_ce_out()readv_wcc,v_dwcandv_dwefrom the global environment, and both models read the strategy and state names from there. The functions now define them.Infrastructure and docs
gen_wcc(), base-case results of both models, PSA wrapper consistency, PSA input means and transition-array check tolerance.renv.lock, which pins MethylCapSig 1.0.1 from the CRAN archive. It has been removed from CRAN.DESCRIPTIONandCITATION.cff.manuscript/README.mddocuments two errata: the WCC weights, and Table 2 listingc_trtBas $12,000 instead of $13,000 (reported in Parameter table prints c_trtB = $12,000; the analysis code and the published results use $13,000 cohort-modeling-tutorial-intro#1). The manuscript files themselves stay archival.Checks
testthat::test_dir("tests/testthat"): all pass, locally and with renv active.