gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 04:16:51 28 4
gpt4 key购买 nike

我正在尝试使用 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com