Bifactor ESEM in R and Mplus7

3,723 views
Skip to first unread message

yleni...@gmail.com

unread,
Apr 8, 2016, 11:20:15 AM4/8/16
to lavaan
I attempted to run a bifactor ESEM model with orthogonal target rotation in R, and compared the results to Mplus. To do so, I ran a simulation and used a few packages.

The fit indices were identical to Mplus 7. The loadings were not exactly the same, but that may be due to differences between the GPArotation package and Mplus. I'm including the code and some output below (notice that in Mplus, the item order is a bit different).

Do you think this is a feasible / sensible way to run an ESEM model in R?



Here's the script:

#Bifactor ESEM in R
library(lavaan)
library(semTools)
library(GPArotation)
library(psych)

#Simulate data (Lavaan)
#One general factor and 2 specific factors
set.seed(123456)
sim.model <- 'g=~.4*i1+.4*i2+.4*i3+.4*i4+.4*i5+.4*i6+.4*i7+.4*i8+.4*i9+.4*i10
f1=~.5*i1+.5*i2+.5*i3+.5*i4+.5*i5
f2=~.6*i6+.6*i7+.6*i8+.6*i9+.6*i10
#orthogonal factors
g~~0*f1+0*f2
f1~~0*f2'
d <- simulateData(model=sim.model, model.type = "cfa", sample.nobs = 200)


#extract 4 factors: g + 3 specific factors (semTools)
fa.un <- efaUnrotate(d, nf = 3) 
#test model fit as you would in lavaan
fitMeasures(fa.un, c("chisq", "df", "pvalue", "cfi", "tli", "srmr", "rmsea", "rmsea.ci.lower", "rmsea.ci.upper", "bic"))

#Rotate using orthogonal target rotation (GPArotation package)
loadings <- inspect(fa.un, "std")$lambda #extract unrotated loadings
Targ <- make.keys(10,list(g=1:10,f1=1:5,f2=6:10)) #create a target matrix
x1 <- targetT(loadings, Target=Targ) #rotate loadings based on target
x1


#To compare these results in Mplus
library(MplusAutomation)
prepareMplusData(d, "ESEM in R data.dat") #data file for Mplus




#Input for Mplus7
#Code was adapted from Morin, A. J., Arens, A. K., & Marsh, H. W. (2015). A bifactor exploratory structural equation modeling framework for the identification of distinct sources of construct-relevant psychometric multidimensionality. Structural Equation Modeling: A Multidisciplinary Journal, 23.  http://www.tandfonline.com/doi/abs/10.1080/10705511.2014.961800 


TITLE: ESEM in Mpluls
DATA: FILE = "ESEM in R data.dat";
VARIABLE: 
NAMES = i1 i2 i3 i4 i5 i6 i7 i8 i9 i10; 
MISSING=.;
usevar =  i1-i10;
Analysis: ESTIMATOR = ML;
ROTATION = TARGET (orthogonal);

  Model:
  FG BY i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 (*1);
  F1 BY i1 i2 i3 i4 i5 i6~0 i7~0 i8~0 i9~0 i10~0 (*1);
  F2 BY i6 i7 i8 i9 i10 i1~0 i2~0 i3~0 i4~0 i5~0 (*1); 

OUTPUT: STDY;

Mplus rotated standardized loadings.png
R rotated standardized loadings.png

yleni...@gmail.com

unread,
Jun 1, 2016, 9:46:41 AM6/1/16
to lavaan

It's actually simpler than the example above (which has some typos). The fit indices and loadings are virtually identical to the ones in Mplus. The difference is that the signs of the loadings are opposite: Mplus shows most loadings as positive and few loadings as negative while funRotate shows the reverse pattern. 


Here's the script:


#Bifactor ESEM in R
library(semTools)
library(GPArotation)

