|
x <- which(Lambda0[vars_cf, y] != 0) |
Through both the GSCA/GSCA_M and IGSCA code there are situations where which is used to index which elements are to be updated.
As far as I can tell, when the specified model is single-indicator or single-construct there are hard-to-detect situations where the indexing can be broken.
For example, take the following two data
Lambda0_A <- matrix(
c(0.4, 0.0,
0.0, 0.5),
nrow = 2,
byrow = TRUE,
dimnames = list(c("xi1", "xi2"), c("x11", "x21"))
)
vars_cf <- 'xi2'
This creates the following buggy behavior
which(Lambda0_A[vars_cf, 2] != 0)
which returns
This isn't correct because xi2 is in the second row.
Improved behavior may be found by running the following
(rowSums(Lambda0_A[vars_cf, 2, drop = FALSE]) != 0) |> which() |> names()
which returns
Which is semantically clearer.
Some other advantages is that as long as the arrays are named correctly, then this indexing should fail noisily, instead of silently, which is important for correctness.
I am applying this fix throughout in my #594
cSEM/R/estimators_weights.R
Line 439 in f544a2d
Through both the GSCA/GSCA_M and IGSCA code there are situations where
whichis used to index which elements are to be updated.As far as I can tell, when the specified model is single-indicator or single-construct there are hard-to-detect situations where the indexing can be broken.
For example, take the following two data
This creates the following buggy behavior
which returns
This isn't correct because
xi2is in the second row.Improved behavior may be found by running the following
which returns
Which is semantically clearer.
Some other advantages is that as long as the arrays are named correctly, then this indexing should fail noisily, instead of silently, which is important for correctness.
I am applying this fix throughout in my #594