Skip to content

Commit df25c76

Browse files
tdm32tbhallett
andauthored
updates from paper analyses for HIV, TB and malaria (#1273)
* updates from paper analyses for HIV, TB and malaria * remove unused import statements * fix imports * update filepath for malaria resource file * remove test_hiv_tb_scenarios.py * updated test_healthsystem.py: test_manipulation_of_service_availability as small population size over 7 days will not schedule VMMC through HIV module. Remove HIV_Prevention_Circumcision in assert statement for HIV services delivered in one week * change ipt_coverage in TB logger as conflicts with existing parameter * updated ResourceFile_Improved_Healthsystem_And_Healthcare_Seeking.xlsx with updated NTP2019 TB data * remove test code * remove test code * delete tmp resourcefiles * malaria code use person_id consistently instead of individual_id * use individual_id for demography.do_death() * style change to avoid conflicts with master * style change to avoid conflicts with master * fix conflicts with master * fix conflicts with master * merge in master * check property hv_date_last_ART correctly set * Manually add PostnatalCare_Comprehensive to policy priorities * edit fix * add schisto high infection as conditional predictor for bladder cancer * fix conditional predictor for active TB - should check presence of CardioMetabolicDisorders * add 'ss' prefix to properties from schisto module referenced in bladder_cancer.py * edit praziquantel code in schisto.py to use value from CMST in place of donated * add parameter rr_depr_hiv for risk of depression with HIV infection * tidy up linear models in depression, include conditional predictors for hiv infection and add comments * move hv_inf into conditional predictor for depression in initial population * convert lm for incident cancer (site_confined) to model with conditional predictors. Include HIV as risk factor. * add parameter rr_site_confined_hiv to other_adult_cancers.py * update other_adult_cancers write-up to include HIV as risk factor * update Depression.docx to include HIV as risk factor for depression * edit HIV in depression to include only HIV cases not virally suppressed * update other_adult_cancers.py linear model to include HIV as risk factor only if not virally suppressed * edit: HIV remains as risk factor for depression independent of treatment status * include HIV as risk factor for low grade dysplasia (oesophageal cancer). Update ResourceFile_Oesophageal_Cancer.xlsx * update linear model for low grade dysplasia to include HIV as conditional risk factor * update OesophagealCancer.docx write-up to include HIV risk * add condition hiv diagnosed for increased risk of depression * remove hiv as risk factor for oesophageal cancer * remove parameter for hiv as risk factor for oesophageal cancer * update OesophagealCancer.docx to remove hiv as risk factor * update value for weighted risk of other_adult_cancers with unsuppressed HIV * add rr_hiv to linear model. update ResourceFile_cmd_condition_onset.xlsx with rr_hiv, leave value=1.0 if no effect of hiv * update resourcefiles for CMD include rr_hiv for all, no effect of majority of processes * add diabetes as risk for active TB and relapse. add params to ResourceFile_TB.xlsx replace linearmodels dict which was accidentally removed in depression.py * add diabetes as risk factor for tb death * add diabetes as risk factor for PLHIV with active TB and on TB treatment * add diabetes as risk factor for PLHIV with active TB and on TB treatment * set up run to check calibration of deaths and disability * add predictor high-intensity S. haematobium infection to risk of bladder cancer in initial population * add predictor high-intensity S. haematobium infection to risk of HIV acquisition * fix indenting in HSI_Hiv_StartOrContinueTreatment * add hv_date_treated abd hv_date_last_ART to baseline_art * convert linear model in CMD to include conditional predictors * delete resourcefile created in error * comment out path-specific changes to analysis_cause_of_death_and_disability_calibrations.py * fix CMD error if Hiv not registered * remove parameter rr_bcg_inf from tb.py * edit comment in initialise_simulation * fix parameter name error * update parameters * test runs * edit and fix flake8 errors * fix failing test * update ResourceFile_Improved_Healthsystem_And_Healthcare_Seeking.xlsx * update ResourceFile_PriorityRanking_ALLPOLICIES.xlsx * updated ResourceFile_Improved_Healthsystem_And_Healthcare_Seeking.xlsx * edit check for last ART when new dispensation occurs * update schisto risk on HIV to only include women * Update tests/test_healthsystem.py Co-authored-by: Tim Hallett <[email protected]> * address comments in PR * address comments in PR * check changes in PR and rollback * check changes in PR and rollback * fix failing tests * merge in latest files from master * merge in latest files from master * baseline AIDS/death scheduling should happen for anyone on ART and not VL suppressed * fix failing tests in test_hiv.py * check tests_hiv passing locally * update enhanced_lifestyle.py due to failing test * remove json file committed accidentally * roll back incidental changes in test_healthsystem.py * roll back inicdental changes in malaria * roll back incidental changes in test_healthsystem.py * roll back incidental changes * Update src/tlo/methods/hiv.py Co-authored-by: Tim Hallett <[email protected]> * check the usage of '' versus "" address comments in PR #1273 review * set VMMC HSI to level 1b otherwise consumables never available * check events using isinstance not string check (string could change) * linting * roll back incidental (formatting) changes in malaria.py * reinstate checks to avoid division by zero * isort --------- Co-authored-by: Tim Hallett <[email protected]>
1 parent d3fb411 commit df25c76

31 files changed

+783
-774
lines changed

docs/write-ups/Depression.docx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:74cc9af2d9e114bee5f695cddcab49c92d79b6fa5abd7c8bb59b1c2a284b8ead
3-
size 233268
2+
oid sha256:947d9954ead452370841b3e8bec8b6bf17fcea40e240ea342dcf169e6c6bb68d
3+
size 235099

docs/write-ups/OesophagealCancer.docx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:ae9f447c5ab5d296f4d5d766a0675865998e386c5b17c97095e36799435f9277
3-
size 180430
2+
oid sha256:ef6ac87512767a2c70dc67d22f5c409c425bf26736624ba039285a1d906750ca
3+
size 185471

docs/write-ups/OtherAdultCancer.docx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:299b9025a1fe1fad73a42ed321061e655e638a9c3ce8ab67e3ee691815ae6d98
3-
size 71556
2+
oid sha256:1f3ff79a3f4e2ad48981cffd95eb6d96d7aa3dc8777015e2b71e63995bf336c9
3+
size 76152
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:0bb3ed875059fa60e8708db0c19da56942d46297c07185849b1ff604f9c67ca8
3-
size 12357
2+
oid sha256:d7016feb63786ef5e87ed199dd79f8b6b4a8b8ead227196a4fb578bf33bc1a2f
3+
size 12432

resources/ResourceFile_HIV.xlsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:d20e316c9b00816da27cc8c104b70cec214787f0d96c80a437f8690806c5e2fb
3-
size 158196
2+
oid sha256:e2345032931c1360046dc7394681cc39669687888f7f8f3e42469d8add067438
3+
size 160376
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:f18f5a91e48fc846c332b55f1742d148816b1fee08ee34383c9995ea36dafdb3
3-
size 48167
2+
oid sha256:da900375dda86f999e744bfb6d6dec7347d5b13f176046ba182740421a43d256
3+
size 48274
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:be37486adb1684f56f4a03a490b7a952d5ddd4e0a19b5aa146d5aaee8dc5e680
3-
size 10830
2+
oid sha256:3d7a8daecbf8a3a6fb7efdcefffb5ece5e91c6abc811da5a038e4fc1fbb44774
3+
size 10865

resources/ResourceFile_TB.xlsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:6760fe2b529eb1538bbbfbd6d5e7350f9dbc2272ab997b363771c8b901739bb3
3-
size 54894
2+
oid sha256:3fc295cc70b8e86c75e1725a92ceb95bc86a26d3fbe1f680db379726bcab3ab3
3+
size 55662
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:bedbf3304e4078e2d495a136eb838757fa06d0e5c7cad13714ba469f1c9a63ae
3-
size 19087
2+
oid sha256:b13090d0ecf6d95c6001133bed733a1642f5e698cc0f048d7526357506088862
3+
size 19200
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:154eb80d1676dd56bd832b77bcd40965ab9c69ee9dc6c146d1a3613cac2848a6
3-
size 30573
2+
oid sha256:b7db0f7a4aca08cdb1852bde35262295c294354a1838b72d65fb14b5cc257364
3+
size 30669
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:b66ae1f6017e1c506970092b975bd6d002dacce13e5c325e59b17cee984eec2f
3-
size 18556
2+
oid sha256:b0d42326a048511264bedf856bb757d0a609ac01361ea1da2b0ed89c066dfa8b
3+
size 18625
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:3fbe4450eb795d3f3c42f71e459f1e703ec4e9aa41c75ed738a6f9c098c5db53
3-
size 11437
2+
oid sha256:82ad9558d816133b020e942c7962b1c783469fa3ba322db164a7305c60caf698
3+
size 11491
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:1a34707bd325d919b8e94cb7135e5a3f17da4bca67d8cc2023418f7b1099e070
3-
size 14047
2+
oid sha256:1419799a637737654950aa137f2f7fd131a934deea6fa2e48ee5b37e531e4517
3+
size 14104
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:a9f6e0e87f17ac90e074eb9434c90f67ec6207f3475c11e4340ba38fe2e94e13
3-
size 13343
2+
oid sha256:328f3c2a624dbbf9072712f573213c744dee7f962f854475b08ffb2a306392c0
3+
size 13425
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:ebfc8af480d9bea1c5321c16acfc64e9ed0a90dea1c15c8a21eb692715ffcf0f
3-
size 42109
2+
oid sha256:734d46d83dccf15bf38ee171a487664f01035da6cf68660d4af62097a6160fb6
3+
size 42716
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:2b703bd5ee7979d349f5dfa825929d36c174a43381ab6fdf08f1b9264814a802
3-
size 67624
2+
oid sha256:6ba5849e265103ee799d1982325b6fed1ef4d3df559ffce9d6790395c201fcaf
3+
size 67562

src/scripts/hiv/projections_jan2023/analysis_full_model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
# %% Run the simulation
2525
start_date = Date(2010, 1, 1)
26-
end_date = Date(2020, 1, 1)
27-
popsize = 5000
26+
end_date = Date(2012, 1, 1)
27+
popsize = 500
2828
# scenario = 0
2929

3030
# set up the log config

src/scripts/hiv/projections_jan2023/analysis_logged_deviance.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
# %% Run the simulation
3636
start_date = Date(2010, 1, 1)
37-
end_date = Date(2015, 1, 1)
38-
popsize = 5000
37+
end_date = Date(2014, 1, 1)
38+
popsize = 1000
3939

4040
# scenario = 1
4141

src/tlo/methods/bladder_cancer.py

+26-14
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, name=None, resourcefilepath=None):
4545

