From c3f5422e3929d6dec2c700abf4ac76e56342cb0b Mon Sep 17 00:00:00 2001 From: "Ryan M. Moore" Date: Thu, 11 Jun 2026 10:42:20 -0400 Subject: [PATCH] Fix off-by-1 indexing bug (#154) Take EMburn = 3, and EMiter = 6. Originally, we're indexing from (3+1):(6+1) -> 4:7 -> c(4, 5, 6, 7). The first item is the init value. The next three c(2, 3, 4) are in the burn section, and the final three c(5, 6, 7) are in the keep section. However, we're pulling in the final one in the burn section. So it should be EMburn + 2. See https://github.com/adw96/DivNet/issues/154. --- R/fit_aitchison.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/fit_aitchison.R b/R/fit_aitchison.R index 82ab620..54b958a 100644 --- a/R/fit_aitchison.R +++ b/R/fit_aitchison.R @@ -174,7 +174,7 @@ fit_aitchison <- function(W, cat("\n") ## Next: take average of EM samples past burn. Included init, so have EMiter+1 total - b0_EM <- colMeans(b0_list[(EMburn + 1):(EMiter + 1), ]) + b0_EM <- colMeans(b0_list[(EMburn + 2):(EMiter + 1), ]) output_list$beta0 <- b0_EM @@ -182,7 +182,7 @@ fit_aitchison <- function(W, if (no_covariates) { fitted_y <- matrix(b0_EM, ncol = Q-1, nrow = N, byrow=T) } else { - b_list_reduced <- b_list[, , (EMburn + 1):(EMiter + 1)] + b_list_reduced <- b_list[, , (EMburn + 2):(EMiter + 1)] if (length(dim(b_list_reduced)) == 2) { b_list_reduced <- b_list_reduced %>% array(c(1, dim(b_list_reduced))) @@ -196,7 +196,7 @@ fit_aitchison <- function(W, } # burn-in sigma and take average; fine b/c class of positive def matrices is closed under addition - sigma_em <- apply(sigma_list[, , (EMburn + 1):(EMiter + 1)], c(1, 2), mean) + sigma_em <- apply(sigma_list[, , (EMburn + 2):(EMiter + 1)], c(1, 2), mean) # store parameters output_list$sigma <- sigma_em