Closed bschneidr closed 2 years ago
The issue was that the loop over first-stage units was using a loop based on the total number of PSUs in the design, not the total number of PSUs in the current subset of data.
arma::colvec h_first_stage_units = first_stage_ids.elem(h_indices);
arma::colvec h_unique_psus = unique(h_first_stage_units);
arma::uword n_h = min(first_stage_strata_samp_sizes.elem(h_indices));
double N_h = static_cast<double>(min(strata_pop_sizes.elem(h_indices)));
double f_h;
if (arma::is_finite(N_h)) {
f_h = static_cast<double>(n_h) / N_h;
} else {
f_h = 0.0;
}
for (arma::uword i=0; i < n_h; ++i ) {
Fixed by changing the loop to the following:
// Get list of PSUs in the current subset of data, and count them
arma::colvec h_first_stage_units = first_stage_ids.elem(h_indices);
arma::colvec h_unique_first_stage_units = unique(h_first_stage_units);
arma::uword n_h_subset = h_unique_first_stage_units.n_elem;
for (arma::uword i=0; i < n_h_subset; ++i ) {
Reproducible example:
Created on 2022-05-06 by the reprex package (v2.0.0)
Debugging of just
fastsurvey::arma_multistage()
:Created on 2022-05-06 by the reprex package (v2.0.0)