# Regression tests pinning fixed defects in imputation row bookkeeping, # group-difference labels, summary scales, and mixed-model sampling paths. # --------------------------------------------------------------------------- # imputation row indices follow the group-sorted row order # --------------------------------------------------------------------------- test_that("imputation targets the right rows when groups are interleaved", { # 6 people, 2 ordinal variables, groups interleaved (1,2,1,2,1,2). x = data.frame( V1 = c(NA, 1, 2, 0, 1, 2), V2 = c(2, 1, 0, NA, 1, 0) ) group_indicator = c(1, 2, 1, 2, 1, 2) spec = without_support_warning(bgm_spec( x = x, model_type = "compare", group_indicator = group_indicator, na_action = "impute", edge_selection = FALSE, difference_selection = FALSE, seed = 1 )) mi = spec$missing$missing_index # Group 1 people (rows 1,3,5) move to sorted rows 1,2,3; group 2 people # (rows 2,4,6) move to sorted rows 4,5,6. The missing cell for person 1 # is in sorted row 1 (0-based 0); the one for person 4 is in sorted row 5 # (0-based 4). Column order: V1 first, then V2. expect_equal(mi[, 1], c(0, 4)) expect_equal(mi[, 2], c(0, 1)) }) # --------------------------------------------------------------------------- # difference labels attached to the right parameter for 3+ groups # --------------------------------------------------------------------------- test_that("pairwise difference summaries carry the right labels for 3 groups", { skip_on_cran() set.seed(11) n_groups = 3 n_per_group = 20 p = 3 x = matrix(sample(0:2, n_groups * n_per_group * p, replace = TRUE), ncol = p) colnames(x) = paste0("V", seq_len(p)) group_indicator = rep(seq_len(n_groups), each = n_per_group) fit = without_support_warning(bgmCompare( x = x, group_indicator = group_indicator, difference_selection = TRUE, iter = 50, warmup = 50, chains = 1, seed = 3, display_progress = "none" )) actual = fit$posterior_summary_pairwise_differences$parameter # The rows run edge by edge (in i