bug since new version?: se=robust.cluster

81 views
Skip to first unread message

Stephan Junker

unread,
Jun 8, 2020, 7:06:06 AM6/8/20
to lavaan
There seems to be a bug in the new version of lavaan (0.6-6). I have done the multiple group regression below in lavaan 0.6-3 without any problems but now get an error message concerning the standard erros.
You can finde some example data, code an error message below.

Thanks for the great package to all the contributers!

example <-
structure(list(cluster = c(1216551L, 1212750L, 1218932L, 1211959L, 
1218821L, 1211202L, 1217646L, 1210088L, 1217206L, 1215094L, 1214164L,
1213861L, 1210688L, 1210194L, 1214785L, 1211827L, 1215240L, 1217153L,
1218138L, 1217631L, 1215094L, 1210718L, 1217417L, 1215406L, 1213593L,
1218782L, 1212019L, 1212914L, 1219324L, 1215725L, 1217357L, 1218680L,
1217249L, 1219149L, 1219774L, 1215314L, 1210718L, 1217249L, 1212091L,
1213969L, 1216195L, 1215900L, 1210842L, 1211176L, 1212966L, 1216241L,
1217423L, 1214284L, 1213582L, 1218932L, 1214221L, 1212750L, 1210097L,
1211808L, 1215959L, 1219554L, 1217357L, 1216163L, 1213582L, 1217631L,
1210642L, 1210165L, 1215966L, 1212232L, 1212600L, 1214754L, 1214785L,
1216374L, 1215240L, 1210642L, 1218145L, 1212232L, 1218138L, 1210562L,
1211204L, 1213969L, 1212643L, 1210755L, 1219112L, 1210974L, 1215094L,
1212966L, 1212643L, 1213969L, 1212582L, 1215959L, 1217901L, 1214341L,
1211176L, 1215972L, 1212232L, 1216575L, 1215156L, 1212116L, 1210874L,
1211942L, 1219560L, 1217144L, 1215240L, 1216308L, 1214463L, 1216387L,
1217430L, 1215082L, 1210131L, 1216661L, 1215156L, 1214754L, 1212056L,
1211204L, 1217144L, 1219605L, 1215406L, 1211210L, 1210088L, 1214341L,
1215725L, 1213517L, 1211204L, 1211500L, 1218782L, 1213969L, 1210165L,
1211210L, 1211202L, 1215314L, 1216009L, 1217430L, 1217631L, 1212600L,
1211500L, 1212709L, 1215094L, 1216575L, 1214727L, 1214284L, 1213582L,
1215576L, 1212232L, 1216465L, 1215156L, 1210165L, 1211827L, 1213517L,
1217430L, 1216176L, 1217249L, 1216465L, 1215634L, 1211202L, 1216551L,
1215634L, 1215634L, 1214785L, 1216387L, 1216163L, 1216163L, 1216241L,
1213582L, 1219605L, 1215871L, 1217452L, 1216551L, 1216163L, 1210729L,
1212143L, 1219905L, 1214058L, 1216003L, 1210842L, 1217249L, 1215406L,
1215634L, 1211500L, 1217423L, 1215966L, 1212339L, 1217500L, 1217153L,
1213969L, 1214086L, 1216619L, 1210974L, 1216223L, 1217423L, 1219982L,
1213759L, 1212431L, 1214754L, 1211232L, 1217249L, 1215634L, 1217153L,
1218418L, 1217572L, 1216465L, 1218932L, 1212582L, 1212667L, 1215679L,
1212091L, 1212056L, 1212232L, 1219516L, 1215725L, 1213582L, 1214284L,
1219774L, 1218373L, 1213582L, 1219268L, 1215679L, 1214221L, 1216176L,
1218932L, 1215576L, 1219560L, 1213720L, 1214086L, 1218773L, 1217417L,
1218890L, 1216004L, 1215156L, 1219112L, 1219324L, 1212914L, 1218863L,
1210194L, 1217894L, 1215406L, 1213646L, 1213698L, 1219516L, 1212667L,
1216575L, 1219216L, 1216223L, 1211833L, 1219516L, 1210097L, 1210061L,
1210097L, 1212966L, 1216661L, 1219560L, 1212143L, 1212582L, 1215082L,
1218391L, 1216465L, 1218391L, 1216223L, 1219560L, 1217144L, 1212750L,
1219982L, 1216575L, 1212431L, 1219560L, 1217572L, 1219324L, 1216465L,
1217631L, 1213698L, 1218773L, 1216777L, 1211176L, 1210522L, 1215240L,
1217901L, 1213759L, 1215634L, 1210031L, 1216843L, 1219605L, 1210522L,
1211959L, 1218782L, 1217206L, 1215314L, 1211403L, 1215583L, 1213759L,
1211827L, 1211216L, 1216387L, 1210562L, 1210088L, 1213517L, 1218373L,
1215900L, 1215715L, 1219216L, 1216003L, 1212232L, 1210165L, 1219216L,
1215093L, 1210194L), group = structure(c(4L, 1L, 1L, 1L, 1L,
6L, 1L, 5L, 5L, 4L, 3L, 3L, 4L, 4L, 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3L, 3L, 3L, 4L, 4L, 3L, 6L,
3L, 4L, 3L, 2L, 2L, 6L, 2L, 4L, 5L, 4L, 5L, 2L, 1L, 1L, 6L, 6L,
3L, 6L, 4L, 3L, 1L, 4L, 5L), .Label = c("KiGGS baseline.boys",
"KiGGS wave 1.boys", "KiGGS wave 2.boys", "KiGGS baseline.girls",
"KiGGS wave 1.girls", "KiGGS wave 2.girls"), class = "factor"),
    weight
= c(0.748, 1.643, 1.738, 2.256, 1.39, 1.039049, 1.363,
   
0.71, 0.278, 0.479, 1.75635, 0.424747, 0.784, 0.885, 0.401,
   
2.761, 2.272, 0.145, 1.376533, 0.846, 1.279, 0.721, 0.353,
   
0.350872, 0.872, 0.941, 1.252, 1.906, 2.781, 0.579801, 1.05,
   
0.884, 0.726, 0.98626, 0.879, 0.944, 0.838, 2.025, 0.512,
   
1.675, 0.521, 0.298, 0.858, 0.610177, 0.479534, 2.716, 1.076,
   
0.34, 0.746, 4.495547, 2.175, 0.523466, 0.54173, 0.57, 0.934128,
   
1.429, 1.777, 0.975983, 0.271093, 0.84, 0.828, 0.972643,
   
0.184, 0.898, 0.932, 0.816, 0.691, 0.773, 1.717032, 0.35,
   
0.272, 1.084, 0.886, 2.416281, 0.478514, 4.046, 2.451, 0.221,
   
1.734, 0.448, 0.495, 0.621, 2.523893, 1.692, 1.296136, 0.688,
   
1.204867, 0.752, 1.406717, 0.594652, 1.126, 1.163, 0.488388,
   
0.622952, 0.490857, 1.313, 0.176891, 1.141, 0.542, 0.895,
   
1.885996, 0.952, 0.288519, 0.998647, 0.211, 0.410095, 0.720388,
   
1.997, 0.154, 1.679, 1.046, 0.3649, 0.371, 0.175, 3.336931,
   
0.751, 0.333203, 0.97, 3.115, 0.796146, 0.695, 1.065, 0.749,
   
0.135, 1.604, 1.818, 2.201, 0.147, 0.538155, 1.095, 0.672,
   
2.578, 0.845262, 1.375, 1.159, 0.493564, 0.282503, 0.957,
   
2.360684, 0.454013, 0.984, 0.767, 0.506, 0.836162, 0.417105,
   
1.626, 0.334, 0.560284, 0.519435, 1.415994, 1.914, 0.394791,
   
1.142, 0.756, 1.123, 0.787, 1.733964, 1.201784, 0.354825,
   
0.35148, 2.403, 1.546, 0.431, 1.016, 1.047, 0.662, 2.229074,
   
1.196944, 0.183968, 0.921822, 1.417, 1.315, 0.662693, 0.619,
   
0.79, 0.133, 0.444, 2.51, 0.427, 1.295, 0.709, 1.817, 1.306946,
   
0.841076, 1.80179, 0.608, 0.479, 0.227, 3.958422, 1.453,
   
1.771, 0.565018, 0.567, 1.145934, 0.382, 0.799837, 1.975776,
   
0.909, 0.276, 1.753, 0.186561, 0.137862, 0.986, 1.054853,
   
1.03, 0.240388, 1.213, 0.191534, 0.98522, 0.350949, 1.059,
   
1.061, 0.837, 0.991, 0.866, 1.515, 0.437, 3.893398, 0.189,
   
1.064, 0.31965, 0.657363, 0.729, 0.753, 1.264, 4.549, 0.891621,
   
2.225, 0.829, 1.526, 0.345, 1.189, 0.158029, 0.683, 0.747,
   
0.425448, 1.522, 1.006, 0.165, 2.143665, 0.674, 1.946, 0.436076,
   
0.265575, 0.449879, 0.418279, 0.819, 1.16, 0.821852, 0.713,
   
0.858, 1.051, 0.99, 0.307935, 1.352, 1.568886, 1.231436,
   
0.739, 0.286, 0.325997, 0.281, 1.501395, 1.422, 0.86128,
   
0.302, 0.886, 0.848, 1.561, 1.576, 1.14, 1.498008, 0.460689,
   
0.431643, 0.258, 1.658, 0.668756, 1.457878, 5.933396, 0.786,
   
0.795328, 1.972, 0.178, 0.592963, 1.849, 2.312, 0.126, 1.11,
   
1.246, 2.453, 0.444, 0.859, 0.505447, 1.017738, 0.782035,
   
0.12149, 1.849, 3.061805, 1.236, 1.182, 2.462), Y = c(17,
   
9, 7, 7, 12, 5, 9, 6, 4, 1, 5, 16, 12, 5, 6, 12, 23, 1, 16,
   
10, 5, 14, 10, 16, 7, 8, 9, 3, 10, 12, 7, 4, 8, 19, 9, 11,
   
12, 30, 17, 9, 10, 9, 12, 8, 3, 20, 9, 7, 8, 9, 4, 16, 10,
   
9, 11, 20, 7, 4, 8, 16, 7, 6, 12, 3, 10, 13, 11, 10, 10,
   
14, 5, 11, 6, 14, 8, 15, 5, 11, 5, 8, 13, 17, 23, 13, 13,
   
15, 8, 15, 10, 6, 17, 10, 10, 8, 6, 8, 9, 5, 4, 1, 13, 8,
   
11, 9, 2, 16, 9, 13, 6, 11, 3, 12, 12, 13, 6, 8, 15, 11,
   
12, 14, 4, 15, 13, 4, 9, 8, 13, 8, 7, 14, 0, 12, 11, 5, 6,
   
15, 16, 13, 5, 5, 11, 5, 7, 9, 10, 7, 13, 18, 11, 5, 8, 15,
   
8, 14, 8, 13, 7, 3, 8, 8, 2, 3, 8, 6, 6, 15, 17, 17, 17,
   
10, 8, 9, 7, 10, 11, 10, 0, 13, 7, 8, 9, 6, 4, 9, 9, 7, 12,
   
4, 13, 10, 10, 14, 7, 9, 9, 9, 6, 9, 6, 16, 9, 13, 6, 6,
   
10, 16, 7, 8, 11, 2, 5, 8, 9, 11, 4, 7, 8, 8, 4, 9, 8, 9,
   
12, 9, 8, 3, 19, 10, 4, 16, 20, 14, 10, 5, 14, 7, 5, 10,
   
1, 14, 7, 13, 4, 5, 13, 8, 7, 16, 4, 11, 7, 13, 7, 7, 9,
   
3, 11, 7, 3, 6, 13, 17, 12, 7, 11, 10, 6, 6, 8, 3, 8, 8,
   
10, 11, 19, 12, 1, 3, 8, 8, 4, 10, 7, 9, 13, 3, 9, 11, 4,
   
11, 2, 19, 3, 7, 21, 19, 8, 5, 11, 4), X = c(4, 3, 0, 4,
   
6, 2, 1, 0, 0, 2, 5, 0, 1, 1, 0, 5, 2, 6, 0, 2, 5, 0, 2,
   
3, 3, 6, 3, 6, 4, 0, 2, 6, 1, 5, 4, 6, 5, 6, 1, 5, 0, 5,
   
3, 2, 4, 0, 3, 2, 4, 5, 4, 5, 5, 2, 4, 6, 5, 2, 4, 5, 6,
   
1, 5, 0, 1, 3, 6, 0, 1, 2, 2, 4, 3, 6, 2, 2, 1, 1, 6, 3,
   
1, 2, 1, 2, 0, 2, 0, 2, 2, 2, 5, 5, 3, 4, 6, 6, 3, 3, 2,
   
3, 1, 0, 6, 5, 1, 3, 6, 0, 1, 1, 5, 1, 1, 0, 4, 4, 1, 6,
   
3, 3, 4, 2, 0, 5, 6, 2, 3, 3, 0, 5, 5, 1, 4, 5, 5, 3, 6,
   
6, 2, 1, 6, 3, 0, 6, 3, 4, 2, 5, 0, 0, 5, 0, 1, 4, 1, 3,
   
5, 2, 1, 6, 2, 4, 2, 5, 0, 4, 5, 6, 4, 4, 2, 4, 1, 1, 6,
   
4, 0, 3, 3, 1, 5, 0, 2, 2, 6, 4, 2, 0, 3, 3, 1, 3, 4, 5,
   
1, 6, 5, 4, 1, 1, 3, 1, 4, 0, 3, 4, 5, 3, 4, 6, 4, 2, 0,
   
1, 4, 1, 4, 1, 6, 5, 4, 1, 6, 1, 1, 0, 3, 5, 4, 3, 0, 6,
   
3, 3, 5, 3, 6, 4, 1, 5, 5, 1, 5, 0, 1, 6, 0, 5, 3, 3, 2,
   
6, 5, 4, 1, 0, 4, 6, 2, 3, 6, 6, 5, 5, 0, 2, 5, 5, 0, 4,
   
4, 0, 2, 2, 5, 4, 5, 6, 0, 5, 6, 6, 0, 4, 0, 6, 3, 3, 4,
   
3, 5, 3, 6, 4, 3, 1, 6, 4, 3, 1)), class = "data.frame", row.names = c(NA,
-300L))



