| Title: | Multistate Population Projection Model for Demographic and HIV Estimation |
|---|---|
| Description: | Leapfrog is a multistate population projection model for estimating population, demographic indicators, and HIV epidemic. The model combines a standard cohort component model of population projection (CCMPP) with a multistate model for HIV infection, disease progression, and treatment. Statistical tools are implemented for joint inference from multiple demographic and epidemiologic data sources. |
| Authors: | Jeffrey Imai-Eaton [aut] (ORCID: <https://orcid.org/0000-0001-7728-728X>), Magdalene Walters [aut], Robert Ashton [aut, cre], Mantra Kusumgar [aut] |
| Maintainer: | Robert Ashton <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.8 |
| Built: | 2026-02-26 12:56:26 UTC |
| Source: | https://github.com/hivtools/leapfrog |
Graduates vector from 5-year to single-year age, assuming the final value is an open-ended age group rather than an additional 5-year age group to be graduated.
beers_open_ended(x)beers_open_ended(x)
x |
vector of length at least 6 |
Get the state space dimensions for a particular model configuration
get_leapfrog_ss(configuration)get_leapfrog_ss(configuration)
configuration |
The configuration to get state space for, see list_model_configurations. |
State space as a named list
Run leapfrog model fit
get_state_space(configuration = "HivFullAgeStratification")get_state_space(configuration = "HivFullAgeStratification")
configuration |
The model configuration to run, see
|
The state space for this model configuration.
s <- get_state_space("HivCoarseAgeStratification")s <- get_state_space("HivCoarseAgeStratification")
Slice a single year from model state
get_time_slice(state, index)get_time_slice(state, index)
state |
The model state with time dimension |
index |
The index of the time step you want to extract |
List of model outputs for the specified time step. Can be used as
input state for run_model_from_state() and run_model_single_year().
All outputs will have 1 fewer dimension than input state.
List the avaialble model configurations
list_model_configurations()list_model_configurations()
List of available model configurations
h_art_stage_dur.Process parameters and convert from 1 based indexing in R to
0 based indexing in C++. Also add in any defaults/extra parameters,
e.g. h_art_stage_dur.
process_parameters_to_cpp(parameters)process_parameters_to_cpp(parameters)
parameters |
The list of parameters to feed into the model. |
List of parameters with 0 based indexing and defaults.
Process parameters and convert from 0 based indexing for C++ to 1 based indexing in R.
process_parameters_to_r(parameters)process_parameters_to_r(parameters)
parameters |
List of parameters. |
List of parameters with 1 based indexing.
Prepare inputs from Spectrum PJNZ
process_pjnz( pjnz, use_coarse_age_groups = FALSE, extract_child_params = FALSE, bypass_adult = FALSE )process_pjnz( pjnz, use_coarse_age_groups = FALSE, extract_child_params = FALSE, bypass_adult = FALSE )
pjnz |
path to PJNZ file |
use_coarse_age_groups |
use the coarse age stratification |
extract_child_params |
If TRUE, then child parameters required to run the child model will be extracted. If FALSE, only adult parameters will be extracted from the PJNZ. |
bypass_adult |
produce parameters that will bypass the adult model when running the child model variant |
list of input parameters
pjnz <- system.file( "pjnz/bwa_aim-adult-art-no-special-elig_v6.13_2022-04-18.PJNZ", package = "leapfrog") parameters <- process_pjnz(pjnz)pjnz <- system.file( "pjnz/bwa_aim-adult-art-no-special-elig_v6.13_2022-04-18.PJNZ", package = "leapfrog") parameters <- process_pjnz(pjnz)
Read parameters from HDF5 file format. This implicitly processes the parameters from C++ 0 based indexing to R 1 based indexing.
read_parameters(file_path)read_parameters(file_path)
file_path |
HDF5 file to read |
Run leapfrog model fit
run_model( parameters, configuration = "HivFullAgeStratification", output_years = seq(1970, 2030) )run_model( parameters, configuration = "HivFullAgeStratification", output_years = seq(1970, 2030) )
parameters |
Projection parameters |
configuration |
The model configuration to run, see
|
output_years |
Which years of the model to return from the simulation,
defaults to all years from 1970 to 2030. Also used to control what years
the simulation is run for. If output only 2030, simulation will be run
from |
List of model outputs, where the last dimension of each element is
time, e.g. p_totpop state variable has dimensions 81 x 2. If
output_years specified has length 61 then the p_totpop output
will have dimensions 81 x 2 x 61.
pjnz <- system.file( "pjnz/bwa_aim-adult-art-no-special-elig_v6.13_2022-04-18.PJNZ", package = "leapfrog", mustWork = TRUE) parameters <- process_pjnz(pjnz, use_coarse_age_groups = TRUE) out <- run_model(parameters, "HivCoarseAgeStratification", 1970:2030)pjnz <- system.file( "pjnz/bwa_aim-adult-art-no-special-elig_v6.13_2022-04-18.PJNZ", package = "leapfrog", mustWork = TRUE) parameters <- process_pjnz(pjnz, use_coarse_age_groups = TRUE) out <- run_model(parameters, "HivCoarseAgeStratification", 1970:2030)
Run leapfrog model fit from initial state
run_model_from_state( parameters, configuration, initial_state, simulation_start_year, output_years = seq(1970, 2030) )run_model_from_state( parameters, configuration, initial_state, simulation_start_year, output_years = seq(1970, 2030) )
parameters |
Projection parameters |
configuration |
The model configuration to run, see
|
initial_state |
The model will run from this initial state |
simulation_start_year |
Start the model simulation from a particular year |
output_years |
Which years of the model to return from the simulation,
defaults to all years from 1970 to 2030. Also used to control what years
the simulation is run for. If output only 2030, simulation will be run
from |
List of model outputs, where the last dimension of each element is
time, e.g. p_totpop state variable has dimensions 81 x 2. If
output_years specified has length 61 then the p_totpop output
will have dimensions 81 x 2 x 61.
pjnz <- system.file( "pjnz/bwa_aim-adult-art-no-special-elig_v6.13_2022-04-18.PJNZ", package = "leapfrog", mustWork = TRUE) parameters <- process_pjnz(pjnz, use_coarse_age_groups = TRUE) out_first_half_years <- run_model(parameters, "HivCoarseAgeStratification", 1970:2000) out_second_half_years <- run_model_from_state( parameters, "HivCoarseAgeStratification", get_time_slice(out_first_half_years, 31), 2000, 2001:2030)pjnz <- system.file( "pjnz/bwa_aim-adult-art-no-special-elig_v6.13_2022-04-18.PJNZ", package = "leapfrog", mustWork = TRUE) parameters <- process_pjnz(pjnz, use_coarse_age_groups = TRUE) out_first_half_years <- run_model(parameters, "HivCoarseAgeStratification", 1970:2000) out_second_half_years <- run_model_from_state( parameters, "HivCoarseAgeStratification", get_time_slice(out_first_half_years, 31), 2000, 2001:2030)
Run leapfrog model fit for a single year
run_model_single_year( parameters, configuration, initial_state, simulation_start_year )run_model_single_year( parameters, configuration, initial_state, simulation_start_year )
parameters |
Projection parameters |
configuration |
The model configuration to run, see
|
initial_state |
The model will run from this initial state |
simulation_start_year |
Start the model simulation from this year |
List of model outputs without the last time dimension.
This is different from run_model_from_state() and run_model()
that do include the last time dimension. Since only the next time
step is returned, dropping the time dimensions makes it easier to
feed the returned list into the next single year model run. In
contrast to run_model_from_state() the p_totpop output will
have dimensions 81 x 2 not 81 x 2 x 61.
pjnz <- system.file( "pjnz/bwa_aim-adult-art-no-special-elig_v6.13_2022-04-18.PJNZ", package = "leapfrog", mustWork = TRUE) parameters <- process_pjnz(pjnz, use_coarse_age_groups = TRUE) out_first_half_years <- run_model(parameters, "HivCoarseAgeStratification", 1970:2000) prev_state <- get_time_slice(out_first_half_years, 31) for (i in 2001:2029) { new_state <- run_model_single_year(parameters, "HivCoarseAgeStratification", prev_state, i) # Do things with new state, other processes, saving output etc. prev_state <- new_state }pjnz <- system.file( "pjnz/bwa_aim-adult-art-no-special-elig_v6.13_2022-04-18.PJNZ", package = "leapfrog", mustWork = TRUE) parameters <- process_pjnz(pjnz, use_coarse_age_groups = TRUE) out_first_half_years <- run_model(parameters, "HivCoarseAgeStratification", 1970:2000) prev_state <- get_time_slice(out_first_half_years, 31) for (i in 2001:2029) { new_state <- run_model_single_year(parameters, "HivCoarseAgeStratification", prev_state, i) # Do things with new state, other processes, saving output etc. prev_state <- new_state }
Save parameters to HDF5 file format. This implicitly processes the parameters to C++ 0 based indexing.
save_parameters(df, file_path)save_parameters(df, file_path)
df |
list/dataframe to serialize |
file_path |
where to save the HDF5 file |