LSEM with categorical indicators

76 views
Skip to first unread message

Christopher Bratt

unread,
Apr 3, 2019, 11:34:00 AM4/3/19
to lavaan
This question might be difficult for the group to answer, since I use another package in addition to lavaan, namely the sirt package. The sirt package can run something called local structural equation models, repeating CFA models many times, using lavaan to estimate models. 

Problem is, I am unable to run the model if indicators are ordinal. Lavaan is able to run such models, so if sirt uses lavaan, I don't quite understand where the problem is. 

Here is a description of the function lsem.estimate in sirt:


My CFA model (only ordinal indicators) runs fine in lavaan, but when using lsem.estimate to call lavaan I get an error once I declare the items to be ordinal:

Error in lm.wfit(x, y, w, offset = offset, singular.ok = singular.ok,  : 
  NA/NaN/Inf in 'y'
In addition: Warning messages:
1: In model.response(mf, "numeric") :
  using type = "numeric" with a factor response will be ignored
2: In Ops.ordered(y, wts) :
 
 Error in lm.wfit(x, y, w, offset = offset, singular.ok = singular.ok,  : 
  NA/NaN/Inf in 'y' 

I'm sorry, I'm not very familiar with R, but I am trying to move from Mplus to lavaan. I have previously run similar analyses with Mplus. 


Christopher

Mauricio Garnier-Villarreal

unread,
Apr 3, 2019, 1:14:55 PM4/3/19
to lavaan
Christopher

It seems the lsem.estimate function has the dots (...) argument for extra lavaan arguments. With this you should be able to add the ordered=variables, and estimator="wlsmv arguments so the lavaan models would identify the desired variables as ordered and use WLSMV for estimation
Message has been deleted

Christopher Bratt

unread,
Apr 4, 2019, 10:33:51 AM4/4/19
to lavaan
Thank you so much for that!
Unfortunately, I'm still stuck.

Adding estimator='wlsmv' and defining variables as ordinal within the lavaan function (rather than prior to calling lavaan), seemed to help. At least lavaan tried to estimate models but then it reported that ML is not available for ordered data.

Input:

test <- lsem.estimate(datafile, moderator="age", moderator.grid=seq(20,80,1),
              lavmodel
=sem.model, h=2, estimator='wlsmv',
              ordered
=c("var1", "var1", "var3", "var4", "var5", "var6"))


Lavaan reports an error:

Error in lav_options_set(opt) :
  lavaan ERROR
: estimator ML for ordered data is not supported yet. Use WLSMV instead.
In addition: Warning message:
In lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats,  :
 
Error in lav_options_set(opt) :
  lavaan ERROR
: estimator ML for ordered data is not supported yet. Use WLSMV instead.


So asking for estimator='wlsmv' in the code is not sufficient. I'll try to make this work somehow. 

Terrence Jorgensen

unread,
Apr 4, 2019, 10:51:19 AM4/4/19
to lavaan
So asking for estimator='wlsmv' in the code is not sufficient. I'll try to make this work somehow. 

WLSMV is not an estimator.  The argument estimator='wlsmv' is just a shortcut for simultaneously setting the following three arguments:

estimator = "DWLS"
se
= "robust"
test
= "scaled.shifted"
# see ?lavOptions help page


Try specifying these instead of estimator='wlsmv'


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

Christopher Bratt

unread,
Apr 4, 2019, 11:39:59 AM4/4/19
to lavaan
Thanks. 

But using 

test <- lsem.estimate(datafile, moderator="age", moderator.grid=seq(20,80,1),

              lavmodel
=sem.model, h=2, estimator = "DWLS", se = "robust",
              test
= "scaled.shifted",

              ordered
=c("var1", "var1", "var3", "var4", "var5", "var6"))



still gives

Mauricio Garnier-Villarreal

unread,
Apr 4, 2019, 11:57:42 AM4/4/19
to lavaan
If you see the function help https://rdrr.io/cran/sirt/man/lsem.estimate.html in the last example they use DWLS, without correcting the test statistics and standard error. Maybe try only with DWLS as the estimator, without changing test and se. If this still doesnt work you will need to contract the developers of sirt, on having these features add

Also, in the DWLS example they change the residualize=FALSE, which by default is TRUE

Christopher Bratt

unread,
Apr 4, 2019, 12:06:52 PM4/4/19
to lavaan
I will continue trying to fix it and report back later, with a positive or a negative outcome. 
Thanks for all your kind help!

Christopher

Christopher Bratt

unread,
Apr 4, 2019, 1:23:35 PM4/4/19
to lavaan
All well now. 
Thanks a lot to Mauricio and Terrence!

Chr.
Reply all
Reply to author
Forward
0 new messages