model <- '# Pfade
              Y ~ c(a.2w, a.2m, a.1w, a.1m, a.0w, a.0m)*X
             
               #Intercepts
              Y ~ cc(i.2w, i.2m, i.1w, i.1m, i.0w, i.0m)*1
              '




sdq_fit
<- sem(data=example, model=model, group="group", cluster = "cluster", sampling.weights = "weight", estimator="GLS")


Error in lav_options_set(opt) : lavaan ERROR: invalid value for `se' argument when estimator is GLS: robust.cluster
6.
stop("lavaan ERROR: invalid value for `se' argument when estimator is GLS: ", opt$se, "\n")
5.
lav_options_set(opt)
4.
lavaan::lavaan(model = model, data = example, sampling.weights = "weight", group = "group", cluster = "cluster", estimator = "GLS", model.type = "sem", int.ov.free = TRUE, int.lv.free = FALSE, auto.fix.first = TRUE, auto.fix.single = TRUE, auto.var = TRUE, ...
3.
eval(mc, parent.frame())
2.
eval(mc, parent.frame())
1.
sem(data = example, model = model, group = "group", cluster = "cluster", sampling.weights = "weight", estimator = "GLS")

Yves Rosseel

unread,
Jun 9, 2020, 3:14:12 AM6/9/20
to lav...@googlegroups.com, stephan....@googlemail.com
On 6/8/20 1:06 PM, 'Stephan Junker' via lavaan wrote:
> sdq_fit <-sem(data=example,model=model,group="group",cluster
> ="cluster",sampling.weights ="weight",estimator="GLS")

When sampling.weights are used, the only available 'estimator' is MLR
(which is just ML, but with cluster-robust standard errors). lavaan
0.6-6 correctly detects that estimator = "GLS" is not compatible with se
= "robust.cluster". It would seem that lavaan failed to detect this in
earlier versions.

The solution is simple: remove estimator = "GLS", and lavaan will pick
the MLR estimator automatically.

Yves.
Reply all
Reply to author
Forward
0 new messages