approximate MI with more than 2 groups

25 views
Skip to first unread message

J S

unread,
Oct 2, 2025, 9:11:51 AMOct 2
to blavaan
Hey,

I want to analyze measurement invariance in blavaan for following model: 

workvalue_mod_4<-'
enhan =~ pow_res_1 + stat_5 + stat_6 + ach_adv_4
open  =~ self_act_2 + stim_var_1 + hed_pl_3 + hed_com_2
trans =~ benev_car_8 + equi_acc_3 + equi_adv_8 + sust_env_3
cons  =~ trad_soc_8 + trad_org_1 + conf_inter_5 + conf_form_7
'

Utilizing the wiggle parameter I am able to conduct approximate MI testing for variables contains two groups (e.g. dichotomous gender). However, when I try to analyze approximate MI between variables with >2 groups (e.g. educational levels) I receive following error: 

> # wiggle .05
> bfit4_education1 <- bcfa(model = workvalue_mod_4, data = valuedata_stud4, group = "education_cat1",
+                          group.equal = "loadings", wiggle = "loadings",
+                          wiggle.sd = 0.05, std.lv = TRUE)
Error in rowvec[samppar] <- which(grepl(stanvec[j], names(b.est)) & !(grepl("_c\\[",  :
  replacement has length zero

education_cat1 contains following groups and n's:
Ausbm   HoR   Abi    BA    MA Ausbo
  621  1443   411   521   732  1417

I would appreciate every help I can get! 

Thanks in advance!
Jannick

Ed Merkle

unread,
Oct 2, 2025, 6:17:01 PMOct 2
to blavaan
Jannick,

Thanks for the report. Is there any more output that appears between the bcfa() command and the "Error in rowvec" line? If yes, please post it because it might be informative about what is going on.

Ed

J S

unread,
Oct 3, 2025, 3:04:26 AMOct 3
to blavaan
Hey Ed,

thanks for your answer, but unfortunately no (see attached as a screenshot). The model without constraints runs perfectly fine (bfit4_education0 <- bcfa(workvalue_mod_4, data = valuedata_stud4, group = "education_cat1", std.lv = TRUE, seed=1108048325)), as does the exact MGCFA approach (fit4_education2<-lavaan::cfa(workvalue_mod_4, data=valuedata_stud4, std.lv=TRUE, estimator="MLR", meanstructure=TRUE, group="education_cat1", group.equal="loadings")) and the grouping variable education_cat1 has no missing values.

Bildschirmfoto 2025-10-03 um 08.59.12.png

Best regards,
Jannick

Ed Merkle

unread,
Oct 3, 2025, 12:24:47 PMOct 3
to J S, blavaan
Thanks for following up. It is a little strange because that error typically arises when the Stan sampling does not finish correctly. But then there is usually Stan output before the error. I also tried the wiggle argument on a different 3-group dataset without an error. If you can share the data (even if only with myself off list) and code, that could help me reproduce the error.

I also still suspect there might be more on-screen output than what you are seeing. Maybe your software is gobbling up the extra output and only showing the error message. If you are using Rstudio or Positron or etc, maybe try to run the same model in R outside of those other programs. Then look for more output before the error message.

Ed


On Fri, 2025-10-03 at 00:04 -0700, 'J S' via blavaan wrote:
Hey Ed,

thanks for your answer, but unfortunately no (see attached as a screenshot). The model without constraints runs perfectly fine (bfit4_education0 <- bcfa(workvalue_mod_4, data = valuedata_stud4, group = "education_cat1", std.lv = TRUE, seed=1108048325)), as does the exact MGCFA approach (fit4_education2<-lavaan::cfa(workvalue_mod_4, data=valuedata_stud4, std.lv=TRUE, estimator="MLR", meanstructure=TRUE, group="education_cat1", group.equal="loadings")) and the grouping variable education_cat1 has no missing values.

--
You received this message because you are subscribed to the Google Groups "blavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blavaan+u...@googlegroups.com.

J S

unread,
Oct 7, 2025, 9:33:16 AMOct 7
to blavaan
Hey Ed,

I tried to run the script in R and indeed there is further output: > bfit4_education1 <- bcfa(model = workvalue_mod_4, data = valuedata_stud4, group = "education_cat1",

+                          group.equal = "loadings", wiggle = "loadings",
+                          wiggle.sd = 0.05, std.lv = TRUE)
Error in eval(mc, parent.frame()) :
  Exception: model_stanmarg_namespace::model_stanmarg: v10[2][5] is 0, but must be greater than or equal to 1.000000 (in 'stanmarg', line 639, column 2 to column 38)
failed to create the sampler; sampling not done
Computing post-estimation metrics (including lvs if requested)...
Stan model 'stanmarg' does not contain samples.

Error in rowvec[samppar] <- which(grepl(stanvec[j], names(b.est)) & !(grepl("_c\\[",  :
  replacement has length zero

Does this help to solve the issue? I can provide the data and code with you if needed. Thanks for the help so far!

Best regards, 
Jannick

Ed Merkle

unread,
Oct 7, 2025, 10:14:04 AMOct 7
to blavaan
Thanks, that helps and I believe the issue is already fixed in the github version of blavaan. (see the "Error when doing measurement invariance" topic in the google group)

To install the github version, see the details at the bottom of https://ecmerkle.github.io/blavaan/

Ed
Reply all
Reply to author
Forward
0 new messages