4646
INIT_DEPENDENCIES = {'Demography', 'Lifestyle', 'HealthSystem', 'SymptomManager'}
4747

48-
OPTIONAL_INIT_DEPENDENCIES = {'HealthBurden'}
48+
OPTIONAL_INIT_DEPENDENCIES = {'HealthBurden', 'Schisto'}
4949

5050
METADATA = {
5151
Metadata.DISEASE_MODULE,
@@ -242,17 +242,23 @@ def initialise_population(self, population):
242242
# check parameters are sensible: probability of having any cancer stage cannot exceed 1.0
243243
assert sum(p['init_prop_bladder_cancer_stage']) <= 1.0
244244

245-
lm_init_bc_status_any_stage = LinearModel(
246-
LinearModelType.MULTIPLICATIVE,
247-
sum(p['init_prop_bladder_cancer_stage']),
245+
predictors = [
248246
Predictor('li_tob').when(True, p['rp_bladder_cancer_tobacco']),
249-
# todo: add line when schisto is merged
250-
# Predictor('sh_infection_status').when('High-infection', p['rp_bladder_cancer_schisto_h']),
251247
Predictor('age_years', conditions_are_mutually_exclusive=True)
252248
.when('.between(30,49)', p['rp_bladder_cancer_age3049'])
253249
.when('.between(50,69)', p['rp_bladder_cancer_age5069'])
254250
.when('.between(70,120)', p['rp_bladder_cancer_agege70'])
255251
.when('.between(0,14)', 0.0)
252+
]
253+
254+
conditional_predictors = [
255+
Predictor('ss_sh_infection_status').when('High-infection', p['rp_bladder_cancer_schisto_h']),
256+
] if "Schisto" in self.sim.modules else []
257+
258+
lm_init_bc_status_any_stage = LinearModel(
259+
LinearModelType.MULTIPLICATIVE,
260+
sum(p['init_prop_bladder_cancer_stage']),
261+
*(predictors + conditional_predictors)
256262
)
257263

258264
bc_status_any_stage = lm_init_bc_status_any_stage.predict(df.loc[df.is_alive], self.rng)
@@ -397,20 +403,26 @@ def initialise_simulation(self, sim):
397403
p = self.parameters
398404
lm = self.linear_models_for_progession_of_bc_status
399405

400-
lm['tis_t1'] = LinearModel(
401-
LinearModelType.MULTIPLICATIVE,
402-
p['r_tis_t1_bladder_cancer_none'],
403-
# todo: add in when schisto is in
404-
# Predictor('sh_infection_status').when('High-infection', p['rp_bladder_cancer_schisto_h']),
406+
predictors = [
405407
Predictor('age_years', conditions_are_mutually_exclusive=True)
406408
.when('.between(30,49)', p['rp_bladder_cancer_age3049'])
407409
.when('.between(50,69)', p['rp_bladder_cancer_age5069'])
408410
.when('.between(70,120)', p['rp_bladder_cancer_agege70'])
409411
.when('.between(0,14)', 0.0),
410412
Predictor('li_tob').when(True, p['rr_tis_t1_bladder_cancer_none_tobacco']),
411-
# todo: add in when schisto module in master
412-
# Predictor('sh_').when(True, p['rr_tis_t1_bladder_cancer_none_ex_alc']),
413-
Predictor('bc_status').when('none', 1.0).otherwise(0.0)
413+
# todo:
414+
# Predictor('tmp_').when(True, p['rr_tis_t1_bladder_cancer_none_ex_alc']),
415+
Predictor('bc_status').when('none', 1.0).otherwise(0.0),
416+
]
417+
418+
conditional_predictors = [
419+
Predictor('ss_sh_infection_status').when('High-infection', p['rp_bladder_cancer_schisto_h']),
420+
] if "Schisto" in self.sim.modules else []
421+
422+
lm["tis_t1"] = LinearModel(
423+
LinearModelType.MULTIPLICATIVE,
424+
p['r_tis_t1_bladder_cancer_none'],
425+
*(predictors + conditional_predictors)
414426
)
415427

416428
lm['t2p'] = LinearModel(

src/tlo/methods/cardio_metabolic_disorders.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class CardioMetabolicDisorders(Module):
6161

6262
INIT_DEPENDENCIES = {'Demography', 'Lifestyle', 'HealthSystem', 'SymptomManager'}
6363

64-
OPTIONAL_INIT_DEPENDENCIES = {'HealthBurden'}
64+
OPTIONAL_INIT_DEPENDENCIES = {'HealthBurden', 'Hiv'}
6565

6666
ADDITIONAL_DEPENDENCIES = {'Depression'}
6767

@@ -598,9 +598,7 @@ def build_linear_model(self, condition, interval_between_polls, lm_type):
598598
# LinearModel expects native python types - if it's numpy type, convert it
599599
baseline_annual_probability = float(baseline_annual_probability)
600600

601-
linearmodel = LinearModel(
602-
LinearModelType.MULTIPLICATIVE,
603-
baseline_annual_probability,
601+
predictors = [
604602
Predictor('sex').when('M', p['rr_male']),
605603
Predictor(
606604
'age_years',
@@ -693,6 +691,17 @@ def build_linear_model(self, condition, interval_between_polls, lm_type):
693691
'rr_chronic_ischemic_heart_disease_on_medication']),
694692
Predictor('nc_ever_stroke_on_medication').when(True, p['rr_stroke_on_medication']),
695693
Predictor('nc_ever_heart_attack_on_medication').when(True, p['rr_heart_attack_on_medication'])
694+
]
695+
696+
conditional_predictors = [
697+
Predictor().when('hv_inf & '
698+
'(hv_art != "on_VL_suppressed")', p['rr_hiv']),
699+
] if "Hiv" in self.sim.modules else []
700+
701+
linearmodel = LinearModel(
702+
LinearModelType.MULTIPLICATIVE,
703+
baseline_annual_probability,
704+
*(predictors + conditional_predictors)
696705
)
697706

698707
return linearmodel

src/tlo/methods/depression.py

+51-12
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, name=None, resourcefilepath=None):
3939
'Demography', 'Contraception', 'HealthSystem', 'Lifestyle', 'SymptomManager'
4040
}
4141

42-
OPTIONAL_INIT_DEPENDENCIES = {'HealthBurden'}
42+
OPTIONAL_INIT_DEPENDENCIES = {'HealthBurden', 'Hiv'}
4343

4444
# Declare Metadata
4545
METADATA = {
@@ -145,6 +145,8 @@ def __init__(self, name=None, resourcefilepath=None):
145145

146146
'rr_depr_agege60': Parameter(Types.REAL, 'Relative rate of depression associated with age > 60'),
147147

148+
'rr_depr_hiv': Parameter(Types.REAL, 'Relative rate of depression associated with HIV infection'),
149+
148150
'depr_resolution_rates': Parameter(
149151
Types.LIST,
150152
'Risk of depression resolving in 3 months if no chronic conditions and no treatments.'
@@ -227,11 +229,13 @@ def read_parameters(self, data_folder):
227229
)
228230
p = self.parameters
229231

230-
# Build the Linear Models:
232+
# Build the Linear Models
233+
234+
# ----- Initialisation of population -----
231235
self.linearModels = dict()
232-
self.linearModels['Depression_At_Population_Initialisation'] = LinearModel(
233-
LinearModelType.MULTIPLICATIVE,
234-
self.parameters['init_pr_depr_m_age1519_no_cc_wealth123'],
236+
237+
# risk of depression in initial population
238+
predictors = [
235239
Predictor('de_cc').when(True, p['init_rp_depr_cc']),
236240
Predictor('li_wealth').when('.isin([4,5])', p['init_rp_depr_wealth45']),
237241
Predictor().when('(sex=="F") & de_recently_pregnant', p['init_rp_depr_f_rec_preg']),
@@ -244,44 +248,63 @@ def read_parameters(self, data_folder):
244248
.when('.between(0, 14)', 0)
245249
.when('.between(15, 19)', 1.0)
246250
.when('.between(20, 59)', p['init_rp_depr_age2059'])
247-
.when('>= 60', p['init_rp_depr_agege60'])
251+
.when('>= 60', p['init_rp_depr_agege60']),
252+
]
253+
254+
conditional_predictors = [
255+
Predictor().when(
256+
'hv_inf & hv_diagnosed',
257+
p["rr_depr_hiv"]),
258+
] if "Hiv" in self.sim.modules else []
259+
260+
self.linearModels["Depression_At_Population_Initialisation"] = LinearModel(
261+
LinearModelType.MULTIPLICATIVE,
262+
p['init_pr_depr_m_age1519_no_cc_wealth123'],
263+
*(predictors + conditional_predictors)
248264
)
249265

266+
# risk of ever having depression in initial population
250267
self.linearModels['Depression_Ever_At_Population_Initialisation_Males'] = LinearModel.multiplicative(
251268
Predictor('age_years').apply(
252269
lambda x: (x if x > 15 else 0) * self.parameters['init_rp_ever_depr_per_year_older_m']
253270
)
254271
)
255272

273+
# risk of ever having depression in initial population (female)
256274
self.linearModels['Depression_Ever_At_Population_Initialisation_Females'] = LinearModel.multiplicative(
257275
Predictor('age_years').apply(lambda x: (x if x > 15 else 0) * p['init_rp_ever_depr_per_year_older_f'])
258276
)
259277

278+
# risk of ever having diagnosed depression in initial population
260279
self.linearModels['Depression_Ever_Diagnosed_At_Population_Initialisation'] = LinearModel.multiplicative(
261280
Predictor('de_ever_depr').when(True, p['init_pr_ever_diagnosed_depression'])
262281
.otherwise(0.0)
263282
)
264283

284+
# risk of currently using anti-depressants in initial population
265285
self.linearModels['Using_AntiDepressants_Initialisation'] = LinearModel.multiplicative(
266286
Predictor('de_depr').when(True, p['init_pr_antidepr_curr_depr']),
267287
Predictor().when('~de_depr & de_ever_diagnosed_depression', p['init_rp_antidepr_ever_depr_not_curr'])
268288
)
269289

290+
# risk of ever having talking therapy in initial population
270291
self.linearModels['Ever_Talking_Therapy_Initialisation'] = LinearModel(
271292
LinearModelType.MULTIPLICATIVE,
272293
p['init_pr_ever_talking_therapy_if_diagnosed'],
273294
Predictor('de_ever_diagnosed_depression').when(False, 0)
274295
)
275296

297+
# risk of ever having self-harmed in initial population
276298
self.linearModels['Ever_Self_Harmed_Initialisation'] = LinearModel(
277299
LinearModelType.MULTIPLICATIVE,
278300
p['init_pr_ever_self_harmed_if_ever_depr'],
279301
Predictor('de_ever_depr').when(False, 0)
280302
)
281303

282-
self.linearModels['Risk_of_Depression_Onset_per3mo'] = LinearModel(
283-
LinearModelType.MULTIPLICATIVE,
284-
p['base_3m_prob_depr'],
304+
# ----- Recurring events -----
305+
306+
# risk of depression every 3 months
307+
predictors = [
285308
Predictor('de_cc').when(True, p['rr_depr_cc']),
286309
Predictor('age_years', conditions_are_mutually_exclusive=True)
287310
.when('.between(0, 14)', 0)
@@ -291,26 +314,42 @@ def read_parameters(self, data_folder):
291314
Predictor('sex').when('F', p['rr_depr_female']),
292315
Predictor('de_recently_pregnant').when(True, p['rr_depr_pregnancy']),
293316
Predictor('de_ever_depr').when(True, p['rr_depr_prev_epis']),
294-
Predictor('de_on_antidepr').when(True, p['rr_depr_on_antidepr'])
317+
Predictor('de_on_antidepr').when(True, p['rr_depr_on_antidepr']),
318+
]
319+
320+
conditional_predictors = [
321+
Predictor().when(
322+
'hv_inf & hv_diagnosed',
323+
p["rr_depr_hiv"]),
324+
] if "Hiv" in self.sim.modules else []
325+
326+
self.linearModels["Risk_of_Depression_Onset_per3mo"] = LinearModel(
327+
LinearModelType.MULTIPLICATIVE,
328+
p['base_3m_prob_depr'],
329+
*(predictors + conditional_predictors)
295330
)
296331

332+
# risk of depression resolution every 3 months
297333
self.linearModels['Risk_of_Depression_Resolution_per3mo'] = LinearModel.multiplicative(
298334
Predictor('de_intrinsic_3mo_risk_of_depr_resolution').apply(lambda x: x),
299335
Predictor('de_cc').when(True, p['rr_resol_depr_cc']),
300336
Predictor('de_on_antidepr').when(True, p['rr_resol_depr_on_antidepr']),
301337
Predictor('de_ever_talk_ther').when(True, p['rr_resol_depr_current_talk_ther'])
302338
)
303339

340+
# risk of stopping anti-depressants every 3 months
304341
self.linearModels['Risk_of_Stopping_Antidepressants_per3mo'] = LinearModel.multiplicative(
305342
Predictor('de_depr').when(True, p['prob_3m_default_antidepr'])
306343
.when(False, p['prob_3m_stop_antidepr'])
307344
)
308345

346+
# risk of self-harm every 3 months
309347
self.linearModels['Risk_of_SelfHarm_per3mo'] = LinearModel(
310348
LinearModelType.MULTIPLICATIVE,
311349
p['prob_3m_selfharm_depr']
312350
)
313351

352+
# risk of suicide every 3 months
314353
self.linearModels['Risk_of_Suicide_per3mo'] = LinearModel(
315354
LinearModelType.MULTIPLICATIVE,
316355
p['prob_3m_suicide_depr_m'],
@@ -519,7 +558,7 @@ def _check_for_suspected_depression(
519558
):
520559
"""
521560
Returns True if any signs of depression are present, otherwise False.
522-
561+
523562
Raises an error if the treatment type cannot be identified.
524563
"""
525564
if treatment_id == "FirstAttendance_NonEmergency":
@@ -574,7 +613,7 @@ def do_when_suspected_depression(
574613
"""
575614
This is called by any HSI event when depression is suspected or otherwise investigated.
576615
577-
At least one of the diagnosis_function or hsi_event arguments must be provided; if both
616+
At least one of the diagnosis_function or hsi_event arguments must be provided; if both
578617
are provided, the hsi_event argument is ignored.
579618
- If the hsi_event argument is provided, that event is used to access the diagnosis
580619
manager and run diagnosis tests.

0 commit comments

Comments
 (0)