Dynamics.Rmd
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).
Let denote the density for infections of age in a host cohort of age born on day .
The dynamics of are described by the following: with the boundary condition: Its solutions are given by:
The function zda
computes
The mean MoI is given by the formula:
The distribution of the MoI is Poisson (Nåsell I, 1985)2 with mean
The function meanMoI
computes
using zda
The true prevalence is the
The function truePR
computes the true prevalence using meanMoI
The density function for the age of infection (AoI) is and its moments are
The age of the youngest infection (AoY) is defined as:
The density function can be expressed in terms of the density and distribution functions of the AoI and MoI.
The distribution function for the AoY is:
Its moments are:
We also developed functions to compute the age of the youngest of infections, called YoN
The distribution function for YoN, , is 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:
The following is a summary table of functions to compute the MoI, AoI, AoY, YoN, and all their moments.
MoI | AoI | AoY | YoN | |
---|---|---|---|---|
|
||||
|
||||
Random Variable | ||||
Density Function | ||||
|
dpois | dAoI | dAoY | dYoN |
Distribution Function | ||||
|
ppois | pAoI | pAoY | pYoN |
Random Numbers | ||||
|
rpois | rAoI | rAoY | rYoN |
Moments | ||||
|
meanMoI | momentAoI | momentAoY |
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.
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,
,
and the cohort birthday,
alpha = 60
a = 6*365
zda(60, 6*365, foiP3)
## [1] 0.001601196
The following computes the density of infections of every age in a cohort of age 3.
When we plot , we note that as 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 ():
We define a random variable describing the multiplicity of infection (MoI). The distribution of the MoI is Poisson (see the MoI vignette).
Since describes the density of all infections of age in a cohort of age , the density of all infections must be the MoI. Since , it must be true that:
The function that computes
is called meanMoI.
mm = meanMoI(a3years, foiP3, hhat=5/365)
Here, we plot the average MoI in the host cohort as it ages:
We define a random variable that describes the age of infection (AoI), which is given by the formula
dAoI
We can compute
using the density function dAoI
:
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:
pAoI
The distribution function for is:
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, tau)), lwd=3)
lines(a3years, F_A_alt, col = "red", lwd=2, lty =2)
rAoI
The function rAoI
uses pAoI
to generate
random numbers from
rhx = rAoI(10000, 3*365, foiP3)
A simple visual check computes the empirical CDF for the random
variates against
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.
Let denote the first moment of of :
Similarly, we let denote the higher order moments of :
moment1 = momentAoI(a3years, foiP3)
moment2 = momentAoI(a3years, foiP3, n=2)
moment3 = momentAoI(a3years, foiP3, n=3)
The first three moments of the AoY plotted over time. In the top plot, we’ve also plotted the root of the moment.
We have derived a random variable describing the age of the youngest infection (AoY). The density function for the AoY is:
The distribution function is:
The derivations are found in a Suppplement to Henry JM, et al. (2024).
The mean AoY is:
And the higher order moments for the AoY are:
dAoY
The density function is computed with the function
dAoY.
f_Y = dAoY(a3years, 3*365, foiP3)
We can compare (in black) to (in grey).
rAoY
raoy = rAoY(10^5, 3*365, foiP3)
aa = seq(5, 3*365, by = 5)
moment1y = momentAoY(aa, foiP3)
moment2y = momentAoY(aa, foiP3, n=2)
moment3y = momentAoY(aa, foiP3, n=3)
The first three moments of the AoY plotted over time. In the top plot, we’ve also plotted the root of the moment.
Next:
Henry JM, Carter AR, Wu SL, Smith DL (in preparation). A Probabilistic Synthesis of Malaria Epidemiology: Exposure, Infection, Parasite Densities, and Detection.↩︎
Nåsell I (1985). Hybrid Models of Tropical Infections, 1st edition. Springer-Verlag. https://doi.org/10.1007/978-3-662-01609-1↩︎