Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

CompartmentalModeling

Guides

  • Compartmental Modeling

Tech Notes

  • Vertical Transmission Models

Symbols

  • DynamicTransmissionModel
  • ForceOfInfection
  • Incidence
  • NextGenerationMatrix
  • CollectModel
  • CompartmentalModelGraph
  • CompetitiveInhibitorKinetics
  • DefinePropensityFunction
  • DeriveTransitions
  • DynamicTransmissionModel
  • EnzymeReaction
  • EpidemiologyModelData
  • EpidemiologyModel
  • ExpandModel
  • ForceOfInfection
  • HillKinetics
  • Incidence
  • KineticCompartmentalModel
  • KineticReactionNetworkModel
  • MichaelisMentenKinetics
  • NextGenerationMatrix
  • NoncompetitiveInhibitorKinetics
  • NullCompartment
  • ResolveCompartmentalModel
  • StochasticSolve
  • StoichiometryTable
  • StratifyModel
  • Transition
  • UncompetitiveInhibitorKinetics
  • VitalDemographicsModel
  • $C
  • $CompartmentalModelingVersion
  • $EpidemiologyColor
  • $EpidemiologyModelingVersion
  • $R
  • $SystemsBiologyModelingVersion
Vertical Transmission Models
Vertical transmission models allow individuals to enter infected compartments at recruitment (birth). This is sometimes called congenital infection. Compartmental models with vertical transmission can be implemented manually by specifying appropriate rate expressions in source transitions or automatically by specifying birth compartments to the functions
VitalDemographicsModel
or
DynamicTransitionModel
.
Vertical transmission occurs when progeny of infected individuals are recruited into the population. Typically, the vertical transmission occurs with a probability less than 1. The symbol
χ
is used here to represent the fraction of recruitment that occurs with transmission, and
1-χ
for the fraction that occurs without transmission.
A simple SIR model is used only for consistency across the examples. Other types of compartmental models can be used as needed for the problem at hand.
Load the paclet:
In[14]:=
Needs["RobertNachbar`EpidemiologyModeling`"]

Age-agnostic models

ViralDemographicsModel
can be used to add the recruitment transitions to age-agnostic models.
VitalDemographicsModel
[{
tr
1
,
tr
2
,…},{
bc
1

r
1
,
bc
2

r
2
,…}]
returns an expanded list of transitions
tr
i
with transitions for births and all-cause mortality added using the total birth rate model. The
bc
i
are individual birth compartments, and the
r
i
are rate expressions.
VitalDemographicsModel
[{
tr
1
,
tr
2
,…},{
bc
1
{{
sc
11
,
sc
12
,…},
r
1
},
bc
2
{{
sc
21
,
s
22
,…},
r
2
},…}]
returns an expanded list of transitions
tr
i
with transitions for births and all-cause mortality added using the maternal birth rate model. The
bc
i
are individual birth compartments, the
sc
ij
are source compartments, and the
r
i
are rate expressions.
Adding vital demographics to a compartmental model.
Vertical transmission involves individuals from infected compartments, so the second form of the recruitment rate model that includes source compartments needs to be used.

Compartment-specific recruitment rate method

Compartment-specific recruitment rates are used when the rate depends on the type of compartment, for example male vs female or healthy vs diseased. Contributions from infected compartments are modulated by
χ
or
1-χ
. The final recruitment rates are computed as the sum of the source compartment (
sc
ij
) sizes multiplied by the specified rate (
r
i
).
In the model below, the recruitment into the ℐ compartment represents the vertical transmission and is specified as ℐ -> {{ℐ}, χ }, and the resulting transition rate is  χ ℐ[t]. There are two different sources of recruitment into the  compartment. The first source is from the  and ℛ compartments, and is specified as  -> {{, ℛ}, } with the resulting transition rate of  (ℛ[t] + [t]). The second source is from the ℐ compartment without vertical transmission, and is specified as  -> {{ℐ}, (1 - χ) } with the resulting transition rate of  (1 - χ) ℐ[t].
Define the SIR model transitions and the compartments for compartment-specific recruitment rates:
In[104]:=
model=
VitalDemographicsModel

βλ[t]
→
ℐ,ℐ
γ
→
ℛ,{ℐ{{ℐ},χ},{{,ℛ},},{{ℐ},(1-χ)}}
Out[104]=

(1-χ)ℐ[t]
↦
,
χℐ[t]
↦
ℐ,
(ℛ[t]+[t])
↦
,ℐ
γ
→
ℛ,ℐ
μ
⇥
,ℛ
μ
⇥
,
μ
⇥
,
βλ[t]
→
ℐ
The compartmental model graph is a good visual check.
Make the compartmental model graph:
In[107]:=
CompartmentalModelGraph
model,
options

Out[107]=

Total recruitment rate method

If the total recruitment rate for the whole population is
Λ
, then the contribution from compartment
sc
j
is
Λ
sc
j
(t)
(t)
, where
(t)
is the total population size. Contributions from infected compartments are modulated by
χ
or
1-χ
. The final recruitment rates are computed as the sum of the source compartment (
sc
ij
) sizes multiplied by the specified rate (
r
i
).
In the model below, the recruitment into the ℐ compartment represents the vertical transmission and is specified as ℐ -> {{ℐ},  Λ/[t]}, and the resulting transition rate is ( Λ ℐ[t])/[t]. There are two different sources of recruitment into the  compartment. The first source is from the  and ℛ compartments, and is specified as  -> {{, ℛ}, Λ/[t]} with the resulting transition rate of Λ(ℛ[t]+[t])/[t]. The second source is from the ℐ compartment without vertical transmission, and is specified as  -> {{ℐ}, (1 - ) Λ/[t]} with the resulting transition rate of ((1 - ) Λ ℐ[t])/[t].
Define the SIR model transitions and the compartments for recruitment (births):
In[108]:=
model=
VitalDemographicsModel

