Skip to content

Convert between BCEA and dampack objects: bcea_to_psa() and psa_to_bcea() (#204) - #244

Open
feralaes wants to merge 2 commits into
mainfrom
204-bcea-conversion
Open

feralaes wants to merge 2 commits into
mainfrom
204-bcea-conversion

Conversation

@feralaes

@feralaes feralaes commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #204. This was Eline's suggestion, so I've asked her to review.

What's new

data(Vaccine, package = "BCEA")
m <- BCEA::bcea(eff, cost, ref = 2, interventions = treats, Kmax = 50000)

psa_vaccine <- bcea_to_psa(m, currency = "£")   # BCEA -> dampack
plot(ceac(psa_vaccine, wtp = seq(0, 50000, by = 5000)))

m2 <- psa_to_bcea(psa_vaccine, ref_str = "Vaccination", Kmax = 50000)   # dampack -> BCEA
  • bcea_to_psa(bcea, currency = "$", parameters = NULL): builds a psa object from a bcea object's costs, effects and intervention names. BCEA objects don't store parameter values, so they can be passed in to use EVPPI or OWSA.
  • psa_to_bcea(psa, ref_str = NULL, ...): calls BCEA::bcea(). ref_str names the reference strategy (it defaults to the first), and ... is passed on, e.g. Kmax.
  • Dependency: BCEA is only suggested. It's needed for psa_to_bcea(), which tells the user to install it if it's missing. The examples run only when BCEA is installed.

Tests

  • Without BCEA: conversion of an object shaped like BCEA output (names, values, currency, optional parameters), and errors for input that isn't a bcea object or is incomplete.
  • With BCEA installed: a round trip on BCEA's own Vaccine data, which returns the same effects, costs and reference.
  • An independent check of dampack: calc_evpi() equals BCEA's own EVPI to within 1e-8 at several willingness-to-pay values. That's an external validation of dampack's EVPI, possibly worth a sentence in the JOSS paper.

I ran the BCEA tests against BCEA 2.4.83, installed in a separate library. CI doesn't install BCEA, so it runs the BCEA-free tests and skips the rest.

Verification

  • 272 tests pass, 0 lints, and pkgdown::check_pkgdown() is clean.
  • R CMD check --as-cran: 0 errors, 0 warnings, 1 NOTE (the development version number).
  • Outputs of every existing vignette and help-page example are identical to main.
  • NEWS credits Eline for the suggestion.

- bcea_to_psa(): turns BCEA::bcea() output into a dampack psa object
  (costs, effects, and intervention names; optional parameters and
  currency), so dampack's analyses and plots can be used on it.
- psa_to_bcea(): the reverse, via BCEA::bcea(); ref_str names the
  reference strategy, and ... is passed on (e.g., Kmax).
- BCEA is a suggested package, needed only for psa_to_bcea()
  (rlang::check_installed()). Examples run only when BCEA is installed.
- Tests: conversion with a BCEA-shaped object (no BCEA needed), input
  errors, and with BCEA installed a round trip on BCEA's Vaccine data and
  an independent check that calc_evpi() equals BCEA's EVPI (to 1e-8).

Closes #204
@feralaes
feralaes requested a review from krijkamp November 13, 2026 15:16
@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@feralaes

Copy link
Copy Markdown
Collaborator Author

Hi @krijkamp, this PR adds the BCEA conversion you suggested in #204. Fernando asked me (Claude, working in his session) to send a short guide so it's quick to review.

Try it

install.packages("BCEA")
remotes::install_github("DARTH-git/dampack", ref = "204-bcea-conversion")
library(dampack)

data(Vaccine, package = "BCEA")
m <- BCEA::bcea(eff, cost, ref = 2, interventions = treats, Kmax = 50000)

psa_vaccine <- bcea_to_psa(m, currency = "£")   # BCEA -> dampack
plot(psa_vaccine)
plot(ceac(psa_vaccine, wtp = seq(0, 50000, by = 5000)))
calc_evpi(psa_vaccine, wtp = seq(0, 50000, by = 5000))

m2 <- psa_to_bcea(psa_vaccine, ref_str = "Vaccination", Kmax = 50000)   # dampack -> BCEA
summary(m2)

What to look at

  • Do the conversions match what you'd expect from BCEA? The strategy names, the reference, and which costs and effects go where.
  • Is the documentation clear for a BCEA user? See ?bcea_to_psa. One point to check: BCEA objects don't store the model parameters. So to use EVPPI or OWSA after converting, you pass them yourself with parameters =.
  • External check: dampack's EVPI matches BCEA's to within 1e-8. If you know other BCEA outputs we should compare, say so.

How to leave your review

  1. Click the Files changed tab at the top of this PR.
  2. Click the green Review changes button at the top right.
  3. Choose Approve, Request changes or Comment, then click Submit review.

A plain comment at the bottom of this page also works.

This branch has not been deployed

No deployments
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.

suggestion to add a wrapper function to turn the BCEA object into the dampack object

1 participant