View source: R/visualize_cost.R
| visualize_cost | R Documentation |
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 how much its term changes the cost over the bounds (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. On narrow bounds far from 0 the terms of the cubic form nearly cancel, so its curve cannot be drawn or shaped accurately there. The app then shows a warning, and the linear form is the better choice. 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().
visualize_cost(
component_names,
unit_costs,
default_cost_fxn_type,
intervention_lower_bounds,
intervention_upper_bounds
)
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. |
The unit costs and the bounds are matched to the components as in
lago_optimization(). An unnamed vector is matched by position. A
named one is matched by name when a name is one of the components, or when
it has two or more values that all have names. Its names must then be the
component names, each once. Other names are ignored and the values are
matched by position.
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.
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.
lago_optimization()
Other LAGO functions:
get_confidence_set(),
lago_budget(),
lago_optimization(),
lago_report(),
lago_sensitivity()
## Not run:
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)
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.