Skip to contents

Visualize the cost functions for the intervention components. This function creates a Shiny app that allows the user to adjust the coefficients of the cost functions for each intervention component and visualize the resulting total cost function and its derivative. The initial coefficients are calculated based on the unit costs, the cost function type (linear or cubic), and the lower and upper bounds. A "Cost function form" toggle at the top switches all components between the linear (2 coefficients) and cubic (a degree-4 total cost, 5 coefficients) forms, resetting each to that form's initial coefficients. The user can adjust the coefficients using sliders and reset them to their initial values. Each slider has a default range scaled to its coefficient's magnitude (derived from the unit costs and bounds), and the user can set a custom range for any slider using its "Range min" / "Range max" inputs. The total cost curve can also be reshaped directly: it carries a draggable handle at each of several points along the curve, and dragging one refits the cost function through the new set of points and updates the sliders. The app also displays the current coefficient vector for each component. The user can copy the final coefficient list for use in the optimization function lago_optimization().

Usage

visualize_cost(
  component_names,
  unit_costs,
  default_cost_fxn_type,
  intervention_lower_bounds,
  intervention_upper_bounds
)

Arguments

component_names

A character vector of the names of the intervention components.

unit_costs

A numeric vector of the unit costs for each intervention component.

default_cost_fxn_type

A character string specifying the cost function type the app opens with. Must be either "linear" or "cubic". The user can switch forms in the app with the "Cost function form" toggle.

intervention_lower_bounds

A numeric vector of the lower bounds for each intervention component.

intervention_upper_bounds

A numeric vector of the upper bounds for each intervention component.

Value

Invisibly, the cost-function coefficient list (a list of numeric vectors, one per intervention component) as it stood when the app was closed, suitable for passing to lago_optimization(cost_list_of_vectors = ...). The same list can be copied from within the app.

Details

When the app is closed with the "Return list to R & close" button, the coefficient list is also stored in the lago_cost_list option (overwriting any existing value) and a message reports this, so the list is available even when the app was launched with a bare visualize_cost(...) call rather than cost_list <- visualize_cost(...). Retrieve it with getOption("lago_cost_list"). Closing the browser tab instead of using the button does not save the list.

See also

Examples

if (FALSE) { # \dontrun{
visualize_cost(
  component_names = c("Component 1", "Component 2"),
  unit_costs = c(0.5, 1),
  default_cost_fxn_type = "linear",
  intervention_lower_bounds = c(0, 0),
  intervention_upper_bounds = c(10, 10)
)
} # }