我希望使用三个变量在R中运行RI-CLPM。本文的作者(Mond和Nestler,2017年)亲切地使下面的语法可用于两个变量模型。
除了增加3个额外的稳定性和滞后的路径外,我还有一些困难-我希望能帮助您修改代码以合并第三个变量。
## load data
data <- read.table("./data/Fakedata_RI-CLPM_R.dat", header = T)
## Define model for lavaan
riclpm <- '
# Define intercept factors
ix =~ 1*x1+1*x2+1*x3+1*x4
iy =~ 1*y1+1*y2+1*y3+1*y4
# Define phantom latent variables
etax1 =~ 1*x1
etax2 =~ 1*x2
etax3 =~ 1*x3
etax4 =~ 1*x4
etay1 =~ 1*y1
etay2 =~ 1*y2
etay3 =~ 1*y3
etay4 =~ 1*y4
# Autoregressive effects
etax2 ~ a1*etax1
etax3 ~ a1*etax2
etax4 ~ a1*etax3
etay2 ~ a2*etay1
etay3 ~ a2*etay2
etay4 ~ a2*etay3
# Crosslagged effects
etay2 ~ c1*etax1
etay3 ~ c1*etax2
etay4 ~ c1*etax3
etax2 ~ c2*etay1
etax3 ~ c2*etay2
etax4 ~ c2*etay3
# Some further constraints on the variance structure
# 1. Set error variances of the observed variables to zero
x1 ~~ 0*x1
x2 ~~ 0*x2
x3 ~~ 0*x3
x4 ~~ 0*x4
y1 ~~ 0*y1
y2 ~~ 0*y2
y3 ~~ 0*y3
y4 ~~ 0*y4
# 2. Let lavaan estimate the variance of the latent variables
etax1 ~~ varx1*etax1
etax2 ~~ varx2*etax2
etax3 ~~ varx3*etax3
etax4 ~~ varx4*etax4
etay1 ~~ vary1*etay1
etay2 ~~ vary2*etay2
etay3 ~~ vary3*etay3
etay4 ~~ vary4*etay4
# 3. We also want estimates of the intercept factor variances and an
# estimate of their covariance
ix ~~ varix*ix
iy ~~ variy*iy
ix ~~ covi*iy
# 4. We have to define that the covariance between the intercepts
and
# the latents of the first time point are zero
etax1 ~~ 0*ix
etay1 ~~ 0*ix
etax1 ~~ 0*iy
etay1 ~~ 0*iy
# 5. Finally, we estimate the covariance between the latents of x
and y
# of the first time point, the second time-point and so on. note
that
# for the second to fourth time point the correlation is
constrained to
# the same value
etax1 ~~ cov1*etay1
etax2 ~~ e1*etay2
etax3 ~~ e1*etay3
etax4 ~~ e1*etay4
# The model also contains a mean structure and we have to define
some
# constraints for this part of the model. the assumption is that we
# only want estimates of the mean of the intercept factors. all
other means
# are defined to be zero:
x1 ~ 0*1
x2 ~ 0*1
x3 ~ 0*1
x4 ~ 0*1
y1 ~ 0*1
y2 ~ 0*1
y3 ~ 0*1
y4 ~ 0*1
etax1 ~ 0*1
etax2 ~ 0*1
etax3 ~ 0*1
etax4 ~ 0*1
etay1 ~ 0*1
etay2 ~ 0*1
etay3 ~ 0*1
etay4 ~ 0*1
ix ~ 1
iy ~ 1
## define correlations
cori := covi / (sqrt(varix) * sqrt(variy))
cor1 := cov1 / (sqrt(varx1) * sqrt(vary1))
cort2 := e1 / (sqrt(varx2) * sqrt(vary2))
cort3 := e1 / (sqrt(varx3) * sqrt(vary4))
cort4 := e1 / (sqrt(varx4) * sqrt(vary4))'