Question about data simulation

53 views
Skip to first unread message

diya roy

unread,
Jan 13, 2018, 12:55:33 PM1/13/18
to lav...@googlegroups.com
Hi,

Can you kindly provide me an example to simulate data for this model ?


Thanks & regards,
Diya Guha Roy

PhD Research Scholar


1234.png

diya roy

unread,
Jan 13, 2018, 1:28:47 PM1/13/18
to lavaan

In fact , it will be a great help if you can help me to create the matrix for this model.
2.png

kma...@aol.com

unread,
Jan 14, 2018, 11:40:23 AM1/14/18
to lavaan
Diya,
  Your examples are overly complex for your question.  Here is a simple example to illustrate the concepts.  You can then apply the concepts to your more complex models.

  Suppose that you have one unmeasured latent variable that affects one measured latent variable with three indicators and that two observed covaraites have direct effects on the observed indicators.  Here is a way to simulate data from such a model.


# Simulate model with unmeasured latent observed covaraites

require(lavaan)

simModelSyntax
<- '
  # Measurement Models (latent variables)
  unmeasuredLatent =~ 0
  measuredLatent =~ 1*x1 + .9*x2 + .8*x3     # indicators x1 to x3

  # Regressions
  measuredLatent ~ .5*unmeasuredLatent
  x1 ~ .5*c1 + -.5*c2                        # covariates c1 and c2

  # Variances and disturbances
  unmeasuredLatent ~~ 1*unmeasuredLatent
  measuredLatent ~~ .5*measuredLatent
  x1 ~~ .3*x1
  x2 ~~ .3*x2
  x3 ~~ .3*x3
  c1 ~~ 1*c1
  c2 ~~ 1*c2
   
  # Covariances
  c1 ~~ .5*c2
'
# End model syntax

myData
<- simulateData(model=simModelSyntax, sample.nobs=1000)
head
(myData)
round
(cov(myData),3) # covariance matrix rounded for viewing


Note that the input to lavaan is just the data for the observed variables.  Were it otherwise, there would be no meaningful distinction between observed and unobserved variables.  As such, the simulated data will not include values for the two latent variables.  If you have an unmeasured latent variable that affects to other latent variables, you could also simulate this as an unexplained covariance between the two variables.  An unmeasured latent variable that has no effects on any other variable in the model, such as in your second example, can be omitted entirely form the simulation because it does not impact the observed variables.

If you want to simulate data for latent variables, then change the model syntax to treat them as observed variables.

Also, as a general rule, a path diagram should represent every parameter in the algebraic model.  Your diagrams are not strictly speaking path diagrams because they omit variances and disturbances.  Explicit representation of the algebraic model is one thing that distinguishes path diagrams from more abstract graphical representations such as causal graphs and logic models.

HTH,
Keith
------------------------
Keith A. Markus
John Jay College of Criminal Justice, CUNY
http://jjcweb.jjay.cuny.edu/kmarkus
Frontiers of Test Validity Theory: Measurement, Causation and Meaning.
http://www.routledge.com/books/details/9781841692203/


diya roy

unread,
Jan 14, 2018, 11:53:48 AM1/14/18
to lav...@googlegroups.com
Thanks a ton Keith.
Earlier I used the matrix method, did not know the regression modelling will work as well. This will make my testing easier.

Deeply grateful. Have a jolly new year.


Thanks & regards,
Diya Guha Roy

PhD Research Scholar



--
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/bpE8PnQ_Z8w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+unsubscribe@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.

Reply all
Reply to author
Forward
0 new messages