forked from MGH-MPEC/CEPAC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCostStats.cpp
More file actions
426 lines (359 loc) · 17.5 KB
/
Copy pathCostStats.cpp
File metadata and controls
426 lines (359 loc) · 17.5 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
#include "include.h"
/** \brief Constructor takes run name and associated simulation context pointer as parameters
*
* \param runName a string representing the run name associated with this costStats object
* \param simContext a pointer to the SimContext representing the inputs associated with this CostSTats object*/
CostStats::CostStats(string runName, SimContext *simContext) {
costStatsFileName = runName;
costStatsFileName.append(CepacUtil::FILE_EXTENSION_FOR_COSTS_OUTPUT);
this->simContext = simContext;
/** Initialize the statistics subclasses */
initCostPopulationSummary();
initAllStats();
initEventStats();
}
/** \brief Destructor */
CostStats::~CostStats(void) {
} /* end Destructor */
/** \brief finalizeStats calculate all aggregate statistics and values to be outputted
*
* The finalize functions calculate all averages and standard deviations.
*
* Calls:
* - CostStats::finalizeCostPopulationSummary();
*/
void CostStats::finalizeStats() {
finalizeCostPopulationSummary();
finalizeAllStats();
finalizeEventStats();
}; /* end finalizeStats */
/** \brief writeStatsFile outputs all statistics to the stats file
*
* * Calls:
* - CostStats::writeCostPopulationSummary();
*/
void CostStats::writeStatsFile() {
CepacUtil::changeDirectoryToResults();
costStatsFile = CepacUtil::openFile(costStatsFileName.c_str(), "w");
if (costStatsFile == NULL) {
costStatsFileName.append("-tmp");
costStatsFile = CepacUtil::openFile(costStatsFileName.c_str(), "w");
if (costStatsFile == NULL) {
string errorString = " ERROR - Could not write cost stats or temporary stats file";
throw errorString;
}
}
writeCostPopulationSummary();
writeAllStats(SimContext::COST_REPORT_DISCOUNTED);
writeAllStats(SimContext::COST_REPORT_UNDISCOUNTED);
writeEventStats();
CepacUtil::closeFile(costStatsFile);
} /* end writeStatsFile */
/** \brief initCostPopulationSummary initializes the CostPopulationSummary object */
void CostStats::initCostPopulationSummary() {
popSummary.numPatients = 0;
popSummary.numPatientsHIVPositive = 0;
popSummary.numDetected = 0;
popSummary.numInCare = 0;
for (int i = 0; i < SimContext::ART_NUM_LINES; i++){
popSummary.numEverOnART[i] = 0;
}
for (int i = 0; i < SimContext::CD4_NUM_STRATA; i++){
popSummary.observedCD4DistributionAtLinkage[i] = 0;
popSummary.observedCD4DistributionAtARTStart[i] = 0;
}
for (int i = 0; i < SimContext::GENDER_NUM; i++){
popSummary.genderDistributionAtLinkage[i] = 0;
popSummary.genderDistributionAtARTStart[i] = 0;
}
for (int i = 0; i < SimContext::LINKAGE_STATS_AGE_CAT_NUM; i++){
popSummary.ageDistributionAtLinkage[i] = 0;
popSummary.ageDistributionAtARTStart[i] = 0;
}
}
/** \brief initAllStats initializes the AllStats object */
void CostStats::initAllStats() {
for (int i = 0; i < SimContext::COST_REPORT_DISCOUNT_NUM; i++){
for (int j = 0; j < SimContext::COST_CD4_STRATA_NUM; j++){
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++){
allStats[i][j][k].LMs = 0.0;
allStats[i][j][k].costs = 0.0;
allStats[i][j][k].costsART = 0.0;
allStats[i][j][k].costsOIProph = 0.0;
allStats[i][j][k].costsTBProph = 0.0;
allStats[i][j][k].costsCD4Testing = 0.0;
allStats[i][j][k].costsHVLTesting = 0.0;
allStats[i][j][k].costsInterventionStartup = 0.0;
allStats[i][j][k].costsInterventionMonthly = 0.0;
allStats[i][j][k].costsClinicVisit = 0.0;
allStats[i][j][k].costsRoutineCare = 0.0;
allStats[i][j][k].costsGeneralMedicine = 0.0;
allStats[i][j][k].costsOITreatment = 0.0;
allStats[i][j][k].costsOIUntreated = 0.0;
allStats[i][j][k].costsToxicity = 0.0;
allStats[i][j][k].costsDeath = 0.0;
allStats[i][j][k].costsHIVScreeningTests = 0.0;
allStats[i][j][k].costsHIVScreeningMisc = 0.0;
allStats[i][j][k].costsLabStagingTests = 0.0;
allStats[i][j][k].costsLabStagingMisc = 0.0;
allStats[i][j][k].costsTBTreatment = 0.0;
for (int l = 0; l < SimContext::COST_NUM_TYPES; l++){
allStats[i][j][k].costsCD4TestingCategory[l] = 0.0;
allStats[i][j][k].costsHVLTestingCategory[l] = 0.0;
allStats[i][j][k].costsClinicVisitCategory[l] = 0.0;
allStats[i][j][k].costsRoutineCareCategory[l] = 0.0;
allStats[i][j][k].costsGeneralMedicineCategory[l] = 0.0;
allStats[i][j][k].costsOITreatmentCategory[l] = 0.0;
allStats[i][j][k].costsOIUntreatedCategory[l] = 0.0;
allStats[i][j][k].costsDeathCategory[l] = 0.0;
}
}
}
}
}
/** \brief initEventStats initializes the EventStats object */
void CostStats::initEventStats() {
for (int j = 0; j < SimContext::COST_CD4_STRATA_NUM; j++){
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++){
eventStats[j][k].numToxicityCases = 0;
eventStats[j][k].numTBInfections = 0;
eventStats[j][k].numOIEvents = 0;
eventStats[j][k].numDeaths = 0;
eventStats[j][k].numCD4Tests = 0;
eventStats[j][k].numHVLTests = 0;
eventStats[j][k].numClinicVisits = 0;
eventStats[j][k].numHIVTests = 0;
eventStats[j][k].numLabStagingTests = 0;
}
}
}
/** \brief finalizeCostPopulationSummary calculates aggregate statistics for the CostPopulationSummary object */
void CostStats::finalizeCostPopulationSummary() {
}
/** \brief finalizeAllStats calculates aggregate statistics for the Allstats object */
void CostStats::finalizeAllStats() {
}
/** \brief finalizeEventStats calculates aggregate statistics for the Eventstats object */
void CostStats::finalizeEventStats() {
}
/** \brief writeCostPopulationSummary outputs the CostPopulationSummary statistics to the cost stats file */
void CostStats::writeCostPopulationSummary() {
int i,j;
// Print out the section header
fprintf(costStatsFile, "CEPAC COST SUMMARY");
// General Population statistics
fprintf (costStatsFile, "\n\t\tTotal\tEver HIV+\tEver Detected\tEver in Care\tEver on 1st line ART\tEver on 2nd line ART");
fprintf (costStatsFile, "\n\tNum Patients\t%d\t%d\t%d\t%d\t%d\t%d", popSummary.numPatients,
popSummary.numPatientsHIVPositive,
popSummary.numDetected,
popSummary.numInCare,
popSummary.numEverOnART[0],
popSummary.numEverOnART[1]);
// Observed CD4 dist
fprintf (costStatsFile, "\n\tObserved CD4 Distribution");
for (j = SimContext::CD4_NUM_STRATA - 1; j >= 0; --j)
fprintf(costStatsFile, "\t%s", SimContext::CD4_STRATA_STRS[j]);
fprintf (costStatsFile, "\n\tPatients in Linkage Month");
for (j = SimContext::CD4_NUM_STRATA - 1; j >= 0; --j)
fprintf(costStatsFile, "\t%d", popSummary.observedCD4DistributionAtLinkage[j]);
fprintf (costStatsFile, "\n\tPatients in ART Initiation Month");
for (j = SimContext::CD4_NUM_STRATA - 1; j >= 0; --j)
fprintf(costStatsFile, "\t%d", popSummary.observedCD4DistributionAtARTStart[j]);
// gender dist
fprintf (costStatsFile, "\n\tGender Distribution");
for (j = 0; j < SimContext::GENDER_NUM; j++)
fprintf(costStatsFile, "\t%s", SimContext::GENDER_STRS[j]);
fprintf (costStatsFile, "\n\tPatients in Linkage Month");
for (j = 0; j < SimContext::GENDER_NUM; j++)
fprintf(costStatsFile, "\t%d", popSummary.genderDistributionAtLinkage[j]);
fprintf (costStatsFile, "\n\tPatients in ART Initiation Month");
for (j = 0; j < SimContext::GENDER_NUM; j++)
fprintf(costStatsFile, "\t%d", popSummary.genderDistributionAtARTStart[j]);
//Age dist
fprintf (costStatsFile, "\n\tAge Distribution");
for (j = 0; j < SimContext::LINKAGE_STATS_AGE_CAT_NUM; j++)
fprintf(costStatsFile, "\t%s", SimContext::LINKAGE_STATS_AGE_CAT_STRS[j]);
fprintf (costStatsFile, "\n\tPatients in Linkage Month");
for (j = 0; j < SimContext::LINKAGE_STATS_AGE_CAT_NUM; j++)
fprintf(costStatsFile, "\t%d", popSummary.ageDistributionAtLinkage[j]);
fprintf (costStatsFile, "\n\tPatients in ART Initiation Month");
for (j = 0; j < SimContext::LINKAGE_STATS_AGE_CAT_NUM; j++)
fprintf(costStatsFile, "\t%d", popSummary.ageDistributionAtARTStart[j]);
}
/** \brief writeAllstats outputs the AllStats statistics to the cost stats file */
void CostStats::writeAllStats(SimContext::COST_REPORT_DISCOUNT disc) {
for (int j = SimContext::COST_CD4_STRATA_NUM-1; j >= 0; j--){
if (disc == SimContext::COST_REPORT_DISCOUNTED)
fprintf(costStatsFile, "\n\nDiscounted\tDiscounting Rate\t%1.2lf\tObsv CD4\t%s", simContext->getRunSpecsInputs()->originalDiscRate, SimContext::COST_CD4_STRATA_STRS[j]);
else
fprintf(costStatsFile, "\n\nUndiscounted\tObsv CD4\t%s", SimContext::COST_CD4_STRATA_STRS[j]);
fprintf(costStatsFile, "\n\t");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%s", SimContext::COST_SUBGROUPS_STRS[k]);
//total patient months
fprintf(costStatsFile, "\n\tTotal Patient Mths");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].LMs);
//total costs
fprintf(costStatsFile, "\n\tTotal Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costs);
//ART Costs
fprintf(costStatsFile, "\n\tART Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsART);
//OI proph costs
fprintf(costStatsFile, "\n\tOI Prophylaxis Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsOIProph);
//TB proph costs
fprintf(costStatsFile, "\n\tTB Prophylaxis Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsTBProph);
//Intervention costs
fprintf(costStatsFile, "\n\tIntervention Startup Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsInterventionStartup);
fprintf(costStatsFile, "\n\tIntervention Monthly Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsInterventionMonthly);
//CD4 Test costs
fprintf(costStatsFile, "\n\tCD4 Test Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsCD4Testing);
for (int l = 0; l < SimContext::COST_NUM_TYPES; l++){
fprintf(costStatsFile, "\n\tCD4 Test Costs %s", SimContext::COST_TYPES_STRS[l]);
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsCD4TestingCategory[l]);
}
//HVL Test costs
fprintf(costStatsFile, "\n\tHVL Test Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsHVLTesting);
for (int l = 0; l < SimContext::COST_NUM_TYPES; l++){
fprintf(costStatsFile, "\n\tHVL Test Costs %s", SimContext::COST_TYPES_STRS[l]);
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsHVLTestingCategory[l]);
}
//Clinic Visit costs
fprintf(costStatsFile, "\n\tClinic Visit Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsClinicVisit);
for (int l = 0; l < SimContext::COST_NUM_TYPES; l++){
fprintf(costStatsFile, "\n\tClinic Visit Costs %s", SimContext::COST_TYPES_STRS[l]);
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsClinicVisitCategory[l]);
}
//Routine care costs
fprintf(costStatsFile, "\n\tRoutine Care Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsRoutineCare);
for (int l = 0; l < SimContext::COST_NUM_TYPES; l++){
fprintf(costStatsFile, "\n\tRoutine Care Costs %s", SimContext::COST_TYPES_STRS[l]);
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsRoutineCareCategory[l]);
}
//General Medicine
fprintf(costStatsFile, "\n\tGeneral Medicine Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsGeneralMedicine);
for (int l = 0; l < SimContext::COST_NUM_TYPES; l++){
fprintf(costStatsFile, "\n\tGeneral Medicine Costs %s", SimContext::COST_TYPES_STRS[l]);
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsGeneralMedicineCategory[l]);
}
//Acute OI Treatment
fprintf(costStatsFile, "\n\tOI Treatment Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsOITreatment);
for (int l = 0; l < SimContext::COST_NUM_TYPES; l++){
fprintf(costStatsFile, "\n\tOI Treatment Costs %s", SimContext::COST_TYPES_STRS[l]);
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsOITreatmentCategory[l]);
}
fprintf(costStatsFile, "\n\tUntreated Acute OI Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsOIUntreated);
for (int l = 0; l < SimContext::COST_NUM_TYPES; l++){
fprintf(costStatsFile, "\n\tUntreated Acute OI Costs %s", SimContext::COST_TYPES_STRS[l]);
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsOIUntreatedCategory[l]);
}
//Toxicity Costs
fprintf(costStatsFile, "\n\tToxicity Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsToxicity);
//Death Costs
fprintf(costStatsFile, "\n\tDeath Costs");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsDeath);
for (int l = 0; l < SimContext::COST_NUM_TYPES; l++){
fprintf(costStatsFile, "\n\tDeath Costs %s", SimContext::COST_TYPES_STRS[l]);
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsDeathCategory[l]);
}
//Screening Costs
fprintf(costStatsFile, "\n\tHIV Screening Tests Cost");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsHIVScreeningTests);
fprintf(costStatsFile, "\n\tHIV Screening Misc Cost");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsHIVScreeningMisc);
//Lab Staging Costs
fprintf(costStatsFile, "\n\tLab Staging Tests Cost");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsLabStagingTests);
fprintf(costStatsFile, "\n\tLab Staging Misc Cost");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsLabStagingMisc);
//TB Treatment Costs
fprintf(costStatsFile, "\n\tTB Treatment Cost");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%1.2lf", allStats[disc][j][k].costsTBTreatment);
}
}/* End writeAllStats */
/** \brief writeEventstats outputs the EventStats statistics to the cost stats file */
void CostStats::writeEventStats() {
for (int j = 0; j < SimContext::COST_CD4_STRATA_NUM; j++){
fprintf(costStatsFile, "\n\n\tObsv CD4\t%s", SimContext::COST_CD4_STRATA_STRS[j]);
fprintf(costStatsFile, "\n\t");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%s", SimContext::COST_SUBGROUPS_STRS[k]);
//Toxicity Cases
fprintf(costStatsFile, "\n\tToxicity Event Quantity");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%d", eventStats[j][k].numToxicityCases);
//Tb Events
fprintf(costStatsFile, "\n\tTB Event Quantity");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%d", eventStats[j][k].numTBInfections);
//OI Events
fprintf(costStatsFile, "\n\tOI Event Quantity");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%d", eventStats[j][k].numOIEvents);
//Death Events
fprintf(costStatsFile, "\n\tDeaths");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%d", eventStats[j][k].numDeaths);
//Num CD4 Tests
fprintf(costStatsFile, "\n\tNum CD4 Tests");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%d", eventStats[j][k].numCD4Tests);
//Num HVL Tests
fprintf(costStatsFile, "\n\tNum HVL Tests");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%d", eventStats[j][k].numHVLTests);
//Num Clinic Visits
fprintf(costStatsFile, "\n\tNum Clinic Visits");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%d", eventStats[j][k].numClinicVisits);
//Num HIV Tests
fprintf(costStatsFile, "\n\tNum HIV Tests");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%d", eventStats[j][k].numHIVTests);
//Num Lab Staging Tests
fprintf(costStatsFile, "\n\tNum Lab Staging Tests");
for (int k = 0; k < SimContext::COST_SUBGROUPS_NUM; k++)
fprintf(costStatsFile, "\t%d", eventStats[j][k].numLabStagingTests);
}
}