Skip to content

plot.psa(): log axes with correctly shaped ellipses (xtrans, ytrans) (#201) - #250

Merged
feralaes merged 1 commit into
209-reference-strategy-corefrom
201-psa-ellipse-log
Nov 14, 2026
Merged

feralaes merged 1 commit into
209-reference-strategy-corefrom
201-psa-ellipse-log

Conversation

@feralaes

Copy link
Copy Markdown
Collaborator

Closes #201.

Base: this PR is built on #227 (209-reference-strategy-core), because it changes plot.psa(), which #227 also changes. When #227 merges, GitHub retargets this PR to main.

Problem

On skewed PSA results, a log scale for cost or QALYs reads better (#201). But plot.psa() had no axis-transformation argument. Users added + scale_y_log10(), which replaced the package's scale, and the ellipses were still computed on the original scale. On example_psa_obj that gives NaNs produced and log-10 transformation introduced infinite values. The ellipses extend below zero cost, so they break, and where they survive they are the wrong shape.

Change

  • plot.psa() gains xtrans and ytrans (default "identity"), passed to its own scales through add_common_aes(). Any ggplot2 transformation works, such as "log10", "sqrt", or a scales::transform_*().
  • Each ellipse is computed from the mean, SD and correlation of the transformed samples, then mapped back. On a log axis it's the usual confidence ellipse of the log values, so it keeps its shape and never crosses zero. The centre points stay at the arithmetic means, which are the expected values the CEA uses.
  • Values a transformation can't show give an informative error instead of silently dropped points. Example: ytrans = "log10"` cannot show every incremental cost value: some are outside its domain (zero or negative, for a log scale). Differences from the reference strategy are often negative.
  • The two copies of the ellipse code (CE plane and incremental plane) are now one internal helper, psa_ellipses().

Tests (test_psa.R)

  • With log10 axes: the build gives no warnings, both scales are log-10, every ellipse point is finite, and the Chemo ellipse equals ellipse::ellipse() computed on the log10 samples.
  • With the default axes, the ellipse equals the one computed on the raw samples. The behavior is unchanged.
  • Errors for the incremental plane on a log axis, and for a zero cost. A zero cost is fine when only x is logged.
  • The new tests fail 5 times without the fix.

Verification

  • devtools::test(): 485 passed, 0 failed. lintr: 0 lints.
  • Every vignette and Rd example output is identical to the base branch.
  • R CMD check --as-cran: only the development-version NOTE.
  • NEWS entry under New features.

…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().
@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.69%. Comparing base (2b6a447) to head (64c6584).

Additional details and impacted files
@@                       Coverage Diff                       @@
##           209-reference-strategy-core     #250      +/-   ##
===============================================================
+ Coverage                        93.65%   93.69%   +0.03%     
===============================================================
  Files                               18       18              
  Lines                             2002     2013      +11     
===============================================================
+ Hits                              1875     1886      +11     
  Misses                             127      127              
Files with missing lines Coverage Δ
R/psa.R 95.93% <100.00%> (+0.24%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@feralaes
feralaes merged commit 785f347 into 209-reference-strategy-core Nov 14, 2026
12 checks passed
@feralaes
feralaes deleted the 201-psa-ellipse-log branch November 14, 2026 01:37
feralaes added a commit that referenced this pull request Nov 14, 2026
Resolve R/ceac.R: keep #251's argument order (psa, then wtp) and this PR's @concept in
place of the multi-word @Keywords. Examples now show the documented ceac(psa, wtp) order.
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