r - 在 semPaths {semPlot} 中排除节点

标签 r structural-equation-model semplot

我正在尝试使用 R 绘制 sem 路径。

我正在使用来自 Mplus 的 OUT 文件和 semPaths {semPLot}。

显然它似乎有效,但我想删除一些潜在变量,但我不知道如何。

我正在使用以下语法:

从 Mplus 输出:https://www.dropbox.com/s/vo3oa5fqp7wydlg/questedMOD2.out?dl=0

outfile1 <- "questedMOD.out"
```

semPaths(outfile1,what="est", intercepts=FALSE, rotation=4,  edge.color="black", sizeMan=5, esize=TRUE, structural="TRUE",  layout="tree2", nCharNodes=0, intStyle="multi" )   

最佳答案

可能有一种更简单的方法来执行此操作(如果这样做是明智的则忽略)- 一种方法是在绘图之前从对象中删除节点。

使用问题中的 Mplus 示例 Rotate Edges in semPaths/qgraph

library(qgraph)
library(semPlot)
library(MplusAutomation)

# This downloads an output file from Mplus examples
download.file("http://www.statmodel.com/usersguide/chap5/ex5.8.out", 
                                        outfile <- tempfile(fileext = ".out"))

# Unadjusted plot
s <- semPaths(outfile, intercepts = FALSE)

enter image description here

在上面对 semPaths 的调用中,outfile 属于 character 类,因此行(靠近 代码的开头) semPaths)

 if (!"semPlotModel" %in% class(object)) 
                    object <- do.call(semPlotModel, c(list(object), modelOpts))  

semPlot:::semPlotModel.mplus.model(outfile) 返回对象。这是 "semPlotModel" 类。

所以想法是先创建这个对象,修改它,然后将这个对象传递给semPaths

# Call semPlotModel on your Mplus file
obj <- semPlot:::semPlotModel.mplus.model(outfile)
# obj <- do.call(semPlotModel, list(outfile)) # this is more general / not just for Mplus

# Remove one factor (F1) from object@Pars - need to check lhs and rhs columns
idx <- apply(obj@Pars[c("lhs", "rhs")], 1, function(i) any(grepl("F1", i)))
obj@Pars <- obj@Pars[!idx, ]

class(obj)

obj 现在属于 "semPlotModel" 类,可以直接传递给 semPaths

s <- semPaths(obj, intercepts = FALSE)

enter image description here

您可以使用str(s) 来查看此返回对象的结构。

关于r - 在 semPaths {semPlot} 中排除节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26214531/

相关文章:

r - 拉万 : Define factor by multiple variables as in Mplus

r - R 中的 SEM (CFA) : Could not compute QR decomposition of Hessian. 优化可能没有收敛。

r - 在 runMI() 之后绘制 SEM 参与者-合作伙伴相互依赖模型

r - r中的路径图

r - Shiny 的 observeEvent() 中的执行顺序是什么?

r - 未知错误(工作进程初始化失败 : 21) in foreach() with doParallel cluster (R)

r - 有没有办法生成类似于 mutate_at 或 mutate_if 的 Gather_at 或 Gather_if 函数

r - 根据现有间隔创建所有可能的时间间隔表