Skip to contents

We have derived mathematical formulas that describe the dynamics of malaria infections as random variables in cohorts of humans as they age (Henry JM, et al., 2024)1 This R package is the computational companion.

In the following, we review the mathematical formulas and the functions in ramp.falciparum that compute the multiplicity of infection (MoI), the age of infection (AoI), and the age of the youngest infection (AoY).

Formulas and Computation

  1. Let zd(α,a)z_d(\alpha,a) denote the density for infections of age α\alpha in a host cohort of age aa born on day dd.

    • The dynamics of z(α,a)z(\alpha,a) are described by the following: za+zα=rz \frac{\partial z}{\partial a} + \frac{\partial z}{\partial \alpha} = - r z with the boundary condition: zd(0,a)=hd(a). \begin{equation} z_d(0,a) = h_d(a). \end{equation} Its solutions are given by: zd(α,a)=hd(aα)erα z_d(\alpha,a) = h_d(a-\alpha) e^{-r \alpha}

    • The function zda computes zd(α,a).z_d(\alpha, a).

  2. The mean MoI is given by the formula: md(a)=0azd(α,a)dα m_d(a) = \int_0^a z_d(\alpha, a) d \alpha

    • The distribution of the MoI is Poisson (Nåsell I, 1985)2 with mean md(a).m_d(a).

    • The function meanMoI computes md(a)m_d(a) using zda

  3. The true prevalence is the pd(a)=1emd(a) p_d(a) = 1 - e^{-m_d(a)} The function truePR computes the true prevalence using meanMoI

  4. The density function for the age of infection (AoI) is Ad(a)fA(α,a,d)=zd(α,a)md(a) A_d(a) \sim f_A(\alpha, a, d) = \frac{z_d(\alpha,a)}{m_d(a)} and its moments are xn(a,d|h)=0aαnfA(α,a,d)dα x_n(a, d | h) = \int_0^a \alpha^n f_A(\alpha, a, d) d \alpha

  5. The age of the youngest infection (AoY) is defined as: Yd(a)fY(α,a,d)=minζMd(a){αi}i=1ζ,αiAd(a) Y_d(a) \sim f_Y(\alpha, a, d) = \min_{\zeta \sim M_d(a)} \left\{ \alpha_i \right\}_{i=1}^\zeta, \alpha_i \sim A_d(a)

    • The density function can be expressed in terms of the density and distribution functions of the AoI and MoI. fY(α;a,d)=fA(α,a,d)emd(a)FA(α,a,d)md(a)pd(a). f_Y(\alpha; a, d) = f_A(\alpha, a,d) e^{-m_d(a) F_A(\alpha, a,d)} \frac{m_d(a)}{p_d(a)}.

    • The distribution function for the AoY is: FY(a)1emd(a)FA(α,a,d)1emd(a)=1emd(a)FA(α,a,d)pd(a) F_Y(a) \sim \frac{1-e^{-m_d(a)F_A(\alpha, a,d)}}{1-e^{-m_d(a)}} = \frac{1-e^{-m_d(a)F_A(\alpha, a,d)}}{p_d(a)} \label{FY}

    • Its moments are: yn(a,d|h)=0aαnfY(α|a,d,h)dα y_n(a, d | h) = \int_0^a \alpha^n f_Y(\alpha | a, d, h) d \alpha

  6. We also developed functions to compute the age of the youngest of NN infections, called YoN Nd(a)minN{αi}i=1N where αiAd(a) N_d(a) \sim \min_{N} \left\{ \alpha_i \right\}_{i=1}^N \mbox { where } \alpha_i \sim A_d(a)

    • The distribution function for YoN, Nd(a)N_d(a), is FN(α,a,t)1(1FA(α,a,d))NF_N(\alpha, a, t) \sim 1- (1-F_A(\alpha, a, d))^N The following is a summary table of functions to compute the MoI, AoI, AoY, and all their moments.

    • The density function for YoN is found by differentiating:

fN(α,a,t)N(1FA(α,a,d))N1fA(α,a,d)md(a)f_N(\alpha, a, t) \sim N (1-F_A(\alpha, a, d))^{N-1}\frac{f_A(\alpha, a, d)}{m_d(a)}

Quick Reference

The following is a summary table of functions to compute the MoI, AoI, AoY, YoN, and all their moments.

