0

我正在尝试在 semPaths 中使用自定义布局,用于数据不完整的 lavaan 模型。这适用于按列表删除,但在我指定按大小写/完整信息估计时无效。

library(lavaan)
library(semPlot)

# Toy dataset with some NAs
df <- data.frame(replicate(3, rnorm(100, 0, 1)))
df[c(1, 2, 3), 2] = NA
df[c(11, 12, 13), 3] = NA

# Create and fit SEM model
model <- "
X1 ~ X2
X1 ~ X3
X2 ~ X3"

fitNA <- sem(model, df) # List-wise deletion
fit <- sem(model, df, missing = 'ML') # Full information

# Custom layout
x <- c(-1, -1, 1)
y <- c(-1, 1, 0)
m <- matrix(c(x,y), ncol = 2)

# Plot with custom layout
semPaths(fitNA, layout = m) # works for listwise deletion
semPaths(fit, layout = m) # throws an error

布局错误[groups[[g]], 1]:下标越界

由于某种原因,节点数量似乎增加了?

# New layout with more nodes
x <- c(-1, -1, 1, 1, 2,3, 4)
y <- c(-1, 1,  0, 1, 2,3, 4)
m2 <- matrix(c(x,y), ncol = 2)
semPaths(fit, layout = m2) # This does not throw an error

我不确定这是否是一个错误或者是否应该是这样 - 在这两种情况下,我都会感谢任何关于如何绘制完整信息模型的指示。我的实际模型要复杂得多,需要自定义布局才能理解它。

4

0 回答 0