Age stratification

Summer provides a special age stratification class (AgeStratification) that automatically adds ageing flows to the model. See the linked documentation for more details on the flows.

AgeStratification is used similarly to the more general-purpose Stratification class, except it makes some assumptions of the meaning of the strata in order to implement ageing flows.

Important caveat: The AgeStratification assumes that your time unit is years.

Let’s start by creating a vanilla SIR model. You can see that there are no flows by default:

[1]
from summer2 import CompartmentalModel, AgeStratification
import pandas as pd
pd.options.plotting.backend = "plotly"

model = CompartmentalModel(
    times=[1990, 2010],
    compartments=["S", "I", "R"],
    infectious_compartments=["I"],
)
model.set_initial_population(distribution={"S": 900, "I": 100, "R": 10})

model.flows
[1]:
[]

Next, lets add an age stratification with the following age strata:

  • 0: 0-19 year olds

  • 20: 20-39 year olds

  • 40: 40-59 year olds

  • 60: ages 60+

Now you can see that 9 ageing flows have been added:

[2]
strata = [0, 20, 40, 60]
strat = AgeStratification(name="age", strata=strata, compartments=['S', 'I', 'R'])
strat.set_population_split({'0': 0.4, '20': 0.3, '40': 0.2, '60': 0.1})
model.stratify_with(strat)
model.flows
[2]:
[<TransitionFlow 'ageing_SXage_0_to_SXage_20' from SXage_0 to SXage_20>,
 <TransitionFlow 'ageing_IXage_0_to_IXage_20' from IXage_0 to IXage_20>,
 <TransitionFlow 'ageing_RXage_0_to_RXage_20' from RXage_0 to RXage_20>,
 <TransitionFlow 'ageing_SXage_20_to_SXage_40' from SXage_20 to SXage_40>,
 <TransitionFlow 'ageing_IXage_20_to_IXage_40' from IXage_20 to IXage_40>,
 <TransitionFlow 'ageing_RXage_20_to_RXage_40' from RXage_20 to RXage_40>,
 <TransitionFlow 'ageing_SXage_40_to_SXage_60' from SXage_40 to SXage_60>,
 <TransitionFlow 'ageing_IXage_40_to_IXage_60' from IXage_40 to IXage_60>,
 <TransitionFlow 'ageing_RXage_40_to_RXage_60' from RXage_40 to RXage_60>]

The rate of ageing is the reciprocal of the width of the age bracket: that is - people in the 0-19 age bracket will leave the bracket at a rate of 5% per year. People in the oldest age bracket will not leave their age bracket through an ageing process (although other flows may cause them to leave the model or transition between compartments within their bracket).

Let’s visualize the results.

[3]
model.run()
outputs = model.get_outputs_df()
outputs.plot()

As you can see above, these ageing flows add new dynamics to the model. They are easier to visualise if we consider the age strata for a single compartment type:

[4]
outputs[model.query_compartments({"name": "S"})].plot()

Summary

Now you know how to use an AgeStratification to automatically generate ageing flows. See the API reference for more details.