【问题标题】:Exclude Node in semPaths {semPlot}在 semPaths {semPlot} 中排除节点
【发布时间】:2014-10-06 10:41:44
【问题描述】:

我正在尝试用 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" )   

【问题讨论】:

  • 向我们展示数据结构。尝试发布str(x) 的输出,甚至更好,发布reproducible example
  • 我刚刚从 Mplus 上传了 OUTfile。谢谢你的建议:)
  • 我建议您将代码“嵌入”到您的答案中,这样一旦您从 Dropbox 中删除文件,问题就不会过时。
  • 我不允许这样做 :( 但一般情况是所有数据集都会发生这种情况。

标签: r structural-equation-model semplot


【解决方案1】:

可能有一种更简单的方法可以做到这一点(并且忽略这样做是否明智) - 一种方法是在绘图之前从对象中删除节点。

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

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)

在上面对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)

你可以使用str(s)查看这个返回对象的结构。

【讨论】:

  • 这不是我所需要的,但我认为这是一个很好的线索,现在我自己做不到。谢谢:)
  • 不客气——我不知道这个包,所以我一直在用 graphviz 手动绘制这些模型——所以我很高兴你问了这个问题。
  • 我几天前以一种“粗鲁”的方式解决了这个问题,但这样更好:)
猜你喜欢
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-02
相关资源
最近更新 更多