# How Epidemics Spread 2, Exercise 2: generations to reach a size, and how uncertain R0 changes the answer import math # Part A: generations needed for one case to lead to 1000 cases in a single # generation, and the days that takes if a generation lasts 5 days (assumed). T = 5 print(" R0 generations days") for r0 in [1.2, 1.5, 2.0, 2.5, 3.0]: generations = math.log(1000) / math.log(r0) print(f"{r0:5.1f} {generations:10.1f} {generations * T:5.0f}") # Part B: how much does the uncertainty in R0 matter? Measles is often quoted # at 12 to 18 and seasonal influenza near 1.3 (Wikipedia, as fetched). for name, r0 in [("measles low", 12), ("measles high", 18), ("influenza", 1.3)]: print(f"{name:13s} R0 {r0:4}: cases in generation 3 = {r0 ** 3:,.0f}") # Output when run: # R0 generations days # 1.2 37.9 189 # 1.5 17.0 85 # 2.0 10.0 50 # 2.5 7.5 38 # 3.0 6.3 31 # measles low R0 12: cases in generation 3 = 1,728 # measles high R0 18: cases in generation 3 = 5,832 # influenza R0 1.3: cases in generation 3 = 2