The openqalyregimen package provides a declarative interface for defining treatment regimens and calculating medication costs. It handles a wide range of cases including:
- Dosing per patient, per m2 of BSA, or per kg of weight, with optional averaging over a patient distribution of BSA or weight
- One costing model for every product (tablets, vials and other units): the cheapest units covering the dose, exact whole-unit doses, dose rounding against the prescribed dose, or a no-wastage scenario
- Drug cost recorded per administration or per dispensing, with separate administration and dispensing fees
- Handling of loading doses, dose escalation, and sequencing
- Correctly attributes all costs to the model cycle schedule, even when medication cycles do not align with model cycles
- Extensive debugging output to ensure transparency
- Out of the box compatability with openqaly models, but can also be used independently
# Install the development version from GitHub
remotes::install_github("PolicyAnalysisInc/openqalyregimen")library(openqalyregimen)
reg <- define_regimen(
name = "Capecitabine",
route = "oral",
dose_per_admin = 2000,
dose_basis = "bsa",
patient_bsa = 1.8,
patient_bsa_sd = 0.2,
med_cycle_length = 21,
admin_days = 1:14,
max_med_cycles = 4,
unit_size = c(150, 500),
unit_cost = 2.21,
exact = FALSE,
charge_timing = "per_dispensing",
dispensing_cost = 45
)
calculate_med_costs(
reg,
model_cycle_length = 21,
n_cycles = 4
)
#> cycle cycle_start_day cycle_end_day n_administrations n_dispensings drug_cost
#> 1 1 0 21 14 1 238.2382
#> 2 2 21 42 14 1 238.2382
#> 3 3 42 63 14 1 238.2382
#> 4 4 63 84 14 1 238.2382
#> admin_cost dispensing_cost total_cost
#> 1 0 45 283.2382
#> 2 0 45 283.2382
#> 3 0 45 283.2382
#> 4 0 45 283.2382Because the dose is averaged over a BSA distribution, this example uses
exact = FALSE: for each BSA the cheapest tablets covering the dose are
costed. Exact whole-tablet dosing (exact = TRUE) needs a fixed dose.
The package vignettes cover:
- Oral regimens
- IV and injection regimens
- Combinations, loading doses, and phase changes
- Use inside an
openqalymodel
Copyright (C) 2026 Avalere Health. Licensed under the GNU General Public
License v3.0; see LICENSE.md.