ERROR: missing observed variables in dataset

899 views
Skip to first unread message

Heidi Wechtler

unread,
May 3, 2019, 12:45:49 PM5/3/19
to lavaan
Dear all,

I am trying to run a multilevel sem with meditation analysis.
Lavaan / cfa works well on the data. Estimated latent can be stored (predict option).
Yet, when I add the regression step, latent variables seem not to be recognized anymore.
I get the following message: ERROR: missing observed variables in dataset: rat evs dub wel (which are my latent variables used in the regressions)
Thank you for your help.

> modelsem <- '
+         level: 1
+             evs=~ KH1 + KH2 + KH3 + KH4
+        dub=~ KH5 + KH6 + KH7 + KH8
+        rat=~ KH9 + KH10 + KH11 + KH12
+             wel=~ PW1 + PW2 + PW3 + PW4 + PW5 + PW6 + PW7
+        wel~ a1*evs + a2*dub + a3*rat
+             evs~~dub
+             evs~~rat
+             dub~~rat
+         level: 2
+             rjp=~ IRP1 + IRP2 + IRP3 + IRP4 + IRP5
+        rjp~ c11*rat + c21*evs + c31*dub + b1*wel
+             inp=~ INN1 + INN2 + INN3 + INN4 + INN5 + INN6 + INN7
+        inp~ c12*rat + c22*evs + c32*dub + b2*wel
+         indirect := a1*b1
+         direct := c1
+         total := c1 + (a1*b1)
+     '
> fitsem <- sem(model = modelsem, data = know2, cluster = "supnumb")
Error in lav_data_full(data = data, group = group, cluster = cluster,  : 
  lavaan ERROR: missing observed variables in dataset: rat evs dub wel

Terrence Jorgensen

unread,
May 8, 2019, 5:35:29 AM5/8/19
to lavaan
when I add the regression step, latent variables seem not to be recognized anymore.

Because you haven't defined them in your level-2 model.

+         level: 2
+             rjp=~ IRP1 + IRP2 + IRP3 + IRP4 + IRP5
+        rjp~ c11*rat + c21*evs + c31*dub + b1*wel
+             inp=~ INN1 + INN2 + INN3 + INN4 + INN5 + INN6 + INN7
+        inp~ c12*rat + c22*evs + c32*dub + b2*wel

Level-1 and Level-2 models can be different (which is why you have a Level-2 factor rjp presumably defined by Level-2 indicators), so defining factors at Level 1 does not mean they are automatically defined at Level 2.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Reply all
Reply to author
Forward
0 new messages