Skip to content

Instantly share code, notes, and snippets.

@datashaman
Last active February 8, 2020 09:35
Show Gist options
  • Save datashaman/09071e8f5652ea86963d34217a3ff6b7 to your computer and use it in GitHub Desktop.
Save datashaman/09071e8f5652ea86963d34217a3ff6b7 to your computer and use it in GitHub Desktop.
Simulate coronavirus outbreak; via https://blog.zorinaq.com/case-fatality-ratio-ncov/
#!/usr/bin/python3
import math
population = 100e3
days = 200
death_prob = 0.50
time_to_death = 21
time_to_heal = 21
hist = []
deaths = recovs = naive_cfr = resolved_cfr = 0
print('day,cases,deaths,recoveries,naive_cfr,resolved_cfr')
for d in range(0, days):
if d == 0:
cases = 0
else:
cases = round(population / (1 + math.e**(-0.08*(d - days/2))))
hist.insert(0, cases)
if len(hist) >= time_to_death + 2:
deaths += round((hist[time_to_death] - hist[time_to_death + 1]) * \
death_prob)
if len(hist) >= time_to_heal + 2:
recovs += round((hist[time_to_heal] - hist[time_to_heal + 1]) * \
(1 - death_prob))
if d > max(time_to_death, time_to_heal):
if cases:
naive_cfr = 100 * deaths / cases
if deaths + recovs:
resolved_cfr = 100 * deaths / (deaths + recovs)
print('{day},{cases},{deaths},{recovs},{naive_cfr},{resolved_cfr}'.\
format(day=d, cases=cases, deaths=deaths, recovs=recovs,
naive_cfr=naive_cfr, resolved_cfr=resolved_cfr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment