simulations

76 views
Skip to first unread message

Omar Salim

unread,
Nov 14, 2020, 5:36:36 PM11/14/20
to lavaan
How to perform simulations for a Likert scale order data 5 for a multi-group model?

Terrence Jorgensen

unread,
Nov 16, 2020, 9:57:48 AM11/16/20
to lavaan

How to perform simulations for a Likert scale order data 5 for a multi-group model?

See the ?simulateData help page for a single-group example and normal data.  I adapted that example below (using just 1 factor, so a CFA with 3 indicators) in two ways:
  • to make it for multiple groups by supplying vectors of parameters (1 per group) and passing a vector of sample sizes to the sample.nobs= argument
  • I added 4 thresholds for variables x1-x3 to make them categorical. 
That shows you the basic functionality, and you can generalize from there to your own goals.

population.model <- ' f1 =~ c(.7, .7)*x1 + c(0.8, 0.8)*x2 + c(0.7, 0.8)*x3
## factor variance
  f1 ~~ c(1, 1)*f1
## residual variances (such that indicator total variances == 1)
  x1 ~~ c(.51, .51)*x1
  x2 ~~ c(.36, .36)*x2
  x3 ~~ c(.51, .36)*x3
## thresholds
  x1 | -1.5*t1 + -0.5*t2 + 0.5*t3 + 1.5*t4
  x2 | -2*t1 + -1*t2 + 0*t3 + 1*t4
  x3 | -1*t1 + 0*t2 + 1*t3 + 2*t4
'
## generate data
set.seed(1234)
myData <- simulateData(population.model, sample.nobs = c(100L, 100L),
                       parameterization = "theta")
## quick check
opar <- par(mfrow = c(3, 1))
for (i in 1:3) hist(myData[ , paste0("x", i)])
par(opar)


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

Omar Salim

unread,
Nov 17, 2020, 5:08:32 PM11/17/20
to lavaan


Thank you so much
Is it possible to control the shape of the distribution through the thresholds for each group, for example? Normal or non normal distribution 
(1) a symmetric distribution, (2) a slightly asymmetric distribution, 
(3) a moderately asymmetric distribution, and (4) a bipolarized distribution. When responding to Likert-type items 



And the second question, and through my changing of the thresholds for the previous example, I had the following error

> population.model <- ' f1 =~ c(.7, .7)*x1 + c(0.8, 0.8)*x2 + c(0.7, 0.8)*x3
+ ## factor variance
+   f1 ~~ c(1, 1)*f1
+ ## residual variances (such that indicator total variances == 1)
+   x1 ~~ c(.51, .51)*x1
+   x2 ~~ c(.36, .36)*x2
+   x3 ~~ c(.51, .36)*x3
+ ## thresholds
+   x1 | −1.282*t1 + −0.524*t2 + 0.524*t3 + 1.282*t4
+   x2 | −1.282*t1 + −0.524*t2 + 0.524*t3 + 1.282*t4
+   x3 | −1.282*t1 + −0.524*t2 + 0.524*t3 + 1.282*t4
+ 
+ '
> ## generate data
> set.seed(1234)
> myData <- simulateData(population.model, sample.nobs = c(100L, 100L),
+                        parameterization = "theta")
Error in parse(text = x, keep.source = FALSE) : 
  <text>:1:3: unexpected '<'
1: ~ <
      ^

Terrence Jorgensen

unread,
Nov 18, 2020, 7:12:40 AM11/18/20
to lavaan
Is it possible to control the shape of the distribution through the thresholds for each group, for example? Normal or non normal distribution 
(1) a symmetric distribution, (2) a slightly asymmetric distribution, 
(3) a moderately asymmetric distribution, and (4) a bipolarized distribution. When responding to Likert-type items 

Yes, that is what my script illustrated by using different thresholds across indicators (see the histograms I produced at the end). 

I had the following error

Error in parse(text = x, keep.source = FALSE) : 
  <text>:1:3: unexpected '<'
1: ~ <
      ^

I'm not sure why parse() was indicating you had a "<" character in your syntax, but the real problem is that you used an actual minus sign character instead of a simple hyphen in your syntax.  

"−" == "-" # false

Your syntax runs fine when you use hyphens:

population.model <- ' f1 =~ c(.7, .7)*x1 + c(0.8, 0.8)*x2 + c(0.7, 0.8)*x3
## factor variance
  f1 ~~ c(1, 1)*f1
## residual variances (such that indicator total variances == 1)
  x1 ~~ c(.51, .51)*x1
  x2 ~~ c(.36, .36)*x2
  x3 ~~ c(.51, .36)*x3
## thresholds
  x1 | -1.282*t1 + -0.524*t2 + 0.524*t3 + 1.282*t4
  x2 | -1.282*t1 + -0.524*t2 + 0.524*t3 + 1.282*t4
  x3 | -1.282*t1 + -0.524*t2 + 0.524*t3 + 1.282*t4
'
set.seed(1234)
myData <- simulateData(population.model, sample.nobs = c(100L, 100L),
                       parameterization = "theta")

FYI, it is easier for us to copy/paste your syntax when you just provide the syntax.  Don't copy it from the Console output, because then we have to erase all the plus signs in the left margin.  Only copy the relevant output from the Console (e.g., error or warning message).

Omar Salim

unread,
Nov 18, 2020, 11:24:01 AM11/18/20
to lavaan

Thank you so much

I have a question, please help me. I need to generate data that track several distributions, is it by (skew and kurtosis  or through thresholds, please help me with a simple example of these distributions

An example of the following distributions is how a simulation of the various groups of Likert scale is performed 1 = normal distribution; 2 = low nonnormality , 3 = moderate nonnormality  4 = high.

Omar Salim

unread,
Nov 18, 2020, 12:07:08 PM11/18/20
to lavaan

Thank you so much

I have a question, please help me. I need to generate data that track several distributions, is it by (skew and kurtosis  or through thresholds, please help me with a simple example of these distributions

An example of the following distributions is how a simulation of the various groups of Likert scale is performed 1 = normal distribution; 2 = low nonnormality , 3 = moderate nonnormality  4 = high.


Reply all
Reply to author
Forward
0 new messages