Skip to contents

status badge

This repository contains a mathematical model of red blood cell (RBC) dynamics in a malaria infection. This model includes the spleen as a separate model compartment that can retain large amounts of infected and uninfected RBCs.

This model is described in The role of the spleen in red blood cell loss caused by malaria: a mathematical model, PLOS Comp Biol 22(1), 2026.

See the online documentation for vignettes and reference materials.

Installation

The model is implemented in R and provided as an R package called spleenrbc. The simplest way to install this package is:

package_repos <- c(
  CRAN = "https://cloud.r-project.org/",
  spleenrbc = "https://robmoss.r-universe.dev"
)
install.packages("spleenrbc", repos = package_repos)
library(spleenrbc)

You will then be able to run the baseline model scenarios, and define and run your own model scenarios. See the provided package documentation and vignettes for examples.

Running simulations and plotting results

The simulation and plotting scripts are not included in the package itself. In order to run them, you will need to clone this repository:

git clone https://gitlab.unimelb.edu.au/rgmoss/malaria-spleen-rbc-loss.git
cd malaria-spleen-rbc-loss

Running simulations

There are scripts to run the following simulations:

  • run-baseline-scenarios.R: using the baseline model parameters, run a single simulation for the following scenarios:

    • No infection;
    • Pf infection; and
    • Pv infection.

    This script saves the results to a separate CSV file in the outputs/ directory.

  • You can plot the results of the above scenarios with the plot-scenarios.R script. For example, run the following command to plot the baseline Pf results:

    ./plot-scenarios.R outputs/baseline-pf.csv
  • run-sensitivity-analysis.R: run 1000 simulations for Pf infections and 1000 simulations for Pv infections, and plot the results. The repository contains summary output files for these simulations, so this script will run very quickly. If these summary output files are removed, note that it may take several hours to run all of the simulations.

Code structure

The model implementation is divided into multiple R files:

  • Model parameters:

    • parameters.R provides functions that return baseline parameter values (baseline_parameters) and calculate values for dependent parameters (define_derived_parameters).

    • homeostasis.R provides a function that calculates the reticulocyte production rate and red blood cell populations at homeostasis, in the absence of a malaria infection (retic_steady_state).

  • Model state:

    • state.R provides functions that create the initial model state (initial_spleenrbc_state), simulate the model forward one time-step (step_spleenrbc_model), and perform an entire model simulation (run_spleenrbc_model).

    • rate_functions.R provides functions that calculate the time-varying rates that govern the movement and destruction of red blood cells in the model.

  • Simulation outputs:

    • outputs.R provides functions that record key outputs of a each simulation (individual_results), and calculate derived quantities of interest (infection_flows_and_loss, calculate_irbc_ratio, uncertainty_intervals, rbc_counts_to_haemoglobin).
  • Running model simulations:

    • run.R provides a function for running multiple model simulations (run_spleenrbc).

    • sensitivity.R provides functions that define sampling distributions for the sensitivity analysis (triangle_distributions) and draw parameter samples for the sensitivity analysis (sample_parameters).