Mplus to lavaan comparison

667 views
Skip to first unread message

Harold Doran

unread,
Oct 9, 2015, 9:57:40 AM10/9/15
to lavaan
I continue to have some struggles in using the cfa() function with my data. As some benchmarking, we have estimated what we think are the same models in Mplus in which case we are very successful in fitting the models under various constraints. I'm certain the errors are in my setup as lavaan is well-tested. So I'm looking to see if there are folks who speak Mplus and also lavaan and can see if my R code is structured to estimate the same model as what we are estimating in Mplus

The model parameter estimates from lavaan are wildy different than what we estimate under Mplus under similar parameterizations, and lavaan is even giving negative variances for some of the latent factors. The Mplus output is identified and very sensible with respect to apriori expectations.

First, I can represent my model as follows (use semPaths() to visualize the model as shown below)

library(lavaan)
library(semPlot)

secondModel <- '
Rep1_OANBT =~ 1*i_14453 + i_15701 + i_15709 + i_15723 + i_15747 + i_15756 + i_15770 + i_15777 + i_15833 + i_15838 + i_15842 + i_15843 + i_15862 + i_15869 + i_15872 + i_15874 + i_15879 + i_15884 + i_15887 + i_15888 + i_15890 + i_15896 + i_16215 + i_16229 + i_21409 + i_21410
Rep2_NF =~ 1*i_15725 + i_15783 + i_15813 + i_16223 + i_16242 + i_16244 + i_16259 + i_16260 + i_16250
Rep3_G3MDG =~ 1* i_15711 + i_15755 + i_15856 + i_15901 + i_16208 + i_16224 + i_16225 + i_16226 + i_16232 + i_16261 + i_16267 + i_16272 + i_16275 + i_16287 + i_16291 + i_21404 + i_15677 + i_15717 + i_15851
Rep1_OANBT ~~ Rep2_NF
Rep1_OANBT ~~ Rep3_G3MDG
Rep2_NF ~~ Rep3_G3MDG
trait =~ Rep1_OANBT + Rep2_NF + Rep3_G3MDG
trait ~~ 1 * trait
'
semPaths(secondModel, title = F)

In this model I have items that load onto three first order latent factors and then those 3 factors load onto a common underlying factor. The constraints are set such that the loading of the first item on each first order factor is fixed at 1 and the variance of the common factor (trait) is also fixed at 1.

I then run this model as

test <- cfa(secondModel, dat, mimic = 'Mplus', ordered = names(dat), estimator = 'WLS', parameterization = 'delta')

I set this model up in Mplus using the code below

  TITLE:    test model
  DATA:    FILE IS g3m.txt;
  VARIABLE:    NAMES ARE u1-u54;
              CATEGORICAL ARE u1-u54;
          MISSING ARE ALL (-999);
  ANALYSIS: estimator=WLS;
  MODEL:
          f1 BY u1 u2-u26;
          f2 BY u27 u28-u36;
          f3 BY u37 u38-u54;
            C BY f1* f2 f3;
          C@1;

  OUTPUT: sampstat STDYX tech4 mod(0);

Thank you for your assistance.

Harold

Mauricio Garnier-Villarreal

unread,
Oct 9, 2015, 9:27:28 PM10/9/15
to lavaan

Hi

Here are the edits to make the models equivakent

secondModel <- '
Rep1_OANBT =~ 1*i_14453 + i_15701 + i_15709 + i_15723 + i_15747 + i_15756 + i_15770 + i_15777 + i_15833 + i_15838 + i_15842 + i_15843 + i_15862 + i_15869 + i_15872 + i_15874 + i_15879 + i_15884 + i_15887 + i_15888 + i_15890 + i_15896 + i_16215 + i_16229 + i_21409 + i_21410 

Rep2_NF =~ 1*i_15725 + i_15783 + i_15813 + i_16223 + i_16242 + i_16244 + i_16259 + i_16260 + i_16250 

Rep3_G3MDG =~ 1* i_15711 + i_15755 + i_15856 + i_15901 + i_16208 + i_16224 + i_16225 + i_16226 + i_16232 + i_16261 + i_16267 + i_16272 + i_16275 + i_16287 + i_16291 + i_21404 + i_15677 + i_15717 + i_15851 

### you need to fix these covariances to 0 since the relation between these constructs is going to be estimated from the factor loadings for the trait factors
Rep1_OANBT ~~ 0*Rep2_NF 
Rep1_OANBT ~~ 0*Rep3_G3MDG 
Rep2_NF ~~ 0*Rep3_G3MDG 

### you need to free the first factor loaidng since lavaan by deafault will fix it to 1
trait =~ NA*Rep1_OANBT + Rep2_NF + Rep3_G3MDG

trait ~~ 1 * trait
trait ~0*1 ## just to be sure I would explicitly fix the factor mean to 0, you may want to check Mplus is fixing the mean of C at 0
'
I think these changes should make the models equivalent

test <- cfa(secondModel, dat, mimic = 'Mplus', ordered = names(dat), estimator = 'WLS', parameterization = 'delta')

For estimators, I would recommend to use WLSMV

Hope it helps

--- Mauricio

yrosseel

unread,
Oct 10, 2015, 4:43:14 AM10/10/15
to lav...@googlegroups.com
On 10/09/2015 03:57 PM, Harold Doran wrote:

> Rep1_OANBT ~~ Rep2_NF
> Rep1_OANBT ~~ Rep3_G3MDG
> Rep2_NF ~~ Rep3_G3MDG

What is the purpose of this part? This will create free parameters for
the residual covariances between the first-order factors. But the
whole point of having a second-order factor is that you 'explain' these
covariances by postulating a common cause, so you either need to remove
these (=fixing them to zero), or remove the second-order factor.

> trait =~ Rep1_OANBT + Rep2_NF + Rep3_G3MDG
> trait ~~ 1 * trait

This will (by default) fix the first factor loading of 'Rep1_OANBT' to
one; to free up this factor loading (you already fix the variance of the
trait factor), you need to write

trait =~ NA*Rep1_OANBT + Rep2_NF + Rep3_G3MDG

Yves.
Reply all
Reply to author
Forward
0 new messages