-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
2214 lines (1862 loc) · 106 KB
/
utils.py
File metadata and controls
2214 lines (1862 loc) · 106 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'''
Utilities for multicalibration
'''
# Standard imports
import sciris as sc
import hpvsim as hpv
import hpvsim.parameters as hppar
import pandas as pd
import numpy as np
import pylab as pl
import seaborn as sns
from matplotlib.gridspec import GridSpec
import math
from scipy.stats import lognorm, norm
import analyzers as an
import run_sim as rs
resfolder = 'results'
figfolder = 'figures'
datafolder = 'data'
def set_font(size=None, font='Libertinus Sans'):
''' Set a custom font '''
sc.fonts(add=sc.thisdir(aspath=True) / 'assets' / 'LibertinusSans-Regular.otf')
sc.options(font=font, fontsize=size)
return
def map_sb_loc(location):
''' Map between different representations of country names '''
location = location.title()
if location == "Cote Divoire": location = "Cote d'Ivoire"
if location == "Drc": location = 'Congo Democratic Republic'
return location
def rev_map_sb_loc(location):
''' Map between different representations of country names '''
location = location.lower()
# location = location.replace(' ', '_')
if location == 'congo democratic republic': location = "drc"
if location == "cote d'ivoire": location = 'cote divoire'
return location
def make_sb_data(location=None, dist_type='lognormal', debut_bias=[0,0]):
sb_location = map_sb_loc(location)
# Read in data
sb_data_f = pd.read_csv(f'data/sb_pars_women_{dist_type}.csv')
sb_data_m = pd.read_csv(f'data/sb_pars_men_{dist_type}.csv')
try:
distf = sb_data_f.loc[sb_data_f["location"]==sb_location,"dist"].iloc[0]
par1f = sb_data_f.loc[sb_data_f["location"]==sb_location,"par1"].iloc[0]
par2f = sb_data_f.loc[sb_data_f["location"]==sb_location,"par2"].iloc[0]
distm = sb_data_m.loc[sb_data_m["location"]==sb_location,"dist"].iloc[0]
par1m = sb_data_m.loc[sb_data_m["location"]==sb_location,"par1"].iloc[0]
par2m = sb_data_m.loc[sb_data_m["location"]==sb_location,"par2"].iloc[0]
except:
print(f'No data for {sb_location=}, {location=}')
debut = dict(
f=dict(dist=distf, par1=par1f+debut_bias[0], par2=par2f),
m=dict(dist=distm, par1=par1m+debut_bias[1], par2=par2m),
)
return debut
def make_datafiles(locations):
''' Get the relevant datafiles for the selected locations '''
datafiles = dict()
asr_locs = ['drc', 'ethiopia', 'kenya', 'nigeria', 'tanzania', 'uganda']
cancer_type_locs = ['ethiopia', 'kenya', 'nigeria', 'tanzania', 'india', 'uganda']
cin_type_locs = ['nigeria', 'tanzania', 'india']
for location in locations:
dflocation = location.replace(' ','_')
datafiles[location] = [
f'data/{dflocation}_cancer_cases.csv',
]
if location in asr_locs:
datafiles[location] += [f'data/{dflocation}_asr_cancer_incidence.csv']
if location in cancer_type_locs:
datafiles[location] += [f'data/{dflocation}_cancer_types.csv']
if location in cin_type_locs:
datafiles[location] += [f'data/{dflocation}_cin_types.csv']
return datafiles
def lognorm_params(par1, par2):
"""
Given the mean and std. dev. of the log-normal distribution, this function
returns the shape and scale parameters for scipy's parameterization of the
distribution.
"""
mean = np.log(par1 ** 2 / np.sqrt(par2 ** 2 + par1 ** 2)) # Computes the mean of the underlying normal distribution
sigma = np.sqrt(np.log(par2 ** 2 / par1 ** 2 + 1)) # Computes sigma for the underlying normal distribution
scale = np.exp(mean)
shape = sigma
return shape, scale
def plot_residual_burden(location=None, scens=None):
'''
Plot the residual burden of HPV under different scenarios
'''
set_font(size=24)
r1 = np.arange(len(scens))
bigdf = sc.loadobj(f'{resfolder}/{location}.obj')
colors = sc.gridcolors(20)
fig, axes = pl.subplots(2, 1, figsize=(20, 16))
ib_labels = scens.keys()
for ib, (ib_label, ib_scens) in enumerate(scens.items()):
vx_scen_label = ib_scens[0]
screen_scen_label = ib_scens[1]
txvx_scen_label = ib_scens[2]
df = bigdf[(bigdf.screen_scen == screen_scen_label) & (bigdf.vx_scen == vx_scen_label)
& (bigdf.txvx_scen == txvx_scen_label)].groupby('year')[
['asr_cancer_incidence', 'asr_cancer_incidence_low', 'asr_cancer_incidence_high', 'cancers', 'cancers_low',
'cancers_high', 'cancer_deaths', 'cancer_deaths_low', 'cancer_deaths_high']].sum()
ys = sc.findinds(df.index, 2020)[0]
ye = sc.findinds(df.index, 2060)[0]
years = np.array(df.index)[ys:ye]
best_ts = np.array(df['cancers'])[ys:ye]
low_ts = np.array(df['cancers_low'])[ys:ye]
high_ts = np.array(df['cancers_high'])[ys:ye]
axes[0].plot(years, best_ts, color=colors[ib], linewidth=3, label=ib_label)
axes[0].fill_between(years, low_ts, high_ts, color=colors[ib], alpha=0.3)
best_short = np.sum(np.array(df['cancers'])[ys:ye])
low_short = np.sum(np.array(df['cancers_low'])[ys:ye])
high_short = np.sum(np.array(df['cancers_high'])[ys:ye])
yerr_short = abs(high_short - low_short)
axes[1].barh(r1[ib], best_short, xerr=yerr_short, color=colors[ib])
sc.SIticks(axes[0])
sc.SIticks(axes[1])
axes[1].set_yticks([r for r in range(len(r1))], ib_labels)
axes[0].legend(loc=3)
# axes[1, 0].legend()
axes[0].set_ylabel('Cervical cancer cases')
# axes[1].set_xlabel('Residual cervical cancer cases (2025-2060)')
axes[1].set_xlabel('Cervical cancer deaths (2025-2060)')
axes[0].set_ylim(bottom=0)
axes[1].invert_yaxis()
fig.suptitle(f'{location.capitalize()}')
fig.tight_layout()
fig_name = f'{figfolder}/{location}_residual_burden.png'
sc.savefig(fig_name, dpi=100)
return
def plot_VIMC_compare(locations=None, scens=None):
dfs = sc.autolist()
for location in locations:
df = sc.loadobj(f'{resfolder}/{location}.obj')
dfs += df
bigdf = pd.concat(dfs)
VIMC = pd.read_csv(f'{datafolder}/VIMC.csv')
n_plots = len(locations)
n_rows, n_cols = sc.get_rows_cols(n_plots)
set_font(12)
fig, axes = pl.subplots(n_rows, n_cols, figsize=(11, 10))
axes = axes.flatten()
VIMC_pivot = pd.pivot_table(
VIMC,
values='cases',
index='year',
columns='country_name',
aggfunc='sum'
)
VIMC_pivot= VIMC_pivot[20:61]
vx_scen_label = scens[0]
screen_scen_label = scens[1]
txvx_scen_label = scens[2]
for pn, ax in enumerate(axes):
if pn >= len(locations):
ax.set_visible(False)
else:
location = locations[pn]
df = bigdf[(bigdf.screen_scen == screen_scen_label) & (bigdf.vx_scen == vx_scen_label)
& (bigdf.txvx_scen == txvx_scen_label) & (bigdf.location == location)].groupby('year')[
['cancers', 'cancers_high', 'cancers_low']].sum()[2020:]
years = np.array(df.index)
ax.plot(years, df['cancers'], label='HPVsim')
ax.fill_between(years, df['cancers_low'], df['cancers_high'], alpha=0.3)
title_country = location.title()
if title_country == 'Tanzania':
title_country = 'Tanzania, United Republic of'
if title_country == 'Drc':
title_country = "Congo, the Democratic Republic of the"
ax.plot(years, VIMC_pivot[title_country], label='VIMC')
ax.set_ylim(bottom=0)
ax.legend()
sc.SIticks(ax)
ax.set_title(location.capitalize())
fig.suptitle('Cervical cancer cases over time')
fig.tight_layout()
fig_name = f'{figfolder}/VIMC_compare.png'
sc.savefig(fig_name, dpi=100)
return
def plot_txv_impact(location=None, background_scens=None, txvx_ages=None, txvx_efficacies=None, discounting=False):
set_font(size=24)
bigdf = sc.loadobj(f'{resfolder}/{location}.obj')
econdf = sc.loadobj(f'{resfolder}/{location}_econ.obj')
colors = sc.gridcolors(20)
width = 0.1
standard_le = 88.8
r1 = np.arange(len(background_scens))
r2 = [x + width for x in r1]
r3 = [x + width for x in r2]
r4 = [x + width for x in r3]
xes = [r1, r2, r3, r4]
markers = ['s', 'v', 'P', '*', '+', 'D', '^', 'x']
fig, axes = pl.subplots(2, 2, figsize=(16, 16))
for ib, (background_scen_label, background_scen) in enumerate(background_scens.items()):
vx_scen_label = background_scen['vx_scen']
screen_scen_label = background_scen['screen_scen']
NoTxV_df = bigdf[(bigdf.screen_scen == screen_scen_label) & (bigdf.vx_scen == vx_scen_label)
& (bigdf.txvx_scen == 'No TxV')].groupby('year')[
['cancers', 'cancers_low', 'cancers_high', 'cancer_deaths', 'cancer_deaths_low', 'cancer_deaths_high',
'n_tx_vaccinated']].sum()
NoTxV_econdf_cancers = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == 'No TxV')].groupby('year')[
['new_cancers', 'new_cancer_deaths']].sum()
NoTxV_econdf = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == 'No TxV')].groupby('year')[
['av_age_cancer_deaths', 'av_age_cancers']].mean()
if discounting:
cancers = np.array([i / 1.03 ** t for t, i in enumerate(NoTxV_econdf_cancers['new_cancers'].values)])
cancer_deaths = np.array([i / 1.03 ** t for t, i in enumerate(NoTxV_econdf_cancers['new_cancer_deaths'].values)])
else:
cancers = NoTxV_econdf_cancers['new_cancers'].values
cancer_deaths = NoTxV_econdf_cancers['new_cancer_deaths'].values
avg_age_ca_death = np.mean(NoTxV_econdf['av_age_cancer_deaths'])
avg_age_ca = np.mean(NoTxV_econdf['av_age_cancers'])
ca_years = avg_age_ca_death - avg_age_ca
yld = np.sum(np.sum([0.54 * .1, 0.049 * .5, 0.451 * .3, 0.288 * .1]) * ca_years * cancers)
yll = np.sum((standard_le-avg_age_ca_death) * cancer_deaths)
daly_noTxV = yll + yld
ys = sc.findinds(NoTxV_df.index, 2030)[0]
ye = sc.findinds(NoTxV_df.index, 2060)[0]
NoTxV_cancers = np.sum(np.array(NoTxV_df['cancers'])[ys:ye])
NoTxV_cancers_low = np.sum(np.array(NoTxV_df['cancers_low'])[ys:ye])
NoTxV_cancers_high = np.sum(np.array(NoTxV_df['cancers_high'])[ys:ye])
NoTxV_cancer_deaths_short = np.sum(np.array(NoTxV_df['cancer_deaths'])[ys:ye])
NoTxV_cancer_deaths_short_low = np.sum(np.array(NoTxV_df['cancer_deaths_low'])[ys:ye])
NoTxV_cancer_deaths_short_high = np.sum(np.array(NoTxV_df['cancer_deaths_high'])[ys:ye])
for i_eff, txvx_efficacy in enumerate(txvx_efficacies):
for i_age, txvx_age in enumerate(txvx_ages):
txvx_scen_label_age = f'Mass TxV, {txvx_efficacy}, age {txvx_age}'
TxV_df = bigdf[(bigdf.screen_scen == screen_scen_label) & (bigdf.vx_scen == vx_scen_label)
& (bigdf.txvx_scen == txvx_scen_label_age)].groupby(
'year')[
['asr_cancer_incidence', 'asr_cancer_incidence_low', 'asr_cancer_incidence_high',
'cancers', 'cancers_low', 'cancers_high', 'cancer_deaths', 'cancer_deaths_low', 'cancer_deaths_high', 'n_tx_vaccinated']].sum()
TxV_econdf_cancers = \
econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == txvx_scen_label_age)].groupby('year')[
['new_cancers', 'new_cancer_deaths']].sum()
TxV_econdf = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == txvx_scen_label_age)].groupby('year')[
['av_age_cancer_deaths', 'av_age_cancers']].mean()
if discounting:
cancers = np.array([i / 1.03 ** t for t, i in enumerate(TxV_econdf_cancers['new_cancers'].values)])
cancer_deaths = np.array(
[i / 1.03 ** t for t, i in enumerate(TxV_econdf_cancers['new_cancer_deaths'].values)])
else:
cancers = TxV_econdf_cancers['new_cancers'].values
cancer_deaths = TxV_econdf_cancers['new_cancer_deaths'].values
avg_age_ca_death = np.mean(TxV_econdf['av_age_cancer_deaths'])
avg_age_ca = np.mean(TxV_econdf['av_age_cancers'])
ca_years = avg_age_ca_death - avg_age_ca
yld = np.sum(np.sum([0.54 * .1, 0.049 * .5, 0.451 * .3, 0.288 * .1]) * ca_years * cancers)
yll = np.sum((standard_le - avg_age_ca_death) * cancer_deaths)
daly_TxV = yll + yld
dalys_averted = daly_noTxV - daly_TxV
best_TxV_cancers_short = np.sum(np.array(TxV_df['cancers'])[ys:ye])
averted_cancers_short = NoTxV_cancers - best_TxV_cancers_short
perc_cancers_averted_short = 100 * averted_cancers_short / NoTxV_cancers
to_plot_short = perc_cancers_averted_short
TxV_cancers = np.sum(np.array(TxV_df['cancers'])[ys:ye])
TxV_cancers_low = np.sum(np.array(TxV_df['cancers_low'])[ys:ye])
TxV_cancers_high = np.sum(np.array(TxV_df['cancers_high'])[ys:ye])
best_TxV_cancer_deaths_short = np.sum(np.array(TxV_df['cancer_deaths'])[ys:ye])
best_TxV_cancer_deaths_short_high = np.sum(np.array(TxV_df['cancer_deaths_high'])[ys:ye])
best_TxV_cancer_deaths_short_low = np.sum(np.array(TxV_df['cancer_deaths_low'])[ys:ye])
averted_cancer_deaths_short = NoTxV_cancer_deaths_short - best_TxV_cancer_deaths_short
averted_cancer_deaths_short_high = NoTxV_cancer_deaths_short_high - best_TxV_cancer_deaths_short_high
averted_cancer_deaths_short_low = NoTxV_cancer_deaths_short_low - best_TxV_cancer_deaths_short_low
TxV_cancers_averted = NoTxV_cancers - TxV_cancers
if i_eff + ib == 0:
axes[0,0].scatter(xes[i_eff][ib], TxV_cancers_averted, marker=markers[i_age], color=colors[i_eff],
s=300, label=f'Age {txvx_age}')
else:
axes[0,0].scatter(xes[i_eff][ib], TxV_cancers_averted, marker=markers[i_age], color=colors[i_eff],
s=300)
if ib + i_age == 0:
axes[0,1].scatter(xes[i_eff][ib], to_plot_short, marker=markers[i_age], color=colors[i_eff], s=300,
label=txvx_efficacy)
else:
axes[0,1].scatter(xes[i_eff][ib], to_plot_short, marker=markers[i_age], color=colors[i_eff], s=300)
axes[1,0].scatter(xes[i_eff][ib], averted_cancer_deaths_short, marker=markers[i_age], color=colors[i_eff], s=300)
axes[1,1].scatter(xes[i_eff][ib], dalys_averted, marker=markers[i_age], color=colors[i_eff], s=300)
ib_labels = background_scens.keys()
axes[1,0].set_xticks([r + 1.5*width for r in range(len(r1))], ib_labels)
axes[1,1].set_xticks([r + 1.5 * width for r in range(len(r1))], ib_labels)
axes[0,0].get_xaxis().set_visible(False)
axes[0,1].get_xaxis().set_visible(False)
axes[0,0].set_ylim(bottom=0)
axes[0, 1].set_ylim(bottom=0)
axes[1, 0].set_ylim(bottom=0)
axes[1, 1].set_ylim(bottom=0)
sc.SIticks(axes[0,0])
sc.SIticks(axes[0,1])
sc.SIticks(axes[1,0])
sc.SIticks(axes[1,1])
axes[0,0].set_ylabel(f'Cervical cancer cases averted (2030-2060)')
axes[0,1].set_ylabel(f'Percent cervical cancer cases averted (2030-2060)')
axes[1,0].set_ylabel(f'Deaths averted')
axes[1,1].set_ylabel(f'DALYs averted')
# axes[1].set_ylim([0, 30])
axes[0,0].legend(title='Age of TxV')
axes[0,1].legend(title='TxV Effectiveness')
fig.suptitle(f'{location.capitalize()}')
# axes[1].set_xlabel('Background intervention scenario')
axes[1,0].set_xlabel('Background intervention scenario')
axes[1, 1].set_xlabel('Background intervention scenario')
fig.tight_layout()
fig_name = f'{figfolder}/{location}_txv_impact.png'
fig.savefig(fig_name, dpi=100)
return
def plot_residual_burden_combined(locations, scens):
set_font(size=24)
dfs = sc.autolist()
for location in locations:
df = sc.loadobj(f'{resfolder}/{location}.obj')
dfs += df
bigdf = pd.concat(dfs)
colors = ['gold', 'orange', 'red', 'darkred']
fig = pl.figure(constrained_layout=True, figsize=(16, 20))
spec2 = GridSpec(ncols=3, nrows=4, figure=fig)
ax1 = fig.add_subplot(spec2[0, :])
axes = []
for i in np.arange(1,4):
for j in np.arange(0,3):
ax = fig.add_subplot(spec2[i,j])
axes.append(ax)
txvx_scen_label = 'No TxV'
for ib, (ib_label, ib_scens) in enumerate(scens.items()):
vx_scen_label = ib_scens[0]
screen_scen_label = ib_scens[1]
df = bigdf[(bigdf.screen_scen == screen_scen_label) & (bigdf.vx_scen == vx_scen_label)
& (bigdf.txvx_scen == txvx_scen_label)].groupby('year')[
['cancers', 'cancers_low', 'cancers_high']].sum()[2020:]
years = np.array(df.index)
ax1.plot(years, df['cancers'], color=colors[ib], label=ib_label)
ax1.fill_between(years, df['cancers_low'], df['cancers_high'], color=colors[ib], alpha=0.3)
for pn, location in enumerate(locations):
ax = axes[pn]
for ib, (ib_label, ib_scens) in enumerate(scens.items()):
vx_scen_label = ib_scens[0]
screen_scen_label = ib_scens[1]
df = bigdf[(bigdf.screen_scen == screen_scen_label) & (bigdf.vx_scen == vx_scen_label)
& (bigdf.txvx_scen == txvx_scen_label) & (bigdf.location == location)].groupby('year')[
['cancers', 'cancers_low', 'cancers_high']].sum()[2020:]
years = np.array(df.index)
ax.plot(years, df['cancers'], color=colors[ib])
ax.fill_between(years, df['cancers_low'], df['cancers_high'], color=colors[ib], alpha=0.3)
sc.SIticks(ax)
if location == 'drc':
ax.set_title('DRC')
else:
ax.set_title(location.capitalize())
for pn in range(len(locations)):
axes[pn].set_ylim(bottom=0)
sc.SIticks(ax1)
ax1.legend()
fig.tight_layout()
fig_name = f'{figfolder}/residual_burden.png'
sc.savefig(fig_name, dpi=100)
return
def plot_CEA(locations=None, background_scens=None, txvx_scen=None, discounting=False):
set_font(size=14)
econdfs = sc.autolist()
for location in locations:
econdf = sc.loadobj(f'{resfolder}/{location}_econ.obj')
econdfs += econdf
econ_df = pd.concat(econdfs)
cost_dict = dict(
txv=8,
leep=41.76,
ablation=11.76,
cancer=450
)
standard_le = 88.8
colors = ['orange', 'red', 'darkred']
fig, ax = pl.subplots(figsize=(10, 6))
for ib, (background_scen_label, background_scen) in enumerate(background_scens.items()):
vx_scen_label = background_scen['vx_scen']
screen_scen_label = background_scen['screen_scen']
dalys_noTxV = 0
dalys_TxV = 0
cost_noTxV = 0
cost_TxV = 0
for location in locations:
NoTxV_econdf_counts = econ_df[(econ_df.screen_scen == screen_scen_label) & (econ_df.vx_scen == vx_scen_label)
& (econ_df.txvx_scen == 'No TxV') & (econ_df.location == location)].groupby('year')[
['new_tx_vaccinations', 'new_thermal_ablations', 'new_leeps',
'new_cancer_treatments', 'new_cancers', 'new_cancer_deaths']].sum()
NoTxV_econdf_means = econ_df[(econ_df.screen_scen == screen_scen_label) & (econ_df.vx_scen == vx_scen_label)
& (econ_df.txvx_scen == 'No TxV') & (econ_df.location == location)].groupby('year')[
['av_age_cancer_deaths', 'av_age_cancers']].mean()
if discounting:
cancers = np.array([i / 1.03 ** t for t, i in enumerate(NoTxV_econdf_counts['new_cancers'].values)])
cancer_deaths = np.array(
[i / 1.03 ** t for t, i in enumerate(NoTxV_econdf_counts['new_cancer_deaths'].values)])
else:
cancers = NoTxV_econdf_counts['new_cancers'].values
cancer_deaths = NoTxV_econdf_counts['new_cancer_deaths'].values
avg_age_ca_death = np.mean(NoTxV_econdf_means['av_age_cancer_deaths'])
avg_age_ca = np.mean(NoTxV_econdf_means['av_age_cancers'])
ca_years = avg_age_ca_death - avg_age_ca
yld = np.sum(np.sum([0.54 * .1, 0.049 * .5, 0.451 * .3, 0.288 * .1]) * ca_years * cancers)
yll = np.sum((standard_le - avg_age_ca_death) * cancer_deaths)
daly_noTxV = yll + yld
dalys_noTxV += daly_noTxV
total_cost_noTxV = (NoTxV_econdf_counts['new_tx_vaccinations'].values * cost_dict['txv']) + \
(NoTxV_econdf_counts['new_thermal_ablations'].values * cost_dict['ablation']) + \
(NoTxV_econdf_counts['new_leeps'].values * cost_dict['leep']) + \
(NoTxV_econdf_counts['new_cancer_treatments'].values * cost_dict['cancer'])
if discounting:
cost_noTxV = np.sum([i / 1.03 ** t for t, i in enumerate(total_cost_noTxV)])
else:
cost_noTxV = np.sum(total_cost_noTxV)
cost_noTxV += cost_noTxV
txvx_scen_label_age = f'{txvx_scen}'
TxV_econdf_counts = econ_df[(econ_df.screen_scen == screen_scen_label) & (econ_df.vx_scen == vx_scen_label)
& (econ_df.txvx_scen == txvx_scen_label_age) & (econ_df.location == location)].groupby(
'year')[
['new_tx_vaccinations', 'new_thermal_ablations', 'new_leeps',
'new_cancer_treatments', 'new_cancers', 'new_cancer_deaths']].sum()
TxV_econdf_means = econ_df[(econ_df.screen_scen == screen_scen_label) & (econ_df.vx_scen == vx_scen_label)
& (econ_df.txvx_scen == txvx_scen_label_age) & (
econ_df.location == location)].groupby(
'year')[
['av_age_cancer_deaths', 'av_age_cancers']].mean()
if discounting:
cancers = np.array([i / 1.03 ** t for t, i in enumerate(TxV_econdf_counts['new_cancers'].values)])
cancer_deaths = np.array(
[i / 1.03 ** t for t, i in enumerate(TxV_econdf_counts['new_cancer_deaths'].values)])
else:
cancers = TxV_econdf_counts['new_cancers'].values
cancer_deaths = TxV_econdf_counts['new_cancer_deaths'].values
avg_age_ca_death = np.mean(TxV_econdf_means['av_age_cancer_deaths'])
avg_age_ca = np.mean(TxV_econdf_means['av_age_cancers'])
ca_years = avg_age_ca_death - avg_age_ca
yld = np.sum(np.sum([0.54 * .1, 0.049 * .5, 0.451 * .3, 0.288 * .1]) * ca_years * cancers)
yll = np.sum((standard_le - avg_age_ca_death) * cancer_deaths)
daly_TxV = yll + yld
dalys_TxV += daly_TxV
total_cost_TxV = (TxV_econdf_counts['new_tx_vaccinations'].values * cost_dict['txv']) + \
(TxV_econdf_counts['new_thermal_ablations'].values * cost_dict['ablation']) + \
(TxV_econdf_counts['new_leeps'].values * cost_dict['leep']) + \
(TxV_econdf_counts['new_cancer_treatments'].values * cost_dict['cancer'])
if discounting:
cost_TxV = np.sum([i / 1.03 ** t for t, i in enumerate(total_cost_TxV)])
else:
cost_TxV = np.sum(total_cost_TxV)
cost_TxV += cost_TxV
dalys_averted = dalys_noTxV - dalys_TxV
additional_cost = cost_TxV - cost_noTxV
cost_daly_averted = additional_cost / dalys_averted
ax.plot(dalys_averted/1e6, cost_daly_averted, color=colors[ib], marker='s', linestyle = 'None', markersize=20,
label=background_scen_label)
# sc.SIticks(ax)
ax.legend(title='Background intervention scenario')
ax.set_xlabel('DALYs averted (millions), 2030-2060')
ax.set_ylabel('Incremental costs/DALY averted,\n$USD 2030-2060')
ax.set_ylim([0, 120])
# fig.suptitle(f'TxV CEA for {locations}', fontsize=18)
fig.tight_layout()
fig_name = f'{figfolder}/CEA.png'
fig.savefig(fig_name, dpi=100)
return
def plot_txv_impact_combined(locations=None, background_scens=None, txvx_ages=None, txvx_efficacies=None, discounting=False):
set_font(size=24)
dfs = sc.autolist()
econdfs = sc.autolist()
for location in locations:
df = sc.loadobj(f'{resfolder}/{location}.obj')
dfs += df
econ_df = sc.loadobj(f'{resfolder}/{location}_econ.obj')
econdfs += econ_df
econdf = pd.concat(econdfs)
bigdf = pd.concat(dfs)
colors = sc.gridcolors(20)
width = 0.1
standard_le = 88.8
r1 = np.arange(len(background_scens))
r2 = [x + width for x in r1]
r3 = [x + width for x in r2]
r4 = [x + width for x in r3]
xes = [r1, r2, r3, r4]
markers = ['s', 'v', 'P', '*', '+', 'D', '^', 'x']
LTFU = 0.2
fig, axes = pl.subplots(3, 1, figsize=(16, 20))
for ib, (background_scen_label, background_scen) in enumerate(background_scens.items()):
vx_scen_label = background_scen['vx_scen']
screen_scen_label = background_scen['screen_scen']
NoTxV_df = bigdf[(bigdf.screen_scen == screen_scen_label) & (bigdf.vx_scen == vx_scen_label)
& (bigdf.txvx_scen == 'No TxV')].groupby('year')[
['cancers', 'cancers_low', 'cancers_high', 'cancer_deaths', 'cancer_deaths_low', 'cancer_deaths_high', 'n_tx_vaccinated']].sum()
NoTxV_econdf_cancers = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == 'No TxV')].groupby('year')[
['new_cancers', 'new_cancer_deaths']].sum()
NoTxV_econdf = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == 'No TxV')].groupby('year')[
['av_age_cancer_deaths', 'av_age_cancers']].mean()
if discounting:
cancers = np.array([i / 1.03 ** t for t, i in enumerate(NoTxV_econdf_cancers['new_cancers'].values)])
cancer_deaths = np.array([i / 1.03 ** t for t, i in enumerate(NoTxV_econdf_cancers['new_cancer_deaths'].values)])
else:
cancers = NoTxV_econdf_cancers['new_cancers'].values
cancer_deaths = NoTxV_econdf_cancers['new_cancer_deaths'].values
avg_age_ca_death = np.mean(NoTxV_econdf['av_age_cancer_deaths'])
avg_age_ca = np.mean(NoTxV_econdf['av_age_cancers'])
ca_years = avg_age_ca_death - avg_age_ca
yld = np.sum(np.sum([0.54 * .1, 0.049 * .5, 0.451 * .3, 0.288 * .1]) * ca_years * cancers)
yll = np.sum((standard_le-avg_age_ca_death) * cancer_deaths)
daly_noTxV = yll + yld
ys = sc.findinds(NoTxV_df.index, 2030)[0]
ye = sc.findinds(NoTxV_df.index, 2060)[0]
NoTxV_cancers = np.sum(np.array(NoTxV_df['cancers'])[ys:ye])
NoTxV_cancers_low = np.sum(np.array(NoTxV_df['cancers_low'])[ys:ye])
NoTxV_cancers_high = np.sum(np.array(NoTxV_df['cancers_high'])[ys:ye])
NoTxV_cancer_deaths_short = np.sum(np.array(NoTxV_df['cancer_deaths'])[ys:ye])
NoTxV_cancer_deaths_short_low = np.sum(np.array(NoTxV_df['cancer_deaths_low'])[ys:ye])
NoTxV_cancer_deaths_short_high = np.sum(np.array(NoTxV_df['cancer_deaths_high'])[ys:ye])
for i_eff, txvx_efficacy in enumerate(txvx_efficacies):
for i_age, txvx_age in enumerate(txvx_ages):
txvx_scen_label_age = f'Mass TxV, {txvx_efficacy}, age {txvx_age}'
TxV_df = bigdf[(bigdf.screen_scen == screen_scen_label) & (bigdf.vx_scen == vx_scen_label)
& (bigdf.txvx_scen == txvx_scen_label_age)].groupby(
'year')[
['asr_cancer_incidence', 'asr_cancer_incidence_low', 'asr_cancer_incidence_high',
'cancers', 'cancers_low', 'cancers_high', 'cancer_deaths', 'cancer_deaths_low', 'cancer_deaths_high',
'n_tx_vaccinated']].sum()
TxV_econdf_cancers = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == txvx_scen_label_age)].groupby('year')[
['new_cancers', 'new_cancer_deaths']].sum()
TxV_econdf = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == txvx_scen_label_age)].groupby('year')[
['av_age_cancer_deaths', 'av_age_cancers']].mean()
if discounting:
cancers = np.array([i / 1.03 ** t for t, i in enumerate(TxV_econdf_cancers['new_cancers'].values)])
cancer_deaths = np.array(
[i / 1.03 ** t for t, i in enumerate(TxV_econdf_cancers['new_cancer_deaths'].values)])
else:
cancers = TxV_econdf_cancers['new_cancers'].values
cancer_deaths = TxV_econdf_cancers['new_cancer_deaths'].values
avg_age_ca_death = np.mean(TxV_econdf['av_age_cancer_deaths'])
avg_age_ca = np.mean(TxV_econdf['av_age_cancers'])
ca_years = avg_age_ca_death - avg_age_ca
yld = np.sum(np.sum([0.54 * .1, 0.049 * .5, 0.451 * .3, 0.288 * .1]) * ca_years * cancers)
yll = np.sum((standard_le - avg_age_ca_death) * cancer_deaths)
daly_TxV = yll + yld
dalys_averted = daly_noTxV - daly_TxV
TxV_cancers = np.sum(np.array(TxV_df['cancers'])[ys:ye])
TxV_cancers_low = np.sum(np.array(TxV_df['cancers_low'])[ys:ye])
TxV_cancers_high = np.sum(np.array(TxV_df['cancers_high'])[ys:ye])
best_TxV_cancer_deaths_short = np.sum(np.array(TxV_df['cancer_deaths'])[ys:ye])
best_TxV_cancer_deaths_short_high = np.sum(np.array(TxV_df['cancer_deaths_high'])[ys:ye])
best_TxV_cancer_deaths_short_low = np.sum(np.array(TxV_df['cancer_deaths_low'])[ys:ye])
averted_cancer_deaths_short = NoTxV_cancer_deaths_short - best_TxV_cancer_deaths_short
averted_cancer_deaths_short_high = NoTxV_cancer_deaths_short_high - best_TxV_cancer_deaths_short_high
averted_cancer_deaths_short_low = NoTxV_cancer_deaths_short_low - best_TxV_cancer_deaths_short_low
TxV_cancers_averted = NoTxV_cancers - TxV_cancers
TxV_cancers_averted_low = NoTxV_cancers_low - TxV_cancers_low
TxV_cancers_averted_high = NoTxV_cancers_high - TxV_cancers_high
if i_eff + ib == 0:
axes[0].scatter(xes[i_eff][ib], TxV_cancers_averted, marker=markers[i_age], color=colors[i_eff],
s=300, label=f'Age {txvx_age}')
else:
axes[0].scatter(xes[i_eff][ib], TxV_cancers_averted, marker=markers[i_age], color=colors[i_eff],
s=300)
if ib + i_age == 0:
axes[1].scatter(xes[i_eff][ib], averted_cancer_deaths_short, marker=markers[i_age], color=colors[i_eff], s=300,
label=txvx_efficacy)
else:
axes[1].scatter(xes[i_eff][ib], averted_cancer_deaths_short, marker=markers[i_age], color=colors[i_eff], s=300)
axes[0].vlines(xes[i_eff][ib], ymin=TxV_cancers_averted_low, color=colors[i_eff], ymax=TxV_cancers_averted_high)
axes[2].scatter(xes[i_eff][ib], dalys_averted, marker=markers[i_age], color=colors[i_eff], s=300)
axes[1].vlines(xes[i_eff][ib], ymin=averted_cancer_deaths_short_low, ymax=averted_cancer_deaths_short_high, color=colors[i_eff])
ib_labels = background_scens.keys()
axes[2].set_xticks([r + 1.5*width for r in range(len(r2))], ib_labels)
axes[0].get_xaxis().set_visible(False)
axes[1].get_xaxis().set_visible(False)
sc.SIticks(axes[0])
sc.SIticks(axes[1])
sc.SIticks(axes[2])
axes[0].set_ylabel(f'Cervical cancer cases averted\n(2030-2060)')
axes[2].set_ylabel(f'DALYs averted (2030-2060)')
axes[1].set_ylabel(f'Cervical cancer deaths averted\n(2030-2060)')
axes[0].legend(title='Age of TxV')
axes[1].legend(title='TxV Effectiveness')
axes[2].set_xlabel('Background intervention scenario')
fig.tight_layout()
fig_name = f'{figfolder}/txv_impact.png'
fig.savefig(fig_name, dpi=100)
return
def plot_txv_impact_combined_v2(locations=None, background_scens=None, txvx_ages=None, txvx_efficacies=None, discounting=False):
set_font(size=24)
dfs = sc.autolist()
econdfs = sc.autolist()
for location in locations:
df = sc.loadobj(f'{resfolder}/{location}.obj')
dfs += df
econ_df = sc.loadobj(f'{resfolder}/{location}_econ.obj')
econdfs += econ_df
econdf = pd.concat(econdfs)
bigdf = pd.concat(dfs)
colors = sc.gridcolors(20)
width = 0.2
standard_le = 88.8
r1 = np.arange(len(background_scens))
r2 = [x + width for x in r1]
r3 = [x + width for x in r2]
r4 = [x + width for x in r3]
xes = [r1, r2, r3, r4]
markers = ['s', 'v', 'P', '*', '+', 'D', '^', 'x']
fig = pl.figure(constrained_layout=True, figsize=(22, 16))
spec2 = GridSpec(ncols=3, nrows=2, figure=fig)
ax1 = fig.add_subplot(spec2[:-1, :])
ax2 = fig.add_subplot(spec2[-1, 0])
ax3 = fig.add_subplot(spec2[-1, 1])
ax4 = fig.add_subplot(spec2[-1, 2])
for ib, (background_scen_label, background_scen) in enumerate(background_scens.items()):
vx_scen_label = background_scen['vx_scen']
screen_scen_label = background_scen['screen_scen']
NoTxV_df = bigdf[(bigdf.screen_scen == screen_scen_label) & (bigdf.vx_scen == vx_scen_label)
& (bigdf.txvx_scen == 'No TxV')].groupby('year')[
['cancers', 'cancers_low', 'cancers_high', 'cancer_deaths', 'cancer_deaths_low', 'cancer_deaths_high', 'n_tx_vaccinated']].sum()
NoTxV_econdf_cancers = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == 'No TxV')].groupby('year')[
['new_cancers', 'new_cancer_deaths']].sum()
NoTxV_econdf = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == 'No TxV')].groupby('year')[
['av_age_cancer_deaths', 'av_age_cancers']].mean()
if discounting:
cancers = np.array([i / 1.03 ** t for t, i in enumerate(NoTxV_econdf_cancers['new_cancers'].values)])
cancer_deaths = np.array([i / 1.03 ** t for t, i in enumerate(NoTxV_econdf_cancers['new_cancer_deaths'].values)])
else:
cancers = NoTxV_econdf_cancers['new_cancers'].values
cancer_deaths = NoTxV_econdf_cancers['new_cancer_deaths'].values
avg_age_ca_death = np.mean(NoTxV_econdf['av_age_cancer_deaths'])
avg_age_ca = np.mean(NoTxV_econdf['av_age_cancers'])
ca_years = avg_age_ca_death - avg_age_ca
yld = np.sum(np.sum([0.54 * .1, 0.049 * .5, 0.451 * .3, 0.288 * .1]) * ca_years * cancers)
yll = np.sum((standard_le-avg_age_ca_death) * cancer_deaths)
daly_noTxV = yll + yld
ys = sc.findinds(NoTxV_df.index, 2030)[0]
ye = sc.findinds(NoTxV_df.index, 2060)[0]
NoTxV_cancers = np.sum(np.array(NoTxV_df['cancers'])[ys:ye])
NoTxV_cancers_low = np.sum(np.array(NoTxV_df['cancers_low'])[ys:ye])
NoTxV_cancers_high = np.sum(np.array(NoTxV_df['cancers_high'])[ys:ye])
years = np.array(NoTxV_df.index)[ys:ye]
NoTxV_cancer_deaths_short = np.sum(np.array(NoTxV_df['cancer_deaths'])[ys:ye])
NoTxV_cancer_deaths_short_low = np.sum(np.array(NoTxV_df['cancer_deaths_low'])[ys:ye])
NoTxV_cancer_deaths_short_high = np.sum(np.array(NoTxV_df['cancer_deaths_high'])[ys:ye])
for i_eff, txvx_efficacy in enumerate(txvx_efficacies):
for i_age, txvx_age in enumerate(txvx_ages):
txvx_scen_label_age = f'Mass TxV, {txvx_efficacy}, age {txvx_age}'
TxV_df = bigdf[(bigdf.screen_scen == screen_scen_label) & (bigdf.vx_scen == vx_scen_label)
& (bigdf.txvx_scen == txvx_scen_label_age)].groupby(
'year')[
['asr_cancer_incidence', 'asr_cancer_incidence_low', 'asr_cancer_incidence_high',
'cancers', 'cancers_low', 'cancers_high', 'cancer_deaths', 'cancer_deaths_low', 'cancer_deaths_high',
'n_tx_vaccinated']].sum()
cancers_averted = np.array(NoTxV_df['cancers'])[ys:ye] - np.array(TxV_df['cancers'])[ys:ye]
cancers_averted_low = np.array(NoTxV_df['cancers_low'])[ys:ye] - np.array(TxV_df['cancers_low'])[ys:ye]
cancers_averted_high = np.array(NoTxV_df['cancers_high'])[ys:ye] - np.array(TxV_df['cancers_high'])[
ys:ye]
ax1.plot(years, cancers_averted, color=colors[ib+1], linewidth=3, label=background_scen_label)
ax1.fill_between(years, cancers_averted_low, cancers_averted_high, color=colors[ib+1], alpha=0.3)
TxV_econdf_cancers = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == txvx_scen_label_age)].groupby('year')[
['new_cancers', 'new_cancer_deaths']].sum()
TxV_econdf = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == txvx_scen_label_age)].groupby('year')[
['av_age_cancer_deaths', 'av_age_cancers']].mean()
if discounting:
cancers = np.array([i / 1.03 ** t for t, i in enumerate(TxV_econdf_cancers['new_cancers'].values)])
cancer_deaths = np.array(
[i / 1.03 ** t for t, i in enumerate(TxV_econdf_cancers['new_cancer_deaths'].values)])
else:
cancers = TxV_econdf_cancers['new_cancers'].values
cancer_deaths = TxV_econdf_cancers['new_cancer_deaths'].values
avg_age_ca_death = np.mean(TxV_econdf['av_age_cancer_deaths'])
avg_age_ca = np.mean(TxV_econdf['av_age_cancers'])
ca_years = avg_age_ca_death - avg_age_ca
yld = np.sum(np.sum([0.54 * .1, 0.049 * .5, 0.451 * .3, 0.288 * .1]) * ca_years * cancers)
yll = np.sum((standard_le - avg_age_ca_death) * cancer_deaths)
daly_TxV = yll + yld
dalys_averted = daly_noTxV - daly_TxV
TxV_cancers = np.sum(np.array(TxV_df['cancers'])[ys:ye])
TxV_cancers_low = np.sum(np.array(TxV_df['cancers_low'])[ys:ye])
TxV_cancers_high = np.sum(np.array(TxV_df['cancers_high'])[ys:ye])
best_TxV_cancer_deaths_short = np.sum(np.array(TxV_df['cancer_deaths'])[ys:ye])
best_TxV_cancer_deaths_short_high = np.sum(np.array(TxV_df['cancer_deaths_high'])[ys:ye])
best_TxV_cancer_deaths_short_low = np.sum(np.array(TxV_df['cancer_deaths_low'])[ys:ye])
averted_cancer_deaths_short = NoTxV_cancer_deaths_short - best_TxV_cancer_deaths_short
averted_cancer_deaths_short_high = NoTxV_cancer_deaths_short_high - best_TxV_cancer_deaths_short_high
averted_cancer_deaths_short_low = NoTxV_cancer_deaths_short_low - best_TxV_cancer_deaths_short_low
TxV_cancers_averted = NoTxV_cancers - TxV_cancers
TxV_cancers_averted_low = NoTxV_cancers_low - TxV_cancers_low
TxV_cancers_averted_high = NoTxV_cancers_high - TxV_cancers_high
if i_eff + ib == 0:
ax2.scatter(xes[i_eff][ib], TxV_cancers_averted, marker=markers[i_age], color='b',
s=300, label=f'{txvx_age}')
else:
ax2.scatter(xes[i_eff][ib], TxV_cancers_averted, marker=markers[i_age], color='b',
s=300)
ax3.scatter(xes[i_eff][ib], averted_cancer_deaths_short, marker=markers[i_age], color='b', s=300)
ax2.vlines(xes[i_eff][ib], ymin=TxV_cancers_averted_low, color='b', ymax=TxV_cancers_averted_high)
ax4.scatter(xes[i_eff][ib], dalys_averted, marker=markers[i_age], color='b', s=300)
ax3.vlines(xes[i_eff][ib], ymin=averted_cancer_deaths_short_low, ymax=averted_cancer_deaths_short_high, color='b')
ib_labels = background_scens.keys()
ax2.set_xticks([r + 1.5*width for r in range(len(r2))], ib_labels)
ax3.set_xticks([r + 1.5 * width for r in range(len(r2))], ib_labels)
ax4.set_xticks([r + 1.5 * width for r in range(len(r2))], ib_labels)
# axes[0].get_xaxis().set_visible(False)
# axes[1].get_xaxis().set_visible(False)
ax2.set_ylim(bottom=0)
ax3.set_ylim(bottom=0)
ax4.set_ylim(bottom=0)
sc.SIticks(ax1)
sc.SIticks(ax2)
sc.SIticks(ax3)
sc.SIticks(ax4)
ax1.set_ylabel(f'Cervical cancer cases averted')
ax2.set_ylabel(f'Cervical cancer cases averted (2030-2060)')
ax3.set_ylabel(f'Cervical cancer deaths averted (2030-2060)')
ax4.set_ylabel(f'DALYs averted (2030-2060)')
# ax2.legend(title='Age of TxV')
ax1.legend(title='Background intervention scale-up')
ax2.set_xlabel('Background intervention scenario')
ax3.set_xlabel('Background intervention scenario')
ax4.set_xlabel('Background intervention scenario')
fig.tight_layout()
fig_name = f'{figfolder}/txv_impactv2.png'
fig.savefig(fig_name, dpi=100)
return
def plot_txv_impact_comparison(locations=None, background_scens=None, txvx_ages=None, txvx_efficacies=None,
do_run=True, discounting=False):
if do_run:
dfs = sc.autolist()
for location in locations:
dt_dfs = sc.autolist()
dt = an.dwelltime_by_genotype(start_year=2000)
calib_par_stem = '_nov13'
calib_pars = sc.loadobj(f'results/{location}_pars{calib_par_stem}.obj')
sim = rs.run_sim(location=location, calib_pars=calib_pars, end=2020, n_agents=50e3, analyzers=[dt])
dt_res = sim.analyzers[0]
dt_df = pd.DataFrame()
dt_df['Age'] = dt_res.age_causal
dt_df['Health event'] = 'Infection'
dt_df['location'] = location
dt_dfs += dt_df
dt_df = pd.DataFrame()
dt_df['Age'] = dt_res.age_cin
dt_df['Health event'] = 'CIN'
dt_df['location'] = location
dt_dfs += dt_df
dt_df = pd.DataFrame()
dt_df['Age'] = dt_res.age_cancer
dt_df['Health event'] = 'Cancer'
dt_df['location'] = location
dt_dfs += dt_df
df = pd.concat(dt_dfs)
dfs += df
set_font(size=24)
econdfs = sc.autolist()
for location in locations:
econ_df = sc.loadobj(f'{resfolder}/{location}_econ.obj')
econdfs += econ_df
econdf = pd.concat(econdfs)
colors = sc.gridcolors(20)
width = 0.2
standard_le = 88.8
r1 = np.arange(len(background_scens))
r2 = [x + width for x in r1]
r3 = [x + width for x in r2]
r4 = [x + width for x in r3]
xes = [r1, r2, r3, r4]
markers = ['s', 'v', 'P', '*', '+', 'D', '^', 'x']
fig, axes = pl.subplots(ncols=2, nrows=2, sharey='row', figsize=(16, 16))
for iloc, location in enumerate(locations):
sns.violinplot(x="Health event",
y="Age",
data=dfs[iloc], ax=axes[0,iloc])
for ib, (background_scen_label, background_scen) in enumerate(background_scens.items()):
vx_scen_label = background_scen['vx_scen']
screen_scen_label = background_scen['screen_scen']
NoTxV_econdf_cancers = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == 'No TxV') & (econdf.location == location)].groupby('year')[
['new_cancers', 'new_cancer_deaths']].sum()
NoTxV_econdf = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == 'No TxV') & (econdf.location == location)].groupby('year')[
['av_age_cancer_deaths', 'av_age_cancers']].mean()
if discounting:
cancers = np.array([i / 1.03 ** t for t, i in enumerate(NoTxV_econdf_cancers['new_cancers'].values)])
cancer_deaths = np.array([i / 1.03 ** t for t, i in enumerate(NoTxV_econdf_cancers['new_cancer_deaths'].values)])
else:
cancers = NoTxV_econdf_cancers['new_cancers'].values
cancer_deaths = NoTxV_econdf_cancers['new_cancer_deaths'].values
avg_age_ca_death = np.mean(NoTxV_econdf['av_age_cancer_deaths'])
avg_age_ca = np.mean(NoTxV_econdf['av_age_cancers'])
ca_years = avg_age_ca_death - avg_age_ca
yld = np.sum(np.sum([0.54 * .1, 0.049 * .5, 0.451 * .3, 0.288 * .1]) * ca_years * cancers)
yll = np.sum((standard_le-avg_age_ca_death) * cancer_deaths)
daly_noTxV = yll + yld
for i_eff, txvx_efficacy in enumerate(txvx_efficacies):
for i_age, txvx_age in enumerate(txvx_ages):
txvx_scen_label_age = f'Mass TxV, {txvx_efficacy}, age {txvx_age}'
TxV_econdf_cancers = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == txvx_scen_label_age) & (econdf.location == location)].groupby('year')[
['new_cancers', 'new_cancer_deaths']].sum()
TxV_econdf = econdf[(econdf.screen_scen == screen_scen_label) & (econdf.vx_scen == vx_scen_label)
& (econdf.txvx_scen == txvx_scen_label_age) & (econdf.location == location)].groupby('year')[
['av_age_cancer_deaths', 'av_age_cancers']].mean()
if discounting:
cancers = np.array([i / 1.03 ** t for t, i in enumerate(TxV_econdf_cancers['new_cancers'].values)])
cancer_deaths = np.array(
[i / 1.03 ** t for t, i in enumerate(TxV_econdf_cancers['new_cancer_deaths'].values)])
else:
cancers = TxV_econdf_cancers['new_cancers'].values
cancer_deaths = TxV_econdf_cancers['new_cancer_deaths'].values
avg_age_ca_death = np.mean(TxV_econdf['av_age_cancer_deaths'])
avg_age_ca = np.mean(TxV_econdf['av_age_cancers'])
ca_years = avg_age_ca_death - avg_age_ca
yld = np.sum(np.sum([0.54 * .1, 0.049 * .5, 0.451 * .3, 0.288 * .1]) * ca_years * cancers)