#Simulate data (with lavaan)
#One general factor and 2 specific factors
set.seed(123456)
sim.model <- 'g=~.4*i1+.4*i2+.4*i3+.4*i4+.4*i5+.4*i6+.4*i7+.4*i8+.4*i9+.4*i10
f1=~.5*i1+.5*i2+.5*i3+.5*i4+.5*i5
f2=~.6*i6+.6*i7+.6*i8+.6*i9+.6*i10
#orthogonal factors
g~~0*f1+0*f2
f1~~0*f2'
d <- simulateData(model=sim.model, model.type = "cfa", sample.nobs = 200)


#extract 3 unrotated factors: g + 2 specific factors
unrotated <- efaUnrotate(d, nf = 3) 
summary(unrotated)
#test model fit as you would in lavaan
fitMeasures(unrotated, c("chisq", "df", "pvalue", "cfi", "tli", "srmr", "rmsea", "rmsea.ci.lower", "rmsea.ci.upper", "bic"))

#Create a target matrix
target <- matrix(0, 10, 3)
target[1:10, 1] <- NA #general factor
target[1:5, 2] <- NA #group factor
target[6:10, 3] <- NA #group factor
target


#Target rotation (orthogonal) 
rotated <- funRotate(unrotated, fun="targetT", Target=target)

#Output
round(rotated@loading, 3) 

Sunthud Pornprasertmanit

unread,
Jun 1, 2016, 10:32:31 AM6/1/16
to lavaan
The different sign does not really matter. It is the nature of factor indeterimancy. You may reverse the sign by hand.

CAUTION: SE resulting from factor rotation in semToools is currently invalid. It does not account for the instability of the results from factor rotation. It is just based on delta method. Therefore, please do not trust the standard error or test statistic of the rotated statistics.

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.

B-ESEM

unread,
Feb 10, 2018, 5:38:37 PM2/10/18
to lavaan
Hello!

I realize this is an old thread, but it is one of the few resources I could find containing Bifactor ESEM syntax in R. I have run ESEM and Bifactor ESEM in Mplus but I do not have access to a computer powerful enough to run them with the dataset I have.

Is anyone familiar with doing an ESEM or Bifactor ESEM in R? What package and syntax did you use? I have very unfamiliar with R and would appreciate any advice!

Thank you!

Terrence Jorgensen

unread,
Feb 12, 2018, 11:04:37 AM2/12/18
to lavaan
Is anyone familiar with doing an ESEM or Bifactor ESEM in R? 

ESEM was developed by the Mplus folks and some colleagues, so as far as I know, it is only available in Mplus.

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

MagunS...@gmail.com

unread,
Mar 15, 2018, 1:43:07 AM3/15/18
to lavaan
It is not only available in Mplus, you can do it yourself quite easily using lavaan. We are currently preparing a draft on a special use of ESEM and we have explored the possibilities to replicate the Mplus results and I can replicate the estimates up to the fourth digits and while it is still mysterious to me how they get their standard errors (which is because their description is very brief and I am still researching all the underlying steps that they silently assume), bootstrap standard errors are a _very_ good alternative for the models I tried. If you are interested, send me PM, I will give you the code and a description what it does. (I will update this post with the respective link to the implementation on the OSF once the paper is ready for submission, i.e., soon.) 

We are also planning on contributing our ESEM implementation to lavaan but it will need some further development (e.g., a reasonable user interface) before that. 

Terrence Jorgensen

unread,
Mar 15, 2018, 6:25:56 AM3/15/18
to lavaan
We are also planning on contributing our ESEM implementation to lavaan but it will need some further development (e.g., a reasonable user interface) before that. 

Would it be a reasonable contribution to the semTools package, which consists of many lavaan add-ons?  If interested, I can help you brainstorm about streamlining the user experience.  I don't have any experience with ESEM, but I would expect users to want to specify their confirmatory model and little else.  Perhaps if they fit a confirmatory model in lavaan, they can pass that object to an esem() function to automatically add exploratory/search parameters to update the model as ESEM.  Just an idea...

MagunS...@gmail.com

