# Simulate data for path model

How does one simulate data for a path model? Below is an example path model with parameters b1, b2, b3, b4, b5, e1, e2 and e3.

I would like to investigate how sample size affects my estimates and what happens to the estimates if a path is added or removed.

-
Do you have a preference for a particular software? –  chl Jul 17 '12 at 7:52
R code would be great, although it is fine for someone to describe the general strategy without any code. –  Glen Jul 17 '12 at 13:02

e1, e2, and e3 are not parameters, these are error terms in the path model. You may need to clarify your understanding of path notation (and may be structural equation modeling in general). These variables do need their parameters, the variances -- I will refer to them as $\psi_k, k=1, 2, 3$. You would also need the variance of x1 as the model parameter; I will denote it as $\phi_{11}$. These are the standard symbols in SEM notation. With that, we can have

    # set up the model parameters and the sample size n
n <- 100
b1 <- 1
b2 <- 0.8
b3 <- -0.3
b4 <- 0.5
b5 <- 0.8
phi11 <- 1
psi1 <- 0.64
psi2 <- 0.49
psi3 <- 0.81

# simulate the data
x1 <- rnorm(n, sd=sqrt( phi11 ) )
x2 <- b1*x1 + rnorm(n, sd=sqrt(psi1) )
x3 <- b2*x2 + rnorm(n, sd=sqrt(psi2) )
y <- b5*x1 + b4*x2 + b3*x3 + rnorm(n, sd=sqrt(psi3) )

-