How to create a lavaan parameter table using simsem package in R?

258 views
Skip to first unread message

Monika Ramoskaite

unread,
Nov 22, 2019, 11:21:00 AM11/22/19
to lavaan
I would like to create a data analysis template (lavaan parameter table) for simulations with structural equation models and then perform simulation based on real data.

I have found the example of this:

loading <- matrix(0, 9, 3)
loading[1:3, 1] <- NA
loading[4:6, 2] <- NA
loading[7:9, 3] <- NA
cfamodel <- estmodel(LY=loading, modelType="CFA", indLab=paste("x", 1:9, sep=""))

out <- analyze(cfamodel, HolzingerSwineford1939)

datamodel.nomis <- model.lavaan(out, std=TRUE)

output.nomis <- sim(1000, n=nrow(HolzingerSwineford1939), datamodel.nomis)
summary(output.nomis)

However, the creation of lavaan parameter table is a bit confusing (the definition of 'cfamodel' variable), especially, if for example exogenous variables or regressions are included in SEM model.


My SEM model is as per below. It includes 23 free parameters (5 factor loadings, 9 covariances between latent variable indicators, 3 regressions, 6 variances) and two defined (variance of the latent variable and indirect effect).


FullModel=
  "
# Latent variable definition
IWB =~ NOVE+EXPL+TEST+SUPP+IMPL

#Direct effects
IWB ~ OSE

#Medation
IWB ~ g*WE
WE ~ h*OSE

#Indirect effect
gh:=g*h

#Covariances
NOVE ~~ EXPL + SUPP + IMPL 
EXPL ~~ TEST + SUPP + IMPL
TEST ~~  SUPP + IMPL
SUPP ~~ IMPL 
"


As by the example I would start with:

loading <- matrix(0, 5, 1)
loading[1:5, 1] <- NA
cfamodel <- estmodel(LY=loading, modelType="sem")


But then I have no idea, how to define the rest of the parameters?

Terrence Jorgensen

unread,
Nov 23, 2019, 9:33:00 AM11/23/19
to lavaan
I would like to create a data analysis template (lavaan parameter table) for simulations with structural equation models and then perform simulation based on real data.

Was this your post on GitHub?


But then I have no idea, how to define the rest of the parameters?


You can specify other parameters in the other LISREL matrices, as you can find in the numerous other simsem examples on simsem.org (see Vignettes).

But you cannot define parameters using the LISREL matrices.  You would have to use lavaan syntax for the the model= argument, which is the model used to analyze the simulated data.  The simulated data can be generated from the model you specify with LISREL matrices, but it would be more efficient to use the parameter table from your fitted model to generate data, if you want to use the estimated parameters from your fitted model as the population values to simulated data.

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

Monika Ramoskaite

unread,
Nov 23, 2019, 10:50:04 AM11/23/19
to lav...@googlegroups.com

Yes, the one in github is my question as well. As it was regarding the two simsem package approaches, I thought it was more appropriate to post it there. Apologies if that is not the case.

 

I have looked at the simsem vignettes, but only found an example of constructing the factor loading matrix (the example I have inserted above is taken from there).

The trouble I have is regarding the specification of the other parameters in a similar way as factor loadings (such as variances or regression coefficients) as I could not find examples in Vignettes (until actually this morning, but even then it was with latent variables, but I would like to do it for observed covariates). I am unfamiliar with LISREL and its syntax therefore I find it a bit confusing.

 

However as I understand from the answer on https://github.com/simsem/simsem/issues/59

I could avoid specifying LISREL parameter matrices altogether and use the parTable() from the fitted lavaan model in sim() instead and receive the same result, however I receive the error.


--
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 view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/2be88cc0-743a-4034-b600-c7257aa76a20%40googlegroups.com.

Terrence Jorgensen

unread,
Nov 23, 2019, 4:33:43 PM11/23/19
to lavaan

I could avoid specifying LISREL parameter matrices altogether and use the parTable() from the fitted lavaan model in sim() instead and receive the same result


Yes
 

however I receive the error.



As it was regarding the two simsem package approaches, I thought it was more appropriate to post it there

It was, since that is specifically for simsem issues.  But it is okay to post here about lavaan-ecosystem issues in general.  I just wanted to make sure not to repeat information when I could simply link between locations.

Monika Ramoskaite

unread,
Nov 24, 2019, 6:22:07 AM11/24/19
to lav...@googlegroups.com
Thank you for reacting so quickly to my questions, appreciate it greatly.
Everything now works fine.

Best regards,
Monika

--
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.
Reply all
Reply to author
Forward
0 new messages