Simulated Data based on 3-dimensional CFA Multiple Group Model

Dataset Description

A simulated dataset used for examples in Structural Equation Modeling. The data generating model is a 3-dimensional CFA multiple group model with correlated error variables of the item indicators (sometimes called Latent state model).


1popLsModel <- '
2eta1 =~ .6*Y11 + .6*Y21 + .6*Y31
eta2 =~ .6*Y12 + .6*Y22 + .6*Y32
eta3 =~ .6*Y13 + .6*Y23 + .6*Y33
3Y11 + Y12 + Y13 ~ i1*1
Y21 + Y22 + Y23 ~ i2*1
Y31 + Y32 + Y33 ~ i3*1
4Y11 ~~ .15*Y12 + .1*Y13
Y12 ~~ .15*Y13
Y21 ~~ .15*Y22 + .1*Y23
Y22 ~~ .15*Y23
Y31 ~~ .15*Y32 + .1*Y33
Y32 ~~ .15*Y33
5eta1 ~~ .5*eta2 + .35*eta3
eta2 ~~ .5*eta3
6eta1 ~ c(0,0)*1
eta2 ~ c(0.25, 0.25)*1
eta3 ~ c(0.5, 0.75)*1
7eta1 ~~ c(1,1)*eta1
eta2 ~~ c(1,1)*eta2
eta3 ~~ c(1,1.5)*eta3
'
1
Define the population model within a literal string (i.e., surrounded by ' ')
2
Specifiy measurement models (=~) and factor loadings (*)
3
Specify intercepts of item indicators (~ 1)
4
Specify error covariances (~~)
5
Specify covariances between latent variables (~~)
6
Specify means of latent variables (~ 1)
7
Specify variances of latent variables (~ 1)

Simulating the Data


# #install.packages("lavaan")
1wideLSdat <- lavaan::simulateData(
2    model = popLsModel,
3    meanstructure = TRUE,
4    sample.nobs = c(500, 500),
5    seed = 987)

wideLSdat$group <- wideLSdat$group-1
1
To generate the dataset with the name wideLSdat, we use the simulateData function from the lavaan package.
2
In the model argument, we state the generated string (popLsModel) from above (the previous slide).
3
(Optional) Setting the meanstructure argument to TRUE.
4
The sample.nobs argument controls the number of observation (per group). Here 2 groups with \(n\) = 500.
5
Defining seed for reproducible results.
saveRDS(wideLSdat, "path-to-data-folder/wideLSdat.RDS")