MoI AoI AoY YoN
ζ\zeta α\alpha α\alpha α\alpha
ζ0\zeta \geq 0 0αa0 \leq \alpha \leq a 0αa0 \leq \alpha \leq a 0αa0 \leq \alpha \leq a
Random Variable Md(ζ,a,h)M_d(\zeta, a, h) Ad(α,a,h)A_d(\alpha, a, h) Yd(α,a,h)Y_d(\alpha, a , h) Nd(α,a,h)N_d(\alpha, a, h)
Density Function fM(ζ,a,h)f_M(\zeta, a, h) fA(ζ,a,h)f_A(\zeta, a, h) fY(ζ,a,h)f_Y(\zeta, a, h) fN(ζ,a,h)f_N(\zeta, a, h)
dpois dAoI dAoY dYoN
Distribution Function FM(ζ,a,h)F_M(\zeta, a, h) FA(ζ,a,h)F_A(\zeta, a, h) FY(ζ,a,h)F_Y(\zeta, a, h) FN(ζ,a,h)F_N(\zeta, a, h)
ppois pAoI pAoY pYoN
Random Numbers M̂d(ζ,a,h)\hat M_d(\zeta, a, h) Âd(α,a,h)\hat A_d(\alpha, a, h) Ŷd(α,a,h)\hat Y_d(\alpha, a , h) N̂d(α,a,h)\hat N_d(\alpha, a , h)
rpois rAoI rAoY rYoN
Moments md(a,h)m_d(a, h) xn(a,d,h)x_n(a, d, h) yn(a,d,h)y_n(a, d, h)
meanMoI momentAoI momentAoY

Demonstration

Force of Infection (FoI)

clrs = viridisLite::turbo(7)
set.seed(234)
Sa = makepar_F_type2()
Sp = makepar_F_sin()

F_t <- make_ts_function(scale = 1, season_par=Sp)
FoI_a <- make_F_a(avg = 3/365, age_par=Sa, season_par=Sp)

tt <- seq(0, 3650, by=5)
aa <-seq(0, 365*5, by =5) 
plot(tt, 0.05*F_t(tt), type = "l")

To compute anything, we must first set up a function to describe exposure (see the FoI vignette). We define functions that plot the FoI for a cohort as it ages (in red), but we can also compute the population average FoI (in black). Different cohorts would experience different histories of exposure.

Computing zda

The function ramp.falciparum::zda(alpha, a, FoIpar, ...) uses the formula in Eq. 1 to compute the density of parasite infections in a cohort of humans as it ages.

Using zda, we can compute the density of parasites in a cohort of any age without solving a full system of equations. Given a function describing the FoI in the population, h(t)h(t), and the cohort birthday, d.d.

# devtools::load_all()
alpha = 60
a = 6*365
zda(60, 6*365, FoI_a) 
## [1] 0.008962569

The following computes the density of infections of every age in a cohort of age 3.

zz = zda(a3years, max(a3years), FoI_a)

When we plot zd(α,a)z_d(\alpha, a), we note that as α\alpha grows larger, the parasite cohort gets older. When we plot parasite cohorts by age, time is going backwards on the x-axis.

Now, we can imagine what zda would look like for several different host cohorts at age three, but who were born at different times. In effect, we are taking a snapshot of the cohorts at the same age, but at different times.

The curves are different because the hosts were born at different months, and they thus experienced different levels of exposure over the first two years of life. Here the annual FoI is 5 infections, per person, per year (h=5/365\bar h = 5/365):

Multiplicity of Infection (MoI)

We define a random variable MM describing the multiplicity of infection (MoI). The distribution of the MoI is Poisson (see the MoI vignette).

Md(a)fM(ζ;a,d)=Pois(md(a))M_d(a) \sim f_M(\zeta; a, d) = \mbox{Pois}(m_d(a))

Since zd(α,a)z_d(\alpha, a) describes the density of all infections of age α\alpha in a cohort of age aa, the density of all infections must be the MoI. Since 0α<a0 \leq \alpha < a, it must be true that:

md(a)=0azd(α,a)dα\begin{equation} \tag{2} m_d(a) = \int_0^a z_d(\alpha, a) d \alpha \end{equation}

The function that computes md(a)m_d(a) is called meanMoI.

mm = meanMoI(a3years, FoI_a, hhat=5/365)

Here, we plot the average MoI in the host cohort as it ages:

Age of Infection (AoI)

We define a random variable Ad(a)A_d(a) that describes the age of infection (AoI), which is given by the formula

Ad(a)fA(α;a,d)=zd(α,a)md(a) A_d(a) \sim f_A(\alpha; a, d) = \frac{z_d(\alpha,a)}{m_d(a)}

The Density Function, dAoI

We can compute Ad(a)A_d(a) using the density function dAoI:

f_A = dAoI(a3years, max(a3years), FoI_a)

Now, as we plot the distribution of the AoI in cohorts at age two, born at different months (as we did above), we notice that the distributions have changed shapes:

The Distribution Function, pAoI

The distribution function for Ad(a)A_d(a) is:

FA(a)0αfA(α;a,d)dα F_A(a) \sim \int_0^\alpha f_A(\alpha; a, d) d\alpha

