@@ -178,13 +178,12 @@ class Wasting(Module):
178178 'none' , 'not_applicable' ]),
179179 }
180180
181- wasting_states = ['WHZ<-3' , '-3<=WHZ<-2' , 'WHZ>=-2' ]
182-
183181 def __init__ (self , name = None , resourcefilepath = None ):
184182 super ().__init__ (name )
185183 self .wasting_models = None
186184 self .resourcefilepath = resourcefilepath
187-
185+ # wasting states
186+ self .wasting_states = self .PROPERTIES ["un_WHZ_category" ].categories
188187 # wasting symptom
189188 self .wasting_symptom = 'weight_loss'
190189
@@ -237,19 +236,19 @@ def initialise_population(self, population):
237236 self .wasting_models = WastingModels (self )
238237
239238 # 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
243242 # linear model external variables
244- agegp = f'{ low_bound_mnts } _{ high_bound_mnths } mo'
243+ agegp = f'{ low_bound_mos } _{ high_bound_mos } mo'
245244 mask = (df .is_alive & df .age_exact_years .between (low_bound_age_in_years , high_bound_age_in_years ,
246245 inclusive = 'left' ))
247246 prevalence_of_wasting = self .wasting_models .get_wasting_prevalence (agegp = agegp ).predict (df .loc [mask ])
248247
249248 # categorize into moderate (-3<=WHZ<-2) or severe (WHZ<-3) wasting
250249 wasted = self .rng .random_sample (len (prevalence_of_wasting )) < prevalence_of_wasting
251250 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 )
253252 wasted_category = self .rng .choice (['WHZ<-3' , '-3<=WHZ<-2' ], p = [probability_of_severe ,
254253 1 - probability_of_severe ])
255254 df .at [idx , 'un_WHZ_category' ] = wasted_category
@@ -300,12 +299,13 @@ def on_birth(self, mother_id, child_id):
300299 df .at [child_id , 'un_am_MUAC_category' ] = '>=125mm'
301300 df .at [child_id , 'un_am_treatment_type' ] = 'not_applicable'
302301
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 ]:
304303 """
305304 This function will calculate the WHZ scores by categories and return probability or odds of severe wasting
306305 for those with wasting status
307306 :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
309309 :return:
310310 """
311311 # generate random numbers from N(meean, sd)
@@ -315,7 +315,7 @@ def get_odds_probs_wasting(self, agegp: str, lm_scaling: bool = False) -> Union[
315315 # get all wasting: WHZ <-2
316316 probability_less_than_minus2sd = 1 - whz_normal_distribution .sf (- 2 )
317317
318- if lm_scaling :
318+ if get_odds :
319319 # convert probability to odds and return the odds
320320 return probability_less_than_minus2sd / (1 - probability_less_than_minus2sd )
321321
@@ -1229,9 +1229,9 @@ def make_linear_model_wasting(intercept: Union[float, int]) -> LinearModel:
12291229 self .params ['or_wasting_preterm_and_AGA' ])
12301230 )
12311231
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 )
12331233 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 )
12351235 actual_mean = unscaled_lm .predict (df .loc [df .is_alive & (df .age_years == 1 )]).mean ()
12361236 scaled_intercept = get_odds_wasting * (target_mean / actual_mean ) if \
12371237 (target_mean != 0 and actual_mean != 0 and ~ np .isnan (actual_mean )) else get_odds_wasting
0 commit comments