@@ -178,13 +178,12 @@ class Wasting(Module):
178
178
'none' , 'not_applicable' ]),
179
179
}
180
180
181
- wasting_states = ['WHZ<-3' , '-3<=WHZ<-2' , 'WHZ>=-2' ]
182
-
183
181
def __init__ (self , name = None , resourcefilepath = None ):
184
182
super ().__init__ (name )
185
183
self .wasting_models = None
186
184
self .resourcefilepath = resourcefilepath
187
-
185
+ # wasting states
186
+ self .wasting_states = self .PROPERTIES ["un_WHZ_category" ].categories
188
187
# wasting symptom
189
188
self .wasting_symptom = 'weight_loss'
190
189
@@ -237,19 +236,19 @@ def initialise_population(self, population):
237
236
self .wasting_models = WastingModels (self )
238
237
239
238
# Assign wasting categories in young children at initiation
240
- for low_bound_mnts , high_bound_mnths in [(0 , 5 ), (6 , 11 ), (12 , 23 ), (24 , 35 ), (36 , 47 ), (48 , 59 )]: # in months
241
- low_bound_age_in_years = low_bound_mnts / 12.0
242
- high_bound_age_in_years = (1 + high_bound_mnths ) / 12.0
239
+ for low_bound_mos , high_bound_mos in [(0 , 5 ), (6 , 11 ), (12 , 23 ), (24 , 35 ), (36 , 47 ), (48 , 59 )]: # in months
240
+ low_bound_age_in_years = low_bound_mos / 12.0
241
+ high_bound_age_in_years = (1 + high_bound_mos ) / 12.0
243
242
# linear model external variables
244
- agegp = f'{ low_bound_mnts } _{ high_bound_mnths } mo'
243
+ agegp = f'{ low_bound_mos } _{ high_bound_mos } mo'
245
244
mask = (df .is_alive & df .age_exact_years .between (low_bound_age_in_years , high_bound_age_in_years ,
246
245
inclusive = 'left' ))
247
246
prevalence_of_wasting = self .wasting_models .get_wasting_prevalence (agegp = agegp ).predict (df .loc [mask ])
248
247
249
248
# categorize into moderate (-3<=WHZ<-2) or severe (WHZ<-3) wasting
250
249
wasted = self .rng .random_sample (len (prevalence_of_wasting )) < prevalence_of_wasting
251
250
for idx in prevalence_of_wasting .index [wasted ]:
252
- probability_of_severe = self .get_odds_probs_wasting (agegp = agegp )
251
+ probability_of_severe = self .get_probs_or_odds_wasting (agegp = agegp )
253
252
wasted_category = self .rng .choice (['WHZ<-3' , '-3<=WHZ<-2' ], p = [probability_of_severe ,
254
253
1 - probability_of_severe ])
255
254
df .at [idx , 'un_WHZ_category' ] = wasted_category
@@ -300,12 +299,13 @@ def on_birth(self, mother_id, child_id):
300
299
df .at [child_id , 'un_am_MUAC_category' ] = '>=125mm'
301
300
df .at [child_id , 'un_am_treatment_type' ] = 'not_applicable'
302
301
303
- def get_odds_probs_wasting (self , agegp : str , lm_scaling : bool = False ) -> Union [float , int ]:
302
+ def get_probs_or_odds_wasting (self , agegp : str , get_odds : bool = False ) -> Union [float , int ]:
304
303
"""
305
304
This function will calculate the WHZ scores by categories and return probability or odds of severe wasting
306
305
for those with wasting status
307
306
:param agegp: age grouped in months
308
- :param lm_scaling: whether this function is used for scaling wasting prevalence linear model or not
307
+ :param get_odds: when set to True, this argument will cause this method return the odds of severe wasting to be
308
+ used for scaling wasting prevalence linear model
309
309
:return:
310
310
"""
311
311
# generate random numbers from N(meean, sd)
@@ -315,7 +315,7 @@ def get_odds_probs_wasting(self, agegp: str, lm_scaling: bool = False) -> Union[
315
315
# get all wasting: WHZ <-2
316
316
probability_less_than_minus2sd = 1 - whz_normal_distribution .sf (- 2 )
317
317
318
- if lm_scaling :
318
+ if get_odds :
319
319
# convert probability to odds and return the odds
320
320
return probability_less_than_minus2sd / (1 - probability_less_than_minus2sd )
321
321
@@ -1229,9 +1229,9 @@ def make_linear_model_wasting(intercept: Union[float, int]) -> LinearModel:
1229
1229
self .params ['or_wasting_preterm_and_AGA' ])
1230
1230
)
1231
1231
1232
- get_odds_wasting = self .module .get_odds_probs_wasting (agegp = agegp , lm_scaling = True )
1232
+ get_odds_wasting = self .module .get_probs_or_odds_wasting (agegp = agegp , get_odds = True )
1233
1233
unscaled_lm = make_linear_model_wasting (intercept = get_odds_wasting )
1234
- target_mean = self .module .get_odds_probs_wasting (agegp = '12_23mo' , lm_scaling = True )
1234
+ target_mean = self .module .get_probs_or_odds_wasting (agegp = '12_23mo' , get_odds = True )
1235
1235
actual_mean = unscaled_lm .predict (df .loc [df .is_alive & (df .age_years == 1 )]).mean ()
1236
1236
scaled_intercept = get_odds_wasting * (target_mean / actual_mean ) if \
1237
1237
(target_mean != 0 and actual_mean != 0 and ~ np .isnan (actual_mean )) else get_odds_wasting
0 commit comments