F_A = pAoI(a3years, max(a3years), FoI_a)

If our functions work correctly, then we should get approximately the same answer from computing the cumulative sum of dAoI.

F_A_alt = cumsum(f_A)

We shouldn’t expect the answers to be exactly the same, but they should be close, with the pAoI in black.

par(mar = c(5,4,1,1))

plot(a3years, F_A, type = "l", 
     xlab = "Parasite Cohort Age", 
     ylab = expression(1-F[X](alpha, a, bday)), lwd=3)

lines(a3years, F_A_alt, col = "red", lwd=2, lty =2)

Random Numbers, rAoI

The function rAoI uses pAoI to generate random numbers from FA(α)F_A(\alpha)

rhx = rAoI(10000, 3*365, FoI_a)

A simple visual check computes the empirical CDF for the random variates against FA(α)F_A(\alpha) computed using pAoI

par(mar = c(5,4,1,2))
plot(stats::ecdf(rhx), xlim = c(0,1095), cex=0.2, main = "", 
     xlab = expression(list(alpha, paste("Parasite Age (in Days)"))), 
     ylab = expression(list(F[A](alpha), paste("ecdf"))))
lines(a3years, F_A, col = "red", lty = 2, lwd=2)

We can also plot the distribution functions.

AoI Moments

Let xx denote the first moment of of Ad(a)A_d(a): xd(a)=Ad(a)=0αzd(α,a)md(a)x_d(a) = \left< A_d(a) \right> = \int_0^\infty \alpha \frac{z_d(\alpha, a)} {m_d(a)}

Similarly, we let xd(a)[n]x_d(a)[n] denote the higher order moments of Ad(a)A_d(a): x[n](a,d)=0αnzd(α,a)md(a)x_{[n]}(a, d) = \int_0^\infty \alpha^n \frac{z_d(\alpha, a)} {m_d(a)}

moment1 = momentAoI(a3years, FoI_a)
moment2 = momentAoI(a3years, FoI_a, n=2)
moment3 = momentAoI(a3years, FoI_a, n=3)

The first three moments of the AoY plotted over time. In the top plot, we’ve also plotted the nthn^{th} root of the nthn^{th} moment.

Age of the Youngest Infection (AoY)

We have derived a random variable Yd(a)Y_d(a) describing the age of the youngest infection (AoY). The density function for the AoY is:

Yd(a)fY(α;a,d)=fA(α,a,d)emd(a)FA(α,a,d)md(a)pd(a)Y_d(a) \sim f_Y(\alpha; a, d) = f_A(\alpha, a,d) e^{-m_d(a) F_A(\alpha, a,d)} \frac{m_d(a)}{p_d(a)} The distribution function is:

FY(a)1emd(a)FA(α,a,d)1emd(a)=1emd(a)FA(α,a,d)pd(a)F_Y(a) \sim \frac{1-e^{-m_d(a)F_A(\alpha, a,d)}}{1-e^{-m_d(a)}} = \frac{1-e^{-m_d(a)F_A(\alpha, a,d)}}{p_d(a)}

The derivations are found in a Suppplement to Henry JM, et al. (2024).

The mean AoY is:

Yd(a)=0aαfY(α,a,d)dα \left< Y_d(a) \right> = \int_0^a \alpha \; f_Y(\alpha, a, d) \; d\alpha

And the higher order moments for the AoY are:

Yd(a)n=0nαnfy(α,a,d)dα\left< Y_d(a)^n \right> = \int_0^n \alpha^n \; f_y(\alpha, a, d) \; d\alpha

AoY Density, dAoY

The density function is computed with the function dAoY.

f_Y = dAoY(a3years, 3*365, FoI_a)

We can compare fY(α)f_Y(\alpha) (in black) to fA(α)f_A(\alpha) (in grey).

Random Variables, rAoY

raoy = rAoY(10^5, 3*365, FoI_a)
hist(raoy, breaks=seq(0, 1095, by = 15), 
     right=F, probability=T, main = "", 
     xlab = expression(list(alpha, paste("Parasite Age (in Days)"))), 
     border = grey(0.5)) -> out
lines(a3years, f_Y, type = "l", col = "red") 

AoY Moments

aa = seq(5, 3*365, by = 5) 
moment1y = momentAoY(aa, FoI_a)
moment2y = momentAoY(aa, FoI_a, n=2)
moment3y = momentAoY(aa, FoI_a, n=3)

The first three moments of the AoY plotted over time. In the top plot, we’ve also plotted the nthn^{th} root of the nthn^{th} moment.


Next:

  • In the vignette MoI, we show that the mean MoI computed using the formula in Eq. 2 gives the same answer as other approaches.