How to calculate R₀ from an infection diagram
On this page
R0Calc is a free web calculator that computes the basic reproduction number R₀ of a compartmental epidemic model as a symbolic formula. You draw the model as an infection diagram, write each rate in LaTeX (β, σ, μ + γ…), and R0Calc returns R₀ in LaTeX together with the infection cycles that produce each term. You do not need to write equations or build matrices. If your model is written as a system of differential equations, the section on building the diagram from your equations shows how to translate each term into an arrow.
What is the basic reproduction number R₀?
The basic reproduction number R₀ (read "R nought", often written R0) is the average number of new infections that one infectious individual causes in a population where everyone is susceptible. It is the threshold of an epidemic model: if R₀ > 1 an infection can invade and spread, and if R₀ < 1 it dies out. For compartmental models R₀ is a formula in the model's parameters, such as β / γ in the simplest SIR model, so it shows which rates control the outbreak. In the SIR model, for example, a fraction 1 − 1/R₀ of the population must be immune to stop transmission. The standard way to obtain R₀ is the next-generation matrix (Diekmann, Heesterbeek and Metz, 1990; van den Driessche and Watmough, 2002), which requires separating new infections from other transitions and inverting a matrix by hand or with a computer algebra system.
What is an infection diagram?
An infection diagram is a graph that keeps only the part of an epidemic model that describes the infection itself: the infected compartments and the processes that bring individuals into that set, move them inside it, and take them out of it. Susceptible, vaccinated, immune or recovered compartments are not drawn, even though they appear in the transmission terms. The diagram is not a free sketch of the model: once the model is fixed, its diagram is fully determined by the equations of the infected compartments, so two people drawing it from the same model get the same graph.
Because it ignores demography and everything that happens outside the infected set, two models that differ in births, loss of immunity or vaccination schedules can share the same infection diagram. That makes the diagram a way to compare models by the structure of their transmission, not by their algebra.
Infected is not the same as infectious
A compartment belongs to the diagram if it is a stage an infected individual passes
through, whether or not it transmits. An exposed class E that does not transmit yet is an
infected compartment; it is drawn as a non-infectious node (blue).
Compartments that generate new infections are infectious nodes (red). A
variable that is not a group of people can also be an infected compartment when it takes
part directly in transmission, for example free bacteria or virus in the environment.
What decides is the role of the variable in the infection dynamics, not its name or
biology. In the YAML, non-infectious infected compartments go under
non_infectious_infested and infectious ones under
infectious_infested.
The three kinds of arrows
- New-infection arrows (dashed). They represent individuals entering the infected set. The arrow goes from the compartment whose presence causes the infection to the compartment where the new infected individuals appear. It is not a movement of people: in an SEIR model the dashed arrow from I to E does not mean that infectious individuals become exposed; the new individuals in E come from S, and I is only the cause. The label is the transmission rate multiplied by the value of the uninfected compartment involved at the disease-free equilibrium (DFE), for example β S*/N. When S* = N, as in the basic SEIR model, this is simply β. If infected individuals can enter from outside the system (infected births, immigration), the arrow has no source node. When a compartment receives new infections by different routes, each route is a separate arrow.
- Transfer arrows (solid, between two nodes). Individuals that are already infected moving from one infected compartment to another: progression from E to I, a change of clinical state, a change of behaviour, a mutation of the pathogen. The label is the rate of that flow, for example σ. They do not change the total number of infected individuals; they only redistribute it.
- Outflow arrows (solid, no destination). Individuals leaving the infected set by recovery, death, treatment or any move to an uninfected compartment. Where they go is not drawn, because for the infection dynamics the effect is the same: they stop being infected. The label is the exit rate, for example γ or μ + α. Several outflows from the same compartment can be drawn separately or as one arrow with the sum of the rates.
Rates are written in LaTeX and can be any expression, such as \beta,
\mu + \gamma or p \sigma. Two parallel arrows between the same
compartments are added together.
How to build an infection diagram from a system of differential equations
Write the equation of each infected compartment xi as the sum of three kinds of terms:
LaTeX: \frac{dx_i}{dt} = \mathcal{F}_i + \mathcal{T}_i + \mathcal{O}_i
where ℱi collects the new infections, 𝒯i the transfers between infected compartments and 𝒪i the outflows from the infected set. Each group becomes one kind of arrow. Only the equations of the infected compartments are read; the equations of S, V, R and other uninfected compartments are used only to find their values at the disease-free equilibrium. If you know the next-generation matrix method, ℱ is what it calls F, and transfers and outflows together are what it calls V.
Read the meaning of each term, not only its sign
A positive term is not always a new infection: it can be a transfer arriving from another infected compartment. A negative term is not always an outflow: it can be a transfer leaving towards another infected compartment. Ask what process the term models. A transfer always appears twice, with a minus sign in the equation of the origin and a plus sign in the equation of the destination (−σE in dE/dt and +σE in dI/dt); the diagram joins the pair into a single arrow.
Four steps
- Choose the infected compartments. They are the nodes. Decide by role in the infection, not by name: an exposed class is in, a recovered class is out, a free pathogen can be in. Mark as infectious the ones that cause new infections.
- Draw the new infections. For every term that adds individuals to the infected set, draw a dashed arrow from the compartment that causes it to the compartment that receives them. Label it with the transmission parameter times the DFE value of the uninfected compartment in the term (β I S/N → β S*/N). External entries are arrows without a source.
- Draw the transfers. For every flow between two infected compartments, draw a solid arrow from origin to destination with its rate. If there are none, draw none: that also tells you something, namely that infected compartments are linked only through infection.
- Draw the outflows. For every term that removes individuals from the infected set, draw a solid arrow leaving the compartment, with its rate and no destination.
The same four steps work for a two-compartment model and for a model with many infected compartments; what changes is the diagram the model produces, not the rules. For a term-by-term walk-through, see the SEIR equations translated into their diagram.
How does R0Calc compute R₀?
R0Calc finds every infection cycle in the diagram: a closed path that leaves an infectious compartment, passes through new-infection and transfer arrows and returns to it. Each cycle is one route of transmission. Along a cycle, each compartment contributes the rate that brings individuals in divided by the total rate at which they leave (its transfers plus its outflows). The product of these ratios is the cycle's term; when a cycle passes through several infectious compartments, R0Calc takes the geometric mean per compartment, that is, the k-th root for k compartments. Cycles that share infectious compartments are combined into one value, and when the diagram has independent groups of cycles, R₀ is the largest of them. The View cycles page of the calculator shows each cycle, its term and how they combine into R₀, which helps explain the result in a thesis or a paper.
Step by step: R₀ of the SEIR model
- Open the calculator. From Add to diagram, add a Non-infectious compartment named
Eand an Infectious compartment namedI. - Add a New infection arrow: select I, then E, and label it
\beta(β S*/N with S* = N; see how arrows are labelled). - Add a Transfer arrow from E to I labelled
\sigma. - Add an Outflow arrow from E labelled
\muand another from I labelled\mu + \gamma. - Choose Update YAML, the → button between the diagram and the YAML (or Ctrl+S). R₀ = βσ / ((σ + μ)(γ + μ)) appears under the diagram; Copy LaTeX copies it.
The same model is available in one click with Load this example in the YAML panel. The SEIR model page explains every term of the formula.
More examples: what the infection diagram shows
The same four steps apply to models with several groups, several transmission routes or a pathogen that lives outside its hosts. Two examples, each with its own page:
Two groups and imperfect vaccination
In an SIS model of a sexually transmitted infection with women and men and an imperfect vaccine (Saldaña et al., 2023), the infected compartments are only If and Im. Both susceptible and vaccinated people can be infected, so there are two dashed arrows in each direction, one per route, and no transfers.
What it shows: vaccination adds an entry route and lowers its rate, but it does not add any infected compartment or change the cycle If → Im → If. The diagram separates changes in the intensity of transmission from changes in its structure. Its R₀ is √(βfm βmf Af Am / ((αf + df)(αm + dm))), where Ak is the fraction of group k that vaccination leaves effectively susceptible.
A pathogen in the environment
In a model of leptospirosis in humans and animals (Baca-Carrasco, Olmos and Barradas, 2015), the infected compartments are infected animals IA, infected humans IH and free bacteria in the environment B. B is not a population, but it causes new infections directly, so it is a node. Bacterial shedding by animals and humans is drawn as new-infection arrows into B.
What it shows: several transmission routes at once (animal to animal, animal to human, through the environment) and a node that is not a population, all with the same four steps. Here R₀ is the largest root of a cubic equation built from the four infection cycles of the diagram.
Common mistakes when drawing an infection diagram
Most wrong R₀ formulas come from a diagram that mixes up what an arrow means. Check yours against this list:
- Reading a dashed arrow as people moving. The arrow from I to E says that I causes new cases in E; the new cases come from S.
- Drawing S, V or R as nodes. Uninfected compartments only enter through their DFE values in the labels.
- Leaving out the exposed class. E does not transmit, but it is infected, so it is a node (non-infectious).
- Classifying terms by sign alone. A positive term can be a transfer and a negative term can be a transfer; check which process the term models.
- Labelling with β instead of β S*/N. They coincide only when S* = N. With vaccination or several groups, the DFE values matter.
- Merging different infection routes. Infection from S and from V are two arrows (R0Calc adds parallel arrows, so the result is the same, but the diagram stays readable).
- Drawing waning immunity or births. They act outside the infected set and are not part of the infection diagram.
Writing a model in YAML
Every diagram has an equivalent YAML description, shown next to the canvas. You can edit
it, paste a model, open a .yaml file or download the current one. The keys are:
| Key | Content |
|---|---|
non_infectious_infested | Names of the non-infectious infected compartments (E…) |
infectious_infested | Names of the infectious compartments (I…) |
new_infections_arrows | List of from, to, param |
transfer_arrows | List of from, to, param |
outs_arrows | List of from, param |
Empty lists can be written as [].
non_infectious_infested:
- E
infectious_infested:
- I
new_infections_arrows:
- from: I
to: E
param: \beta
transfer_arrows:
- from: E
to: I
param: \sigma
outs_arrows:
- from: E
param: \mu
- from: I
param: \mu + \gamma
R0Calc compared with other ways to get R₀
Unlike next-generation matrix calculators, which ask you to type the matrices F and V and usually return a number, R0Calc starts from a drawing of the model and returns R₀ as a symbolic formula. Unlike tools that estimate R₀ from case counts, it works from the model structure, before any data exists.
| R0Calc | Next-generation matrix by hand or with a CAS | Estimation from case data | |
|---|---|---|---|
| Input | Infection diagram or YAML | Matrices F and V | Daily or weekly case counts |
| Output | Symbolic formula in LaTeX | Formula or number | A number with uncertainty |
| Shows each transmission route | Yes, one term per infection cycle | No | No |
| Needs programming | No, runs in the browser | Algebra, or Maple, Mathematica, SymPy or R | Usually R or Python |
| Best for | Designing and teaching models, writing up derivations | Formal proofs | Describing a real outbreak |
Frequently asked questions
Is R0Calc free?
Yes. R0Calc is free and runs in the browser. You can use it without an account; signing up lets you keep named diagrams under My diagrams and share them by link.
Does R0Calc estimate R₀ from case data?
No. R0Calc derives R₀ as a formula from the structure of a compartmental model. Estimating a number from an epidemic curve needs a statistical method, such as the exponential growth rate with a generation-interval distribution (Wallinga and Lipsitch, 2007).
Does R0Calc give the same R₀ as the next-generation matrix?
For standard models such as SIR and SEIR it returns the same expressions as the next-generation matrix method, βσ / ((σ + μ)(γ + μ)) for SEIR for example, without you writing the matrices F and V.
Can I export the R₀ formula?
Yes. Copy LaTeX copies R₀ ready to paste into a paper or a LaTeX document, and the model itself can be downloaded and opened again as a YAML file.
How large can a model be?
Any number of compartments can be drawn, but the number of infection cycles grows very fast in densely connected models. Each calculation is stopped after 15 seconds; models with several infectious compartments that are all connected to each other can reach that limit.
Is an infection diagram the same as a compartmental flow diagram?
No. A flow diagram shows every compartment and every flow of the model. An infection diagram keeps only the infected compartments, and it separates new infections (dashed arrows) from transfers and outflows (solid arrows), which a flow diagram does not.
Why are susceptible and recovered compartments not in the diagram?
R₀ depends only on what happens inside the infected set near the disease-free equilibrium. Uninfected compartments enter only through their equilibrium values, which appear in the labels of the new-infection arrows (for example S*/N).
Can a pathogen in the environment be a node?
Yes. If a variable such as free bacteria or virus causes new infections directly, it is an infected compartment and is drawn as a node, even though it is not a population of hosts. See the leptospirosis model.
How do I label a new-infection arrow?
Multiply the transmission parameter by the disease-free equilibrium value of the uninfected compartment in that term: β I S/N becomes β S*/N, which is β when S* = N.
References
- Diekmann O., Heesterbeek J. A. P., Metz J. A. J. (1990). On the definition and the computation of the basic reproduction ratio R₀ in models for infectious diseases in heterogeneous populations. Journal of Mathematical Biology, 28, 365–382.
- van den Driessche P., Watmough J. (2002). Reproduction numbers and sub-threshold endemic equilibria for compartmental models of disease transmission. Mathematical Biosciences, 180, 29–48.
- Wallinga J., Lipsitch M. (2007). How generation intervals shape the relationship between growth rates and reproductive numbers. Proceedings of the Royal Society B, 274, 599–604.
- Anderson R. M., May R. M. (1991). Infectious Diseases of Humans: Dynamics and Control. Oxford University Press.
- Saldaña F., Steindorf V., Srivastav A. K., Stollenwerk N., Aguiar M. (2023). Optimal vaccine allocation for the control of sexually transmitted infections. Journal of Mathematical Biology, 86, 75. doi:10.1007/s00285-023-01910-y
- Baca-Carrasco D., Olmos D., Barradas I. (2015). A mathematical model for human and animal leptospirosis. Journal of Biological Systems, 23(Suppl. 1), S55–S65. doi:10.1142/S0218339015400057