unread,
Mar 15, 2018, 1:47:43 PM3/15/18
to lavaan
As I said, I am happy to share our insights and contribute an implementation (to whatever package). Maybe, we should start a separate thread to discuss what is the most reasonable way to implement it? As this would be my first contribution at this level of complexity, I'd be happy to listen to as much advise as possible.

Terrence Jorgensen

unread,
Mar 18, 2018, 10:59:22 AM3/18/18
to lavaan
we should start a separate thread to discuss what is the most reasonable way to implement it

That's fine. You can also post a feature request by starting a new "issue" on github, if you have an account.  But if there is a thread here, perhaps others will offer recommendations, too.  

Jorge Sinval

unread,
Jul 30, 2018, 5:34:56 PM7/30/18
to lavaan
Any update on this implementation?

Yves Rosseel

unread,
Jul 31, 2018, 5:19:47 AM7/31/18
to lav...@googlegroups.com
No.

I do plan to take on 'efa' after my holidays. It may be a small step to
extend this to esem. Ask me again in a few months.

Yves.

On 07/30/2018 11:34 PM, Jorge Sinval wrote:
> Any update on this implementation?
>
> 2018 at 2:59:22 PM UTC, Terrence Jorgensen wrote:
>
> we should start a separate thread to discuss what is the most
> reasonable way to implement it
>
>
> That's fine. You can also post a feature request by starting a new
> "issue" on github <https://github.com/simsem/semTools/issues>, if
> you have an account.  But if there is a thread here, perhaps others
> will offer recommendations, too.
>
> Terrence D. Jorgensen
> Postdoctoral Researcher, Methods and Statistics
> Research Institute for Child Development and Education, the
> University of Amsterdam
> UvA web page: http://www.uva.nl/profile/t.d.jorgensen
> <http://www.uva.nl/profile/t.d.jorgensen>
>
> --
> You received this message because you are subscribed to the Google
> Groups "lavaan" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to lavaan+un...@googlegroups.com
> <mailto:lavaan+un...@googlegroups.com>.
> To post to this group, send email to lav...@googlegroups.com
> <mailto:lav...@googlegroups.com>.

Jorge Sinval

unread,
Jul 31, 2018, 5:51:40 AM7/31/18
to lav...@googlegroups.com
Sure! Looking forward to seeing ESEM and Bi-factor ESEM in lavaan.

Thanks!

You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/q7SRObGv1_c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.

santiago zarate guerrero

unread,
Aug 22, 2018, 1:39:13 PM8/22/18
to lavaan
Hi 
looking for an script to do ESEM in R. some update? 

Florian Scharf

unread,
Aug 22, 2018, 3:01:15 PM8/22/18
to lavaan
I've provided Yves with a working demonstration how to replicate the Mplus example in lavaan. I attach it. The point estimates are spot on, the SEs however are bootstrapped because I haven't yet worked out what the Mplus people do but bootstrapping works reasonably well for now and is quite flexible.

Disclaimer: Use at your own risk. The implementation of the bootstrap SEs is very quick and dirty and does not properly account for all sorts of indeterminacies that may occur in EFAs and ESEMs. I recommend not to proceed unless you feel that you really understand what's going on.
Archiv.zip

Pedro Saulo

unread,
Nov 29, 2018, 11:21:27 AM11/29/18
to lavaan
Any updates regarding this implementation?

Kabir Daljeet

unread,
Feb 13, 2019, 11:50:23 AM2/13/19
to lavaan
Hi I would also love to know if anyone has had any success with this recently? I found a post about ESEM in R here https://tkaiser.science/esemR.html but I haven't tried this out myself yet
 

Pedro Saulo

unread,
May 16, 2019, 8:26:27 PM5/16/19
to lavaan
Hello, 
does anyone have news about this old topic?

balal izanloo

unread,
May 17, 2019, 12:49:13 AM5/17/19
to lav...@googlegroups.com
Hi
Please look to this article and its related syntax in R and lavaan. look at to inside the article for how to access commands and it's supplementary. HTH



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

