Skip to content

Potential off-by-1 bug in fit_aitchison.R #154

Description

@mooreryan

Hey y'all, I think I may have found a potential off by one indexing bug in fit_aitchison.R:

I believe these three should all be (EMburn + 2):(EMiter + 1).

E.g., for EMburn <- 3 and EMiter <- 6, the first item is the init, next three are EM iters in the burn in stage, next three are EM iters past the burn in stage. But as written these would all be indexing (3+1):(6+1) -> 4:7 -> c(4, 5, 6, 7). That is the last EM iter in the burn stage, and the three after the burn stage. Doing (EMburn + 2):(EMiter + 1) instead gives you the 5, 6, and 7, which are only the EM iters past the burn in which is what it should be if I'm not mistaken.


Here's where the things are initialized for reference:

In all three cases the first item is the "init". Here is b_list and b0_list being initialized before the EM loop starts:

DivNet/R/fit_aitchison.R

Lines 103 to 114 in 63908cf

b0_list <- matrix(0, nrow = EMiter + 1, ncol = length(b0))
b0_list[1,] <- b0
if (!no_covariates) {
if (is.matrix(b)) {
b_list <- array(0, dim = c(dim(b), EMiter + 1))
b_list[,, 1] <- b
} else {
b_list <- matrix(0, nrow = length(b), ncol = EMiter + 1)
b_list[, 1] <- b
}
}

And here is sigma_list:

DivNet/R/fit_aitchison.R

Lines 117 to 118 in 63908cf

sigma_list <- array(0, dim = c(dim(sigma), EMiter + 1))
sigma_list[, , 1] <- sigma

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions