Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## New features

- The currency of a `psa` object now carries through to its analyses: `ceac()`, `calc_exp_loss()`, `calc_evpi()`, `calc_evppi()`, `calc_evsi()`, and `calculate_icers_psa()` keep it, and their `plot()` and `print()` methods use it unless `currency` is given. `plot.ceac()` gains `effect_units` (#203).
- `summary.psa()` gains `ref_str` and `wtp`. With a reference strategy it adds the mean incremental cost and effect and the proportion of PSA samples in each quadrant of the incremental cost-effectiveness plane (`propNE`, `propSE`, `propSW`, `propNW`); with `wtp` it adds the mean NMB and, with a reference, `meanIncNMB` and the proportion of samples that are cost-effective compared with the reference (`propCostEffective`) (#209, #202).
- `calculate_icers_psa()` gains `ref_str`, `wtp`, and `nhb`. With `uncertainty = TRUE` and a reference strategy, it adds 95% intervals for the differences from the reference, computed sample by sample (#209).
- `plot.icers()` gains `ref_str`, which plots the incremental cost-effectiveness plane with the reference strategy at the origin, and `wtp`, which draws a willingness-to-pay line. `plot.psa()` gains `wtp` for the same line on its incremental plane. `plot.icers()` uses the currency stored by `calculate_icers()` (#209, #202).
Expand All @@ -27,6 +28,7 @@

## Bug fixes

- EVPPI and EVSI computed from net health benefit (`outcome = "nhb"`, the default of `calc_evsi()`) are in health units, and their plots are now labeled with `effect_units` (e.g., "EVSI (QALY)") instead of a currency (#203).
- `plot.psa(ref_str = )` now works when there are only two strategies; it used to fail with "'dims' cannot be of length 0" (#209).
- `plot.owsa(col = "bw")` now draws each strategy with its own line type; all strategies used to share one line type and could not be told apart (#176).
- `metamodel()` now names invalid parameters in its error message, including when called through `calc_evppi()` and `calc_evsi()` (#177).
Expand Down
27 changes: 27 additions & 0 deletions R/add_common_aes.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,30 @@ number_ticks <- function(n) {
pretty(limits, n + 1)
}
}

#' Currency to use for labels
#'
#' @param currency currency given by the user, or \code{NULL}.
#' @param x a result object that may carry a \code{"currency"} attribute.
#' @return \code{currency} if given, otherwise the currency stored on \code{x}, otherwise \code{"$"}.
#' @keywords internal
resolve_currency <- function(currency, x) {
if (!is.null(currency)) {
return(currency)
}
if (is.null(attr(x, "currency"))) "$" else attr(x, "currency")
}

#' Units of a value-of-information result
#'
#' EVPPI and EVSI computed from net health benefit are in health units; from net monetary
#' benefit, in currency.
#'
#' @param x an \code{evppi} or \code{evsi} object.
#' @param currency currency label.
#' @param effect_units units of effectiveness.
#' @return \code{effect_units} if \code{x} was computed with \code{outcome = "nhb"}, else \code{currency}.
#' @keywords internal
voi_units <- function(x, currency, effect_units) {
if (identical(attr(x, "outcome"), "nhb")) effect_units else currency
}
11 changes: 8 additions & 3 deletions R/ceac.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ ceac <- function(wtp, psa) {
# define classes
# defining data.frame as well allows the object to use print.data.frame, for example
class(ceac) <- c("ceac", "data.frame")
attr(ceac, "currency") <- psa$currency

ceac
}
Expand All @@ -134,7 +135,9 @@ ceac <- function(wtp, psa) {
#' @param frontier whether to plot acceptability frontier (TRUE) or not (FALSE)
#' @param points whether to plot points (TRUE) or not (FALSE)
#' @param currency string with currency used in the cost-effectiveness analysis (CEA).
#'Defaults to \code{$}, but can be any currency symbol or word (e.g., £, €, peso)
#' Defaults to the currency of the PSA the CEAC was computed from (or \code{$}), but can be any
#' currency symbol or word (e.g., £, €, peso).
#' @param effect_units units of effectiveness, used in the x-axis label. Default: QALY
#' @param min_prob minimum probability to show strategy in plot.
#' For example, if the min_prob is 0.05, only strategies that ever
#' exceed Pr(Cost Effective) = 0.05 will be plotted. Most useful in situations
Expand All @@ -157,7 +160,7 @@ ceac <- function(wtp, psa) {
plot.ceac <- function(x,
frontier = TRUE,
points = TRUE,
currency = "$",
currency = NULL,
min_prob = 0,
txtsize = 12,
n_x_ticks = 10,
Expand All @@ -167,7 +170,9 @@ plot.ceac <- function(x,
ylim = NULL,
xlim = c(0, NA),
col = c("access", "full", "bw"),
effect_units = "QALY",
...) {
currency <- resolve_currency(currency, x)
wtp_name <- "WTP"
prop_name <- "Proportion"
strat_name <- "Strategy"
Expand Down Expand Up @@ -217,7 +222,7 @@ plot.ceac <- function(x,
y = !!sym(prop_name),
color = !!sym(strat_name))) +
geom_line() +
xlab(paste("Willingness to Pay (Thousand ", currency, " / QALY)", sep = "")) +
xlab(paste("Willingness to Pay (Thousand ", currency, " / ", effect_units, ")", sep = "")) +
ylab("Pr Most Cost-Effective")

if (points) {
Expand Down
7 changes: 5 additions & 2 deletions R/evpi.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ calc_evpi <- function(psa, wtp, pop = 1) {

# declare class as both evpi (plotting) and data.frame (printing)
class(df_evpi) <- c("evpi", "data.frame")
attr(df_evpi, "currency") <- psa$currency
df_evpi
}

Expand All @@ -66,7 +67,8 @@ calc_evpi <- function(psa, wtp, pop = 1) {
#' @param x object of class \code{evpi}, produced by function
#' \code{\link{calc_evpi}}
#' @param currency string with currency used in the cost-effectiveness analysis (CEA).
#' Default: $, but it could be any currency symbol or word (e.g., £, €, peso)
#' Default: the currency of the PSA the results were computed from (or $), but it could be any
#' currency symbol or word (e.g., £, €, peso)
#' @param effect_units units of effectiveness. Default: QALY
#' @inheritParams add_common_aes
#' @keywords expected value of perfect information
Expand All @@ -77,7 +79,7 @@ calc_evpi <- function(psa, wtp, pop = 1) {
#' @export
plot.evpi <- function(x,
txtsize = 12,
currency = "$",
currency = NULL,
effect_units = "QALY",
n_y_ticks = 8,
n_x_ticks = 20,
Expand All @@ -87,6 +89,7 @@ plot.evpi <- function(x,
ylim = NULL,
...) {
WTP_thou <- EVPI <- NULL
currency <- resolve_currency(currency, x)
x$WTP_thou <- x$WTP / 1000
g <- ggplot(data = x,
aes(x = WTP_thou, y = EVPI)) +
Expand Down
12 changes: 9 additions & 3 deletions R/evppi.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ calc_evppi <- function(psa,
# define parameter values and make sure they correspond to a valid option
type <- match.arg(type)
outcome <- match.arg(outcome)
outcome_input <- outcome

# adjust outcome type
outcome <- paste0(outcome, "_loss_voi")
Expand Down Expand Up @@ -127,6 +128,8 @@ calc_evppi <- function(psa,

evppi_ls <- list(df_evppi = df_evppi, metamodel_ls = l_mms)
class(evppi_ls) <- c("evppi")
attr(evppi_ls, "currency") <- psa$currency
attr(evppi_ls, "outcome") <- outcome_input
evppi_ls
}

Expand All @@ -138,7 +141,8 @@ calc_evppi <- function(psa,
#' @param x object of class \code{evppi}, produced by function
#' \code{\link{calc_evppi}}
#' @param currency string with currency used in the cost-effectiveness analysis (CEA).
#' Default: $, but it could be any currency symbol or word (e.g., £, €, peso)
#' Default: the currency of the PSA the results were computed from (or $), but it could be any
#' currency symbol or word (e.g., £, €, peso)
#' @param effect_units units of effectiveness. Default: QALY
#' @inheritParams add_common_aes
#' @keywords expected value of perfect information
Expand All @@ -149,7 +153,7 @@ calc_evppi <- function(psa,
#' @export
plot.evppi <- function(x,
txtsize = 12,
currency = "$",
currency = NULL,
effect_units = "QALY",
n_y_ticks = 8,
n_x_ticks = 20,
Expand All @@ -159,13 +163,15 @@ plot.evppi <- function(x,
ylim = NULL,
...) {
WTP_thou <- EVPPI <- NULL
currency <- resolve_currency(currency, x)
v_units <- voi_units(x, currency, effect_units)
x <- x[[1]]
x$WTP_thou <- x$WTP / 1000
g <- ggplot(data = x,
aes(x = WTP_thou, y = EVPPI)) +
geom_line() +
xlab(paste("Willingness to Pay (Thousand ", currency, "/", effect_units, ")", sep = "")) +
ylab(paste("EVPPI (", currency, ")", sep = ""))
ylab(paste("EVPPI (", v_units, ")", sep = ""))
add_common_aes(g, txtsize, continuous = c("x", "y"),
n_x_ticks = n_x_ticks, n_y_ticks = n_y_ticks,
xbreaks = xbreaks, ybreaks = ybreaks,
Expand Down
12 changes: 9 additions & 3 deletions R/evsi.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ calc_evsi <- function(psa,
progress = TRUE) {
# define parameter values and make sure they correspond to a valid option
outcome <- match.arg(outcome)
outcome_input <- outcome

# adjust outcome type
outcome <- paste0(outcome, "_loss_voi")
Expand Down Expand Up @@ -108,6 +109,8 @@ calc_evsi <- function(psa,
}
evsi_ls <- list(df_evsi = df_evsi, metamodel_ls = l_mms)
class(evsi_ls) <- c("evsi")
attr(evsi_ls, "currency") <- psa$currency
attr(evsi_ls, "outcome") <- outcome_input
evsi_ls
}

Expand Down Expand Up @@ -282,7 +285,8 @@ predict_matrix_tensor_smooth_ga <- function(object,
#' @param x object of class \code{evsi}, produced by function
#' \code{\link{calc_evsi}}
#' @param currency string with currency used in the cost-effectiveness analysis (CEA).
#' Default: $, but it could be any currency symbol or word (e.g., £, €, peso)
#' Default: the currency of the PSA the results were computed from (or $), but it could be any
#' currency symbol or word (e.g., £, €, peso)
#' @param effect_units units of effectiveness. Default: QALY
#' @inheritParams add_common_aes
#' @keywords expected value of sample information
Expand All @@ -293,7 +297,7 @@ predict_matrix_tensor_smooth_ga <- function(object,
#' @export
plot.evsi <- function(x,
txtsize = 12,
currency = "$",
currency = NULL,
effect_units = "QALY",
n_y_ticks = 8,
n_x_ticks = 20,
Expand All @@ -305,6 +309,8 @@ plot.evsi <- function(x,
...) {
# Select EVSI data.frame, discarding metamodel list
EVSI <- WTP_thou <- NULL
currency <- resolve_currency(currency, x)
v_units <- voi_units(x, currency, effect_units)
x <- x[[1]]
x$WTP_thou <- x$WTP / 1000
col <- match.arg(col)
Expand Down Expand Up @@ -332,7 +338,7 @@ plot.evsi <- function(x,

g <- g +
geom_line() +
ylab(paste("EVSI (", currency, ")", sep = ""))
ylab(paste("EVSI (", v_units, ")", sep = ""))
add_common_aes(g, txtsize, continuous = c("x", "y"),
n_x_ticks = n_x_ticks, n_y_ticks = n_y_ticks,
xbreaks = xbreaks, ybreaks = ybreaks,
Expand Down
7 changes: 5 additions & 2 deletions R/exp_loss.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ calc_exp_loss <- function(psa, wtp) {
df_exp_loss_melt$Strategy <- factor(df_exp_loss_melt$Strategy, levels = v_strategies, ordered = TRUE)

class(df_exp_loss_melt) <- c("exp_loss", "data.frame")
attr(df_exp_loss_melt, "currency") <- psa$currency
df_exp_loss_melt
}

Expand All @@ -96,7 +97,8 @@ calc_exp_loss <- function(psa, wtp) {
#' @param x object of class \code{exp_loss}, produced by function
#' \code{\link{calc_exp_loss}}
#' @param currency string with currency used in the cost-effectiveness analysis (CEA).
#' Default: $, but it could be any currency symbol or word (e.g., £, €, peso)
#' Default: the currency of the PSA the results were computed from (or $), but it could be any
#' currency symbol or word (e.g., £, €, peso)
#' @param effect_units units of effectiveness. Default: QALY
#' @param log_y take the base 10 log of the y axis
#' @param frontier indicate the frontier (also the expected value of perfect information).
Expand All @@ -117,7 +119,7 @@ plot.exp_loss <- function(x,
points = TRUE,
lsize = 1,
txtsize = 12,
currency = "$",
currency = NULL,
effect_units = "QALY",
n_y_ticks = 8,
n_x_ticks = 20,
Expand All @@ -128,6 +130,7 @@ plot.exp_loss <- function(x,
col = c("access", "full", "bw"),
...) {
On_Frontier <- NULL
currency <- resolve_currency(currency, x)
wtp_name <- "WTP_thou"
loss_name <- "Expected_Loss"
strat_name <- "Strategy"
Expand Down
3 changes: 2 additions & 1 deletion R/icers.R
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ calculate_icers_psa <- function(psa, uncertainty = FALSE, ref_str = NULL, wtp =
df_icers <- calculate_icers(cost = df_psa_sum$meanCost,
effect = df_psa_sum$meanEffect,
strategies = df_psa_sum$Strategy,
ref_str = ref_str, wtp = wtp, nhb = nhb)
ref_str = ref_str, wtp = wtp, nhb = nhb,
currency = psa$currency)

if (uncertainty == TRUE) {
# the joins and column selection below drop the icers class and attributes; keep them
Expand Down
8 changes: 6 additions & 2 deletions man/plot.ceac.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/plot.evpi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/plot.evppi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/plot.evsi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/plot.exp_loss.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading