具有线性相关性的结构方程模型(Lavaan)

时间:2017-05-10 16:41:17

标签: r identification r-lavaan sem causality

我想在lavaan中使用R估算结构方程模型,并使用分类中介。皱纹是三个外生变量linearly dependent。但是,这应该不是问题,因为我使用分类中介来实现识别la Judea Pearl's front-door criterion。也就是说,在数学上识别出每个特定的等式(参见下面的R代码)。

lavaan中的R我可以在介体为数字时获取估算值,但在分类时不能获得。使用分类调解器,我得到以下错误:

Error in lav_samplestats_step1(Y = Data, ov.names = ov.names, ov.types = ov.types,  
: lavaan ERROR: linear regression failed for y; X may not be of full rank in group 1

有关如何使用lavaan获取分类调解员估算值的任何建议?

代码:

# simulating the dataset
set.seed(1234) # seed for replication
x1 <- rep(seq(1:4), 100) # variable 1
x2 <- rep(1:4, each=100) # variable 2
x3 <- x2 - x1 + 4 # linear dependence
m <- sample(0:1, size = 400, replace = TRUE) # mediator
df <- data.frame(cbind(x1,x2,x3,m)) # dataframe
df$y <- 6.5 + x1*(0.5) + x2*(0.2) + m*(-0.4) + x3*(-1) + rnorm(400, 0, 1) # outcome

# structural equation model using pearl's front-door criterion
sem.formula <- 'y ~ 1 + x1 + x2 + m 
m ~ 1 + x3'

# continuous mediator: works!
fit <- lavaan::sem(sem.formula, data=df, estimator="WLSMV",
                   se="none", control=list(iter.max=500))

# categorical mediator: doesn't work
fit <- lavaan::sem(sem.formula, data=df, estimator="WLSMV",
                   se="none", control=list(iter.max=500),
                   ordered = "m")

0 个答案:

没有答案