done parameters
@@ -60,7 +60,7 @@ def make_pars():
return pars
-def get_age_sex(min_age=0, max_age=99, age_mean=40, age_std=15, use_data=True):
+def get_age_sex(min_age=0, max_age=99, age_mean=40, age_std=15, cfr_by_age=True, use_data=True):
'''
Define age-sex distributions.
'''
@@ -74,7 +74,34 @@ def get_age_sex(min_age=0, max_age=99, age_mean=40, age_std=15, use_data=True):
sex = pl.randint(2) # Define female (0) or male (1) -- evenly distributed
age = pl.normal(age_mean, age_std) # Define age distribution for the crew and guests
age = pl.median([min_age, age, max_age]) # Normalize
- return age, sex
+
+ # Get case fatality rate for a person of this age
+ age_for_cfr = age if cfr_by_age else None # Whether or not to use age-specific values
+ cfr = get_cfr(age=age_for_cfr)
+
+ return age, sex, cfr
+
+
+def get_cfr(age=None, default_cfr=0.02, cfrdict=None):
+ '''
+ Get age-dependent case-fatality rates
+ '''
+ # Check inputs and assign default CFR if age not supplied
+ if age is None:
+ #print(f'No age given, using default case fatality rate of {default_cfr}...')
+ cfr = default_cfr
+
+ else:
+ # Define age-dependent case fatality rates if not given
+ if cfrdict is None:
+ cfrdict = {'cutoffs': [9, 19, 29, 39, 49, 59, 69, 79, 120], # Absolute maximum upper age limit
+ 'values': [0.0001, 0.0002, 0.0009, 0.0018, 0.004, 0.013, 0.046, 0.098, 0.18]} # Table 1 of https://www.medrxiv.org/content/10.1101/2020.03.04.20031104v1.full.pdf
+
+ # Figure out which CFR applies to a person of the specified age
+ cfrind = next((ind for ind, val in enumerate([True if age<cutoff else False for cutoff in cfrdict['cutoffs']]) if val))
+ cfr = cfrdict['values'][cfrind]
+
+ return cfr
def load_data(filename=None):
