Repository navigation
Fully incremental calculate_icers() with NMB and an incremental plot, plus calculate_cers_ref() for comparisons with a reference strategy (#209, #200) - #227
Conversation
calculate_icers() gains ref_str, wtp, nhb, and currency (added after the
existing arguments, so positional calls keep working). The frontier
(Status, Inc_Cost, Inc_Effect, ICER) is computed exactly as before and is
never changed; the new columns are added afterwards by
add_reference_and_nmb(), and only for the arguments that are given, so
with the defaults the object is identical to before.
- ref_str: Inc_Cost_ref, Inc_Effect_ref, ICER_ref (numeric, NA where a
ratio is not meaningful), and Status_ref ('Reference', 'Dominant',
'Dominated', 'More costly, more effective', 'Less costly, less
effective', or 'Equivalent' for the same cost and effect) (#209).
- wtp: NMB, plus iNMB_ref with a reference (#200); nhb = TRUE also adds
NHB and iNHB_ref.
- currency: stored on the object and used by print.icers().
- print.icers() gains ref = c('sequential', 'reference', 'both'); the
default prints the same table as before. Headers name the reference
('Incremental Costs vs Standard of care ($)').
- Validation helpers check_ref_str() and check_wtp_nhb() with clear
errors; a new example in ?calculate_icers.
Tests (test_icers_reference.R) check hand-calculated values for every
Status_ref category, a dominated and a most-expensive reference,
hund_strat, NMB/NHB, one and two strategies, names with spaces, the
errors, and the print views. The default printed tables are identical to
main's print.icers().
Part of #209. Closes #200
…lines - plot.icers() gains ref_str, wtp, ref_axis, and ref_caption (after the existing arguments). ref_str shifts the plot so the reference strategy is at the origin (the frontier and statuses are unchanged); wtp draws a dotted line with slope wtp through the reference, or without ref_str through the least costly frontier strategy. The currency defaults to the one stored by calculate_icers() (#209, #202). - plot.psa() gains wtp, which draws the same line on its incremental plane (requires ref_str) (#202). - plot.psa(ref_str = ) with two strategies: keep a data frame when one comparator is left (drop = FALSE); it failed with "'dims' cannot be of length 0". ref_str is now checked with check_ref_str(). - Captions name the reference and the WTP threshold; this also removes a double space in plot.psa()'s 'Reference Strategy: X' caption. - Tests (test_reference_plots.R) check the plotted coordinates, axis labels, captions, WTP line slope and intercept, currency, the two-strategy case, and the errors. Default plots are unchanged. Part of #209
…_icers_psa() - summary.psa() gains ref_str and wtp (after calc_sds). With ref_str it adds meanIncCost, meanIncEffect, and the share of PSA samples in each quadrant of the incremental CE plane (propNE, propSE, propSW, propNW; NA for the reference). With wtp it adds meanNMB, and with ref_str also meanIncNMB and propCostEffective (share of samples with a higher NMB than the reference) (#209, #202). - calculate_icers_psa() gains ref_str, wtp, and nhb, passed to calculate_icers(). With uncertainty = TRUE and ref_str, it adds 95% intervals of the sample-by-sample differences from the reference (Lower_95_/Upper_95_ for Inc_Cost_ref, Inc_Effect_ref, iNMB_ref). The icers class and attributes are now kept through the uncertainty joins. - print.icers(): every *_ref column belongs to the reference view. - Docs: escape % in roxygen. An unescaped % starts an Rd comment, which had silently truncated ?calculate_icers_psa ('whether or not 95') and ?predict.metamodel. calculate_icers_psa() output for existing calls is identical to main's (objects, class, and printed tables, with and without uncertainty). Part of #209. Closes #202
…y-core # Conflicts: # NEWS.md
…fix entry first in Bug fixes so the open PRs merge in any order
- ceac(), calc_exp_loss(), calc_evpi(), calc_evppi(), calc_evsi(), and calculate_icers_psa() store psa$currency on their results. - Their plot() methods (and print.icers()) use it: currency defaults to NULL, resolved by resolve_currency() as the argument if given, else the result's currency, else '$'. Existing calls keep working. - plot.ceac() gains effect_units (the x-axis label hard-coded QALY). - EVPPI and EVSI computed from net health benefit are in health units: calc_evppi() and calc_evsi() store the outcome, and their plots are labeled 'EVPPI (QALY)' / 'EVSI (QALY)' instead of a currency. calc_evsi() defaults to outcome = 'nhb', so its default plot was mislabeled in dollars. - Tests (test_currency.R) with a euro PSA for every function, overrides, effect_units, and dollar defaults; two existing tests now build the expected object with the same currency. Outputs of all vignettes and examples change only by the new currency attribute; values, plot data, and labels are unchanged. Closes #203
Carry the currency of a psa object through to its analyses (#203)
mbkauf
left a comment
There was a problem hiding this comment.
icers.R
- Printing with reference strategy has the strategies in the same order as without a reference strategy. So, the example code in the roxygen has the reference strategy is "1", but it ends up being the 55th strategy printed in the table. It should reorder with the reference strategy at the top? Or at least with some other ordering with respect to the reference strategy.
- In calculate_icers() lines 117 to 124, there is a chunk of code for if only 1 strategy is provided. It returns a data frame, but should it just return an error that more than 1 strategy must be provided?
- Are lines 103, 369-370 necessary?
- General naming conventions as it relates to capitalization. Should everything be lower case unless it's for formatting purposes to display.
- Line 406, what is everything() doing? Is it necessary?
- Add comments to explain code in add_reference_and_nmb() and add_reference_intervals() functions. In general, more commenting with newly written code would be good.
- Do we want incremental net monetary and incremental net health benefit to have the lower case "i" in the name (e.g. iNMB and iNHB)?
psa.R
- Lines 219-222, why does having a WTP threshold require a reference strategy be supplied?
…ng, wtp without ref_str in plot.psa - print.icers(ref = "reference") lists the reference first and the other strategies by increasing cost; "sequential" and "both" keep the frontier order. - Rename iNMB_ref/iNHB_ref to Inc_NMB_ref/Inc_NHB_ref, matching Inc_Cost_ref, Inc_Effect_ref and summary.psa()'s meanIncNMB. Print headers say "Incremental NMB/NHB". - plot.psa(wtp = ) no longer requires ref_str: without one, the line goes through the mean of the least costly strategy, as plot.icers() already did. - Comment add_reference_and_nmb(), add_reference_intervals(), the global-variable declarations, and the everything() in calculate_icers_psa().
|
@mbkauf thanks for the careful review. Point by point; the changes are in 308850f. icers.R
psa.R
Tests: 343 passing, 0 lints, R CMD check |
…rtainty; drop context() for testthat 3e - plot.icers() now always reduces x to its seven plot columns as a plain data frame. dplyr::select() had dropped the stored currency attribute only when uncertainty bounds were present, so the two plots differed under testthat's edition-3 comparison. - Replace context() in the four test files added by this PR (deprecated in edition 3).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #227 +/- ##
==========================================
+ Coverage 93.14% 93.92% +0.77%
==========================================
Files 18 19 +1
Lines 1794 2073 +279
==========================================
+ Hits 1671 1947 +276
- Misses 123 126 +3
🚀 New features to boost your workflow:
|
…y-core # Conflicts: # NEWS.md
…scale (#201) The ellipses were computed on the data scale, so on log axes (added with scale_*_log10()) they lost their shape and any part below zero became NaN. plot.psa() now takes xtrans and ytrans, passes them to its own scales, and computes each ellipse from the transformed samples before mapping it back. Values a transformation cannot show (zero or negative on a log scale, common on the incremental plane) give an informative error. With the default identity transformations the plots are unchanged. The duplicated ellipse code of the two planes is now one helper, psa_ellipses().
…idth, axis limits, effect_units
- ceac() takes the psa object first, like calc_exp_loss() and calc_evpi(). The old positional
ceac(wtp, psa) still works with lifecycle::deprecate_soft(); named calls work in any order.
- plot.owsa() and plot.exp_loss() take linewidth; size and lsize still work, deprecated.
- plot.owsa() and plot.twsa() gain xlim/ylim, owsa_opt_strat() gains xlim.
- effect_units defaults to "QALYs" in every plot; per_unit() gives the singular for
willingness-to-pay labels, so default labels are unchanged ("$/QALY").
- lifecycle (>= 1.0.0) added to Imports.
- API style decision record in .github/CONTRIBUTING.md, including the open 2.0 questions.
plot.psa(): log axes with correctly shaped ellipses (xtrans, ytrans) (#201)
The minimum-dependency CI job could not install ggplot2@3.5.0 with lifecycle@1.0.0.
…o HEAD # Conflicts: # NEWS.md
Current dplyr needs lifecycle (>= 1.0.5) and ggplot2 3.5.0 needs lifecycle (> 1.0.1), so any lower pin makes the minimum-dependency environment unsolvable. dampack only uses deprecate_soft(), deprecated() and is_present(), which predate lifecycle 1.0.
Harmonize the API with soft deprecation: ceac(psa, wtp), linewidth, axis limits, effect_units (#214)
|
Hi @mbkauf and @krijkamp, Fernando asked me (Claude, working in his session) to send a short guide for reviewing this PR. It's the one most other work is waiting on: three more PRs are built on top of it. GitHub won't let Fernando approve his own PR, so it needs an approval from one of you. You don't need to read all the code. The most useful review is to run it and check that the results and wording make sense. 1. Try it (about 5 minutes)In R: remotes::install_github("DARTH-git/dampack", ref = "209-reference-strategy-core")
library(dampack)
data(cancer_psa_data)
psa <- make_psa_obj(cost = cancer_psa_data$cost,
effectiveness = cancer_psa_data$effectiveness,
parameters = cancer_psa_data$parameters,
strategies = cancer_psa_data$strategies)
icers <- calculate_icers_psa(psa, ref_str = "Radio", wtp = 100000)
print(icers) # the usual sequential table (unchanged)
print(icers, ref = "reference") # every strategy vs Radio, Radio listed first
plot(icers, ref_str = "Radio", wtp = 100000)
summary(psa, ref_str = "Radio", wtp = 100000) # mean differences and quadrant shares
plot(psa, ref_str = "Radio", wtp = 100000) # incremental CE plane with a WTP line2. What to look atMatt:
Eline: the methods, as agreed on #209:
Both:
3. How to leave your review on GitHub
A plain comment at the bottom of this page also works. Fernando or I will turn it into changes. |
# Conflicts: # NEWS.md
…r comparisons with a reference As agreed at the DARTH meeting of Nov 17, 2026: - Remove ref_str from calculate_icers(), print.icers(), plot.icers(), calculate_icers_psa() and summary.psa(). They keep wtp/nhb (NMB, NHB) and currency. - plot.icers(incremental = TRUE) puts the first non-dominated strategy at the origin. - New calculate_cers_ref() and calculate_cers_ref_psa(), with print() and plot() methods, compare every strategy with a reference strategy, citing the NICE, CDA-AMC and Zorginstituut Nederland guidelines. - basic_cea vignette section, README bullet, pkgdown reference group. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Keep calculate_icers() fully incremental; add calculate_cers_ref() for comparisons with a reference strategy (#209)
This PR delivers the reference-strategy work (#209), as redesigned at the DARTH meeting on Nov 17 and implemented in #261.
What changed from the original design
calculate_icers()stays fully incremental. Theref_stroptions this PR first added tocalculate_icers(),print.icers(),plot.icers(),calculate_icers_psa()andsummary.psa()have been removed.calculate_cers_ref().The rest of the description reflects the current branch.
This branch also contains these PRs, which were merged into it: #228 (plots), #229 (PSA summaries, since reworked), #242 (currency), #250 (log axes), #251 (API harmonization) and #261 (redesign).
What it adds
Fully incremental analysis (unchanged frontier)
calculate_icers()andcalculate_icers_psa():wtp, which adds each strategy's net monetary benefit (NMB), andnhb = TRUE, which also adds the net health benefit (NHB);calculate_icers()also gainscurrency.print.icers()uses the stored currency.plot.icers():incremental = TRUEputs the first non-dominated strategy (the least costly strategy on the frontier) at the origin. This was Eline's original request.wtpdraws a willingness-to-pay line through that strategy.Comparison with a reference strategy (new)
calculate_cers_ref(cost, effect, strategies, ref_str, wtp = NULL)compares every strategy with one reference. It gives:Inc_CostandInc_Effect;CER, the cost-effectiveness ratio versus the reference;Status: Reference / Dominant / Dominated / More costly, more effective / Less costly, less effective / Equivalent;wtp,NMBandInc_NMB.calculate_cers_ref_psa(psa, ref_str, wtp, uncertainty = TRUE)adds 95% intervals and the share of PSA samples in each quadrant, plus the share that is cost-effective versus the reference.print()andplot()methods. The plot is the "star" around the reference, with an optional WTP line.vignette("basic_cea")cite the NICE, CDA-AMC and Zorginstituut Nederland guidelines. All three require a fully incremental analysis; NICE allows pairwise comparisons "when relevant and justified".PSA plots
plot.psa()gainswtp(WTP line to CE plot #202), andxtrans/ytransfor log axes with correctly shaped ellipses (The confidence eclipse can not be added when the axes use the log-scale #201).plot.psa(ref_str = )now works with two strategies.Currency and API
psaobject carries through to its analyses (Plotting after calc_icer does not apply the currency as specified in make_psa_obj #203).ceac(psa, wtp),linewidth, axis limits, andeffect_units(Harmonize plot-method arguments andceac()argument order (soft deprecation) #214).Closes
ref_str) #209ceac()argument order (soft deprecation) #214Checks
R CMD check --as-cran: 0 errors, 0 warnings.The examples in #252 are updated to the new design once this branch has #261.