Please install from our r-universe:
install.packages(
"frogger",
repos = c("https://mrc-ide.r-universe.dev", "https://cloud.r-project.org"))
You can install the development version of frogger from GitHub with:
# install.packages("remotes")
remotes::install_github("mrc-ide/frogger", subdir = "r-package")
The simulation model is implemented in a header-only C++ library located in r-package/inst/include/frogger.hpp
. This location allows the C++ code to be imported in other R packages via specifying LinkingTo: leapfrog
in the DESCRIPTION
file.
[!IMPORTANT] We use C++20 for this package. Please make sure you have a compiler that is compatible.
The simulation model is callable in R via a wrapper function run_model()
created with Rcpp.
You can control how the simulation model is run by setting the configuration
argument, see
frogger::list_model_configurations()
for the list of available models. At the time of writing these are - DemographicProjection
- runs on the demographic projections - HivFullAgeStratification
- runs the demographic projection and HIV adult projection with single-year age groups - HivCoarseAgeStratification
- runs the demographic projection and HIV adult projection with 5-year age groups - ChildModel
- runs the demographic projection, single-year age stratified HIV adult projection and HIV child projection
The file pjnz/bwa_aim-adult-art-no-special-elig_v6.13_2022-04-18.PJNZ
contains an example Spectrum file constructed from default country data for Botswana with Spectrum (April 2022).
Prepare model inputs.
library(frogger)
pjnz <- system.file("pjnz/bwa_aim-adult-art-no-special-elig_v6.13_2022-04-18.PJNZ",
package = "frogger", mustWork = TRUE)
parameters <- prepare_leapfrog_parameters(pjnz)
Simulate adult ‘full’ age group (single-year age) and ‘coarse’ age group (collapsed age groups) models from 1970 to 2030 with 10 HIV time steps per year.
lsimF <- run_model(parameters, "HivFullAgeStratification", 1970:2030)
lsimC <- run_model(parameters, "HivCoarseAgeStratification", 1970:2030)
Compare the HIV prevalence age 15-49 years and AIDS deaths 50+ years. Deaths 50+ years are to show some noticeable divergence between the "full"
and "coarse"
age group simulations.
prevF <- colSums(lsimF$p_hiv_pop[16:50,,],,2) / colSums(lsimF$p_total_pop[16:50,,],,2)
prevC <- colSums(lsimC$p_hiv_pop[16:50,,],,2) / colSums(lsimC$p_total_pop[16:50,,],,2)
deathsF <- colSums(lsimF$p_hiv_deaths[51:81,,],,2)
deathsC <- colSums(lsimC$p_hiv_deaths[51:81,,],,2)
plot(1970:2030, prevF, type = "l", main = "Prevalence 15-49")
lines(1970:2030, prevC, col = 2)
plot(1970:2030, deathsF, type = "l", main = "AIDS Deaths 50+ years")
lines(1970:2030, deathsC, col = 2)
Lint R code with lintr
lintr::lint_package()
Lint C++ code with cpplint
cpplint r-package/inst/include/*
There is some pre-prepared test data available to make tests run faster. This is generated and saved ./scripts/create_test_data.R
.
We also have some separate data written out in a generic format which can be read to test the model directly from C++. This is in inst/standalone_model/data
in zipped files.
If this is your first time running you will need to unzip the standalone test data
If you want to update the test data, it should be updated in the ./scripts/create_test_data.R
script so that we know how it was created and we can do it again fairly easily. Steps are 1. Update the script and generate the test data 1. Update the standalone data which is built from this ./scripts/update_standalone_data
. You might need to add a new mapping from R to serialized name if you are adding new input data 1. Unzip this for automated tests ./inst/standalone_model/extract_data