The functions in this package analyze compartmental differential equation models, where the compartments are states of individuals who are co-located in a healthcare facility, for example, patients in a hospital or patients/residents of long-term care facility.
Our example here is a hospital model with four compartments: two compartments and representing patients who are colonized with an infectious organism, and two compartments and representing patients who are susceptible to acquiring colonization with that same organism. The two colonized and susceptible states are distinguished by having potentially different infectivity to other patients and vulnerability to acquisition from other patients, respectively.
A system of differential equations with those 4 compartments may take the following general form:
The acquisition rate appearing in each equation, and governing the transition rates between the S compartments and the C compartments, is assumed to depend on the number of colonized patients in the facility, as follows:
We will demonstrate how to calculate the basic reproduction number
of this system using the facilityR0
function. The following
components of the system are required as inputs to the function call
below.
S
matrix; pre-invasion susceptible state
transitions
A matrix S
governing the transitions between, and out
of, the states
and
in the absence of any colonized patients “invading” the facility (i.e.,
all state transitions except for acquiring colonization):
The rates can be used to model transitions between different patient states that might alter susceptibility to acquiring the modeled organism, for example risky treatment procedures, drug exposures, or protective measures. The rates model removal from the facility via discharge or death.
C
matrix; colonized state transitions
Next, we require a matrix C
governing the transitions
between, and out of, the states
and
:
c21 <- 0.1; c12 <- 0
r11 <- r22 <- 0.1; r12 <- r21 <- 0
omega3 <- omega4 <- 0.1
C <- rbind(c(-c21-r11-r21-omega3, c12), c(c21, -c12-r12-r22-omega4))
The rates can be used to model transitions between different colonized patient states that might be observable in data and/or alter the patient’s infectivity to other patients, for example clinical infection, detection status, or placement under protective measures. The rates govern clearance of colonization (thus, transitions back to one of the susceptible states), while the rates model removal from the facility via discharge or death.
A
matrix; susceptible-to-colonized state
transitions and relative susceptibility
The next input requirement is a matrix A
describing the
S-to-C state transitions when an acquisition occurs:
The rates describe which of the two colonized states can be entered from each of the two susceptible states at the moment of acquiring colonization; in the above example, state patients move only to state and state patients move only to state . The values also describe the susceptibility of the two states; in the above example, state patients are twice as susceptible as state patients.
transm
vector: transmission rates
The next required input is a vector transm
containing
the
coefficients (transmission rates from each colonized compartment)
appearing in the
equation above:
beta1 <- 0.2; beta2 <- 0.3
transm <- c(beta1, beta2)
The values describe the transmissibility of each colonized state; in this example, state patients are 50% more transmissible than state patients. When the levels of colonization in the facility are and , the acquisition rate of an patient is
initS
vector: susceptible state admission
distribution
A vector initS
containing the admission state
probabilities for the susceptible compartments only (i.e., the
pre-invasion system before a colonized patient is introduced):
theta1 <- 0.9; theta2 <- 1 - theta1
initS <- c(theta1, theta2)
The initS
vector should sum to 1.
facilityR0
function call with
The time-of-stay-dependent removal rate is the remaining component in the master equations above. When , the above components are sufficient to calculate the facility as in the following example:
facilityR0(S,C,A,transm,initS)
#> [1] 1.763978
Note that when , the removal rates (discharge and death) are entirely governed by the values, which must be set such that patients in any state must be guaranteed to eventually reach a state for which ; otherwise, patients can have an infinitely long length of stay in the facility.
mgf
function: moment generating function associated
with
When the time-of-stay-dependent removal rate
,
there is one additional argument required as input to the
facilityR0
function: a function mgf(x,deriv)
that is the moment-generating function (and its derivatives) of the
distribution for which
is the hazard function. This is the length of stay distribution when the
state-dependent removal rates
are all zero, as in the following example.
omega1 <- omega2 <- omega3 <- omega4 <- 0
S <- rbind(c(-s21-omega1, s12), c(s21, -s12-omega2))
C <- rbind(c(-c21-r11-r21-omega3, c12), c(c21, -c12-r12-r22-omega4))
The length of stay distribution can be any statistical distribution
with non-negative range, as long as the moment generating function (mgf)
and its derivatives can be evaluated, as this calculation is required
within the
formula. We currently provide three mgf functions in this package: one
for the exponential distribution, MGFexponential
, one for
the gamma distribution MGFgamma
, and one for a mixed gamma
distribution MGFmixedgamma
; the latter distribution can
employ a weighted mixture of any number of different gamma
distributions.
The mgf(x, deriv)
function to be passed to
facilityR0()
must be defined as in the following example,
which uses a gamma distribution.
mgf <- function(x, deriv=0) MGFgamma(x, rate=0.1, shape=3.1, deriv)
facilityR0
function call with
The call to facilityR0()
is the same as above with the
additional argument mgf
(which defaulted to
NULL
when not provided):
facilityR0(S,C,A,transm,initS,mgf)
#> [1] 2.570984
We will demonstrate how to calculate the equilibrium of the full
system of equations, with a given set of initial conditions,
i.e. distribution of patient states at admission, using the
facilityeq
function. The following components of the system
are required as inputs to the function call below.
The matrix S
, the matrix C
, the matrix
A
, the vector transm
, and the (optional)
function mgf
are the same as those required by the
facilityR0
function as described above. The following are
new components:
init
vector: admission state distribution
A vector init
containing the admission state
probabilities for all four compartments:
pa <- 0.05; kappa1 <- 1; kappa2 <- 1-kappa1
init <- c((1-pa)*theta1, (1-pa)*theta2, pa*kappa1, pa*kappa2)
Here we have modeled an importation probability (probability of an admitted patient being colonized at admission) of 5%, and assumed that all admitted colonized patients are in state .
The init
vector should sum to 1.
facilityeq
function call with
We can now calculate the equilibrium of the facility model:
facilityeq(S, C, A, R, transm, init, mgf)
#> [1] 0.14469390 0.07783363 0.20457665 0.57289581
The result is the portion of patients in the facility who are in each of the state , , , and , respectively, at equilibrium.