βλ[t]
→
ℐ,ℐ
γ
→
ℛ,{ℐ{{ℐ},Λ/[t]},{{,ℛ},Λ/[t]},{{ℐ},(1-)Λ/[t]}}
Out[108]=

(1-)Λℐ[t]
[t]
↦
,
Λℐ[t]
[t]
↦
ℐ,
Λ(ℛ[t]+[t])
[t]
↦
,ℐ
γ
→
ℛ,ℐ
μ
⇥
,ℛ
μ
⇥
,
μ
⇥
,
βλ[t]
→
ℐ
The compartmental model graph is a good visual check.
Make the compartmental model graph:
In[111]:=
CompartmentalModelGraph
model,
options

Out[111]=
The total recruitment rate should equal Λ, and that can be checked with the following code.
Select the recruitment transitions and compute the sum of their rates:
In[24]:=
Casesmodel,
rate_
↦
_rate/.[t][t]+ℐ[t]+ℛ[t]//Total//Simplify
Out[24]=
Λ

Age-stratified models

DynamicTransitonModel
must be used for discrete age-structured models so that recruitment occurs only into the first age group.
DynamicTransmissionModel
[{
tr
1
,
tr
2
,…},t]
returns an association of model data for the input transitions in
tr
i
and time symbol
t
.
Adding vital demographics to a compartmental model along with age stratification of model transitions.
The options relevant for recruitment and age stratification are show below.
"BirthCompartments"
a list rules
{
bc
i

r
i
,…}
or
{
bc
i
{{{
sc
ij
,…},
r
i
},…}
where
bc
i
are birth compartments,
sc
ij
are source compartments, and
r
i
are rate expressions
"AgeStratification"
a list
{symb,n}
where
symb
is the symbol for the aging progression rate parameter and
n
is the number of age groups
"AgeStratifiedParameters"
a list of parameters to stratify by age along with the compartments; integers are used for the indices
Options for
DynamicTransitionModel
needed for recruitment and age stratification.

Compartment-specific recruitment rate method

Compartment-specific recruitment rates are used when the rate depends on the type of compartment, for example male vs female or healthy vs diseased. Contributions from infected compartments are modulated by
χ
or
1-χ
. The final recruitment rates are computed as the sum of the source compartment (
sc
ij
) sizes multiplied by the specified rate (
r
i
).In the model below, the recruitment rates are specified with the option "ForceOfInfection". The recruitment into the ℐ compartment represents the vertical transmission and is specified as ℐ -> {{ℐ}, χ }, and the resulting transition rate is  χ ℐ[t]. There are two different sources of recruitment into the  compartment. The first source is from the  and ℛ compartments, and is specified as  -> {{, ℛ}, } with the resulting transition rate of  (ℛ[t] + [t]). The second source is from the ℐ compartment without vertical transmission, and is specified as  -> {{ℐ}, (1 - χ) } with the resulting transition rate of  (1 - χ) ℐ[t].
The option "AgeStratification" -> {α, 3} specifies that
α
i
will be the age group transfer rate and that there are 3 age groups in the model. The option "AgeStratifiedParameters" -> {, } specifies that the age-stratified recruitment rate parameters are
$i
and
$i
.
Define the SIR model transitions and the compartments for compartment- and age-specific recruitment rates:
In[100]:=
modelData=
DynamicTransmissionModel

βλ[t]
→
ℐ,ℐ
γ
→
ℛ,t,​​"ForceOfInfection"{λ,{ℐ}},​​"BirthCompartments"{ℐ{{ℐ},χ},{{,ℛ},},{{ℐ},(1-χ)}},​​"AgeStratification"{α,3},​​"AgeStratifiedParameters"{,};
The compartmental model graph is a good visual check.
Make the compartmental model graph:
In[94]:=
CompartmentalModelGraph
Simplify/@modelData["ComponentTransitions"],
options
//
wrap edge labels
Out[94]=

Total recruitment rate method

In the model below, the recruitment rates are specified with the option "ForceOfInfection". The recruitment into the ℐ compartment represents the vertical transmission and is specified as ℐ -> {{ℐ},  Λ/[t]}, and the resulting transition rate is ( Λ ℐ[t])/[t]. There are two different sources of recruitment into the  compartment. The first source is from the  and ℛ compartments, and is specified as  -> {{, ℛ}, Λ/[t]} with the resulting transition rate of Λ(ℛ[t]+[t])/[t]. The second source is from the ℐ compartment without vertical transmission, and is specified as  -> {{ℐ}, (1 - ) Λ/[t]} with the resulting transition rate of ((1 - ) Λ ℐ[t])/[t].
Define the SIR model transitions and the compartments for recruitment (births):
The compartmental model graph is a good visual check.
Make the compartmental model graph:
The total recruitment rate should equal Λ, and that can be checked with the following code.
Select the recruitment transitions and compute the sum of their rates:

© 2025 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com