To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.

Kabir Daljeet

unread,
May 17, 2019, 12:56:43 AM5/17/19
to lavaan
This is great and all but it seems basically impossible for the everyday user to take this script and apply to their own research...


On Friday, May 17, 2019 at 12:49:13 AM UTC-4, balal izanloo wrote:
Hi
Please look to this article and its related syntax in R and lavaan. look at to inside the article for how to access commands and it's supplementary. HTH



On Fri, May 17, 2019 at 4:56 AM Pedro Saulo <pedros...@gmail.com> wrote:
Hello, 
does anyone have news about this old topic?

On Wednesday, February 13, 2019 at 2:50:23 PM UTC-2, Kabir Daljeet wrote:
Hi I would also love to know if anyone has had any success with this recently? I found a post about ESEM in R here https://tkaiser.science/esemR.html but I haven't tried this out myself yet
 

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

balal izanloo

unread,
May 17, 2019, 1:03:07 AM5/17/19
to lav...@googlegroups.com

To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.

To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
ESEM_implementation.R

Florian Scharf

unread,
May 17, 2019, 1:21:46 AM5/17/19
to lavaan
We are in active development of ESEM features but as always we cannot say when you can expect them to launch. As you can see from our article, we know exactly how to reproduce the Mplus point estimates. Standard errors are a little more tricky. We have made some good progress but it does not yet work sufficiently flexible for different types of models to invite you to an alpha test - so you need to hold on a bit longer but a user-friendly implementation is on the way.

Pedro Saulo

unread,
May 17, 2019, 7:13:09 AM5/17/19
to lavaan
Thank you all for the fast responses!

Terrence Jorgensen

unread,
May 17, 2019, 8:42:49 AM5/17/19
to lavaan
Bill Revelle released his take on ESEM in his psych package:


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

朱谦

unread,
Aug 11, 2019, 8:49:24 AM8/11/19
to lavaan
The esem function released in the the psych package is not the mplus-esem they are discussed above.
psych::esem can do some path analysis by using factor extension, but do not provide measurement model like mplus-esem.

在 2019年5月17日星期五 UTC+8下午8:42:49,Terrence Jorgensen写道:

Brian Peña Calero

unread,
Mar 10, 2021, 12:34:12 PM3/10/21
to lavaan
Hi. Any update at the moment?

Leon

unread,
May 12, 2021, 11:41:09 AM5/12/21
to lavaan
Also looking for an ESEM solution for lavaan such as is implemented in Mplus, for normal ESEM, bifactor SEM and H-ESEM. 

Does lavaan have some sort of bounty program, or is there someone here who would be able to complete a user-friendly function for lavaan as a wrapper or otherwise for a fee. I am willing to contribute to such a fund for the development of functions for lavaan of interest. It would of course remain open source, but I know peoples' time is important to them. 

We have created a tool for Mplus code by the way for all these models for those who might be interested: http://www.surveyhost.co.za/esem/

Thank you. 
Message has been deleted

Florian Scharf

unread,
May 13, 2021, 3:31:09 PM5/13/21
to lav...@googlegroups.com

sorry, here the missing attachment

--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/q7SRObGv1_c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/3d74560e-5a66-45fd-8da3-621dc1fdd290n%40googlegroups.com.
ex5.27.R
Message has been deleted
Message has been deleted

Dani Broxy

unread,
Jul 11, 2023, 12:14:00 PM7/11/23
to lavaan
It seems that lavaan can now do ESEM
However, is there an update to being able to run bifactor ESEM?

Leon de Beer

unread,
Jul 12, 2023, 3:33:43 AM7/12/23
to lav...@googlegroups.com
You can do bifactor-esem-within-cfa with the esemComp package that creates the lavaan code, if it is not possible yet in lavaan: https://mateuspsi.github.io/esemComp/index.html

See the vignette after installation: 

library(esemComp)
vignette("esem-within-cfa")

Reply all
Reply to author
Forward
0 new messages