Runs a vectorised microsimulation for a cohort of individuals over a specified number of cycles. Individuals transition between health states according to probabilities that depend on their current state and time spent in that state. Costs and QALYs are accumulated each cycle and optionally discounted.
Usage
run_microSimV(
v_starting_states,
num_i,
num_cycles,
m_indi_features,
v_states_names,
v_states_costs,
v_cost_coeffs,
v_states_utilities,
v_util_coeffs,
v_util_t_decs,
l_trans_probs,
discount_rate_costs,
discount_rate_QALYs,
cycle_length = 1,
starting_seed = 1,
assert = TRUE
)Arguments
- v_starting_states
Character vector giving the starting state for each individual.
- num_i
Integer giving the number of individuals in the cohort.
- num_cycles
Integer giving the number of cycles to simulate.
- m_indi_features
Matrix or data.frame of individual covariates with rows corresponding to individuals and columns corresponding to features. Must include a column named
agewhich is incremented each cycle.- v_states_names
Character vector of all state names in the order used throughout the model.
- v_states_costs
Named numeric vector of base costs for each state.
- v_cost_coeffs
Numeric vector of regression coefficients for costs.
- v_states_utilities
Named numeric vector of base utilities for each state.
- v_util_coeffs
Numeric vector of regression coefficients for utilities.
- v_util_t_decs
Named numeric vector of time‑dependent utility decrements for states S1 and S2.
- l_trans_probs
Named list of transition probabilities and rate ratios; see
update_probsVfor details.- discount_rate_costs
Numeric. Annual discount rate used for costs.
- discount_rate_QALYs
Numeric. Annual discount rate used for QALYs.
- cycle_length
Numeric. Length of each cycle in years. Defaults to 1.
- starting_seed
Numeric. Optional seed for the random number generator to allow reproducible results.
- assert
Logical. Boolean for whether to run full assertion of inputs. This feature is useful when running probabilistic sensitivity analysis (PSA).
Value
A list containing the matrices of states, costs and QALYs by cycle, undiscounted and discounted totals per individual and averages across individuals.
Examples
res <- run_microSimV(
v_starting_states = v_starting_states,
num_i = num_i,
num_cycles = num_cycles,
m_indi_features = m_indi_features,
v_states_names = v_states_names,
v_states_costs = v_states_costs,
v_cost_coeffs = v_cost_coeffs,
v_states_utilities = v_states_utilities,
v_util_coeffs = v_util_coeffs,
v_util_t_decs = v_util_t_decs,
l_trans_probs = l_trans_probs,
discount_rate_costs = discount_rate_costs,
discount_rate_QALYs = discount_rate_QALYs,
cycle_length = cycle_length,
starting_seed = seed
)
res$mean_costs
#> [1] 98822.67
res$mean_qalys
#> [1] 18.72664