Skip to content

Commit

Permalink
Treatment of SAM extension only covers some MAM children
Browse files Browse the repository at this point in the history
  • Loading branch information
nickidge committed Jun 30, 2023
1 parent b2879cb commit 5e8649f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

### Changelog

#### [2.0.10]
- If treatment of SAM is expanded to treatment of MAM, the MAM component only covers former SAM children


#### [2.0.9]
- If treatment of SAM is expended to treatment of MAM, the MAM component only covers former SAM children
- Reduce threshold for filtering programs in complex objective function optimizations


Expand Down
25 changes: 17 additions & 8 deletions nutrition/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ def _track(self):
@translate
def _set_pop_probs(self, year):
init_cov = self.prog_info.get_ann_covs(year - 1)
# Treatment of SAM must be relative to initial year to avoid MAM extension issues. Other coverages are updated iteratively
#init_cov[_("Treatment of SAM")] = self.prog_info.get_ann_covs(0)[_("Treatment of SAM")]
prog_areas = self.prog_info.prog_areas
for pop in self.pops:
pop.previousCov = init_cov
Expand Down Expand Up @@ -376,12 +374,23 @@ def _update_dists(self, population):

@translate
def _wasting_trans(self, age_group):
"""Calculates the transitions between MAM and SAM categories
Currently only accounting for the movement from sam to mam, because the other direction is complicated"""
numsam = age_group.num_risk(_("SAM"))
nummam = age_group.num_risk(_("MAM"))
# If the denominator is 0.0 or close, set update to 1 (no change).
age_group.fromSAMtoMAMupdate[_("MAM")] = 1 + sc.safedivide(((1.0 - age_group.wastingTreatmentUpdate[_("SAM")]) * numsam), nummam, default=0.0)
"""Calculates the transitions INTO MAM category
For wasting treatment intervention, children leaving SAM are accounted for in programs.py.
If MAM extension is selected, then children leaving MAM are also accounted for in programs.py.
This function accounts for the inflow to MAM (whether or not MAM extension is selected)."""
if len(age_group.data.or_wasting_prog) == 1: # if treatment of MAM extension is not selected
numsam = age_group.num_risk(_("SAM"))
nummam = age_group.num_risk(_("MAM")) * age_group.wastingTreatmentUpdate[_("MAM")]
age_group.fromSAMtoMAMupdate[_("MAM")] = 1 + sc.safedivide(((1.0 - age_group.wastingTreatmentUpdate[_("SAM")]) * numsam), nummam, default=0.0)
else:
age_group.fromSAMtoMAMupdate[_("MAM")] = 1
# TESTING differences for increasing vs decreasing coverage
# if age_group.wastingTreatmentUpdate[_("SAM")] <= 1: # if treatment program coverage is increasing
# age_group.fromSAMtoMAMupdate[_("MAM")] = 1 #+ sc.safedivide(((1.0 - age_group.wastingTreatmentUpdate[_("SAM")]) * numsam), nummam, default=0.0)
# else:
# #numsam = age_group.num_risk(_("SAM")) / age_group.wastingTreatmentUpdate[_("SAM")]
# #nummam = age_group.num_risk(_("MAM")) / age_group.wastingTreatmentUpdate[_("MAM")]
# age_group.fromSAMtoMAMupdate[_("MAM")] = 1# + sc.safedivide(((1.0 - age_group.wastingTreatmentUpdate[_("SAM")]) * numsam), nummam, default=0.0)

@translate
def _dia_indirect_effects(self, age_group):
Expand Down
7 changes: 6 additions & 1 deletion nutrition/populations.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,12 @@ def _set_prob_wasted(self, prog_areas):
OR = self.data.or_wasting_prog[wastingCat][program][age]
except Exception: # if, for eg, MAM doesn't have Treatment of SAM key (odict doesn't have keyerror)
OR = 1
fracCovered = self.previousCov[program]
if wastingCat ==_("MAM"):
# If SAM treatment is extended to MAM, then the coverage refers to continuing treatment
# for SAM children (from MAM to mild), who are only a fraction of MAM children
fracCovered = min(1, self.previousCov[program] * age_group.frac_wasted(_('SAM')) / age_group.frac_wasted(_('MAM')))
else:
fracCovered = self.previousCov[program]
pn, pc = solve_quad(OR, fracCovered, fracThisCatAge)
age_group.probConditionalCoverage[wastingCat][program] = {}
age_group.probConditionalCoverage[wastingCat][program]["covered"] = pc
Expand Down
17 changes: 9 additions & 8 deletions nutrition/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,15 @@ def _wasting_prev_update(self, age_group):
oldProb = age_group.frac_wasted(wastingCat)
probWastedIfCovered = age_group.probConditionalCoverage[wastingCat][self.name]["covered"]
probWastedIfNotCovered = age_group.probConditionalCoverage[wastingCat][self.name]["not covered"]
# if self.name == _("Treatment of SAM") and wastingCat == _('MAM'):
# # If SAM treatment is extended to MAM, then the coverage refers to SAM children, who are only a fraction of MAM children
# newcov = min(1, self.annual_unrestr_cov[self.year] * (age_group.frac_wasted(_('SAM')) / age_group.frac_wasted(_('MAM'))))
# newProb = get_new_prob(newcov, probWastedIfCovered, probWastedIfNotCovered)
# print(self.year, age_group.age, newcov, probWastedIfCovered, newProb, oldProb)
# else:
newcov = self.annual_unrestr_cov[self.year]
newProb = get_new_prob(newcov, probWastedIfCovered, probWastedIfNotCovered)
if self.name == _("Treatment of SAM") and wastingCat == _('MAM'):
# If SAM treatment is extended to MAM, then the coverage refers to SAM children, who are only a fraction of MAM children
newcov = min(1, self.annual_unrestr_cov[self.year] * age_group.frac_wasted(_('SAM')) / age_group.frac_wasted(_('MAM')))
newProb = get_new_prob(newcov, probWastedIfCovered, probWastedIfNotCovered)
print(self.year, age_group.age, newcov, probWastedIfCovered, newProb, oldProb,
sc.safedivide(oldProb - newProb, oldProb, default=0.0), probWastedIfCovered - probWastedIfNotCovered)
else:
newcov = self.annual_unrestr_cov[self.year]
newProb = get_new_prob(newcov, probWastedIfCovered, probWastedIfNotCovered)
reduction = sc.safedivide(oldProb - newProb, oldProb, default=0.0) # If the denominator is 0.0 or close, set reduction to zero (no change)
update[wastingCat] = 1 - reduction
return update
Expand Down
4 changes: 2 additions & 2 deletions nutrition/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sciris as sc

version = "2.0.9"
versiondate = "2023-03-10"
version = "2.0.10"
versiondate = "2023-06-30"
gitinfo = sc.gitinfo(__file__)

0 comments on commit 5e8649f

Please sign in to comment.