2

我想用一个分类中介来估计一个结构方程lavaan模型R。一个皱纹是三个外生变量是线性相关的。但是,这应该不是问题,因为我使用分类调解器来实现 la Judea Pearl 的前门标准的识别。也就是说,在数学上每个特定的方程都被识别(见R下面的代码)。

当中介是数字时lavaanR我可以获得估计值,但当它是分类时则不能。使用分类调解器,我得到以下错误:

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")
4

0 回答 0