@@ -79,15 +79,15 @@ void impute_missing_bgmcompare(
7979 std::vector<arma::imat>& counts_per_category,
8080 std::vector<arma::imat>& blume_capel_stats,
8181 std::vector<arma::mat>& pairwise_stats,
82- const arma::imat & num_categories,
82+ const arma::ivec & num_categories,
8383 const arma::imat& missing_data_indices,
8484 const arma::uvec& is_ordinal_variable,
8585 const arma::ivec& baseline_category,
8686 SafeRNG& rng
8787) {
8888 const int num_variables = observations.n_cols ;
8989 const int num_missings = missing_data_indices.n_rows ;
90- const int max_num_categories = arma::max (arma::vectorise ( num_categories) );
90+ const int max_num_categories = arma::max (num_categories);
9191
9292 arma::vec category_response_probabilities (max_num_categories + 1 );
9393 double exponent, cumsum, u;
@@ -120,11 +120,12 @@ void impute_missing_bgmcompare(
120120
121121 double rest_score =
122122 arma::as_scalar (observations.row (person) * group_pairwise_effects.col (variable));
123+
123124 if (is_ordinal_variable[variable] == true ) {
124125 // For regular binary or ordinal variables
125126 cumsum = 1.0 ;
126127 category_response_probabilities[0 ] = 1.0 ;
127- for (int category = 1 ; category <= num_categories (variable, group ); category++) {
128+ for (int category = 1 ; category <= num_categories (variable); category++) {
128129 exponent = group_main_effects (category - 1 );
129130 exponent += category * rest_score;
130131 cumsum += MY_EXP (exponent);
@@ -133,7 +134,7 @@ void impute_missing_bgmcompare(
133134 } else {
134135 // For Blume-Capel variables
135136 cumsum = 0.0 ;
136- for (int category = 0 ; category <= num_categories (variable, group ); category++) {
137+ for (int category = 0 ; category <= num_categories (variable); category++) {
137138 exponent = group_main_effects[0 ] * category;
138139 exponent += group_main_effects[1 ] *
139140 (category - baseline_category[variable]) *
@@ -161,9 +162,9 @@ void impute_missing_bgmcompare(
161162 if (is_ordinal_variable[variable] == true ) {
162163 arma::imat counts_per_category_group = counts_per_category[group];
163164 if (old_observation > 0 )
164- counts_per_category_group (old_observation, variable)--;
165+ counts_per_category_group (old_observation- 1 , variable)--;
165166 if (new_observation > 0 )
166- counts_per_category_group (new_observation, variable)++;
167+ counts_per_category_group (new_observation- 1 , variable)++;
167168 counts_per_category[group] = counts_per_category_group;
168169 } else {
169170 arma::imat blume_capel_stats_group = blume_capel_stats[group];
0 commit comments