I believe this fixes a bug that was a tricky one to find, related to observed variables that appear at the within level but not at the between level.
In computing Sigma.W, the within-only variables were being centered by group means. But I believe that all the variance of within-only variables should be attributed to the within level, so we should center by grand mean instead of group mean. The blavaan models under development also work better (better sampling and agreement with lavaan) with this change.
There might be some matrix trick to replace the loop that I added, but I couldn't immediately think of a good way to do it.
Thanks. You are right. This bug could stay hidden for a long time for the simple reason that lavaan re-estimates Sigma.W and Sigma.B using the EM algorithm later.
I believe this fixes a bug that was a tricky one to find, related to observed variables that appear at the within level but not at the between level.
In computing Sigma.W, the within-only variables were being centered by group means. But I believe that all the variance of within-only variables should be attributed to the within level, so we should center by grand mean instead of group mean. The blavaan models under development also work better (better sampling and agreement with lavaan) with this change.
There might be some matrix trick to replace the loop that I added, but I couldn't immediately think of a good way to do it.