@@ -63,20 +63,9 @@ void AnalysisModule::initialise_vector(RuntimeContext &context) {
63
63
// `factors` vector.
64
64
size_t num_stats_to_calc = context.mapping ().entries ().size () - factors_to_calculate_.size ();
65
65
66
- // But we calculate the mean and standard deviation of each factor, so we need to multiply by 2
67
- num_stats_to_calc *= 2 ;
68
-
69
- // We also want to calculate the prevalence and incidence of each disease
70
- num_stats_to_calc += 2 * context.diseases ().size ();
71
-
72
- // We also want to keep the count, deaths, and emigrations
73
- num_stats_to_calc += 3 ;
74
-
75
- // We also want to calculate the normal, overweight, obese, and above weight prevalence
76
- num_stats_to_calc += 4 ;
77
-
78
- // Finally, we want to calculate the mean and standard deviation of YLL, YLD, and DALY
79
- num_stats_to_calc += 6 ;
66
+ // And for each factor, we calculate the stats described in `stats_to_calculate_`, so we
67
+ // multiply the number of stats to calculate by the number of factors to calculate stats for.
68
+ num_stats_to_calc *= stats_to_calculate_.size ();
80
69
81
70
// The product of the number of bins for each factor can be used to calculate the size of the
82
71
// `calculated_stats_` in the next step
@@ -573,6 +562,37 @@ void AnalysisModule::initialise_output_channels(RuntimeContext &context) {
573
562
channels_.emplace_back (" std_daly" );
574
563
}
575
564
565
+ void AnalysisModule::initialise_stats_to_calc (RuntimeContext &context) {
566
+ if (!stats_to_calculate_.empty ()) {
567
+ return ;
568
+ }
569
+
570
+ stats_to_calculate_.push_back (" count" );
571
+ stats_to_calculate_.push_back (" deaths" );
572
+ stats_to_calculate_.push_back (" emigrations" );
573
+
574
+ for (const auto &factor : context.mapping ().entries ()) {
575
+ stats_to_calculate_.push_back (" mean_" + factor.key ().to_string ());
576
+ stats_to_calculate_.push_back (" std_" + factor.key ().to_string ());
577
+ }
578
+
579
+ for (const auto &disease : context.diseases ()) {
580
+ stats_to_calculate_.push_back (" prevalence_" + disease.code .to_string ());
581
+ stats_to_calculate_.push_back (" incidence_" + disease.code .to_string ());
582
+ }
583
+
584
+ stats_to_calculate_.push_back (" normal_weight" );
585
+ stats_to_calculate_.push_back (" over_weight" );
586
+ stats_to_calculate_.push_back (" obese_weight" );
587
+ stats_to_calculate_.push_back (" above_weight" );
588
+ stats_to_calculate_.push_back (" mean_yll" );
589
+ stats_to_calculate_.push_back (" std_yll" );
590
+ stats_to_calculate_.push_back (" mean_yld" );
591
+ stats_to_calculate_.push_back (" std_yld" );
592
+ stats_to_calculate_.push_back (" mean_daly" );
593
+ stats_to_calculate_.push_back (" std_daly" );
594
+ }
595
+
576
596
std::unique_ptr<AnalysisModule> build_analysis_module (Repository &repository,
577
597
const ModelInput &config) {
578
598
auto analysis_entity = repository.manager ().get_disease_analysis (config.settings ().country ());
0 commit comments