2014-10-06 72 views
2

我试图绘制与R.排除在semPaths {} semPlot

进出口使用从Mplus的OUT文件provinent与semPaths {} semPLot的SEM路径节点。

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

我使用的语法如下:

走出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") 
+0

向我们展示数据结构。尝试发布'str(x)'的输出,甚至更好,做一个[可重现的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。 – 2014-10-06 10:49:04

+0

我刚刚从Mplus上传了OUTfile。感谢您的建议:) – 2014-10-06 11:06:45

+0

我建议您将代码嵌入到您的答案中,以便在您从Dropbox中移除文件后,问题不会过时。 – 2014-10-06 11:25:47

回答

3

有可能做到这一点更简单的方法(和忽略,如果它是明智的做) - 一种方式您可以通过在绘图之前从对象中删除节点来完成此操作。

从你的问题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

使用Mplus例如在上面的调用semPathsoutfilecharacter类的,太行(代码为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 [email protected] - need to check lhs and rhs columns 
idx <- apply([email protected][c("lhs", "rhs")], 1, function(i) any(grepl("F1", i))) 
[email protected] <- [email protected][!idx, ] 

class(obj) 

obj现在是"semPlotModel"类的,可以直接传递到semPaths

s <- semPaths(obj, intercepts = FALSE) 

enter image description here

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

+0

这不完全是我需要的,但我认为是一个很好的线索,现在我不能自己做。谢谢:) – 2014-10-29 08:09:25

+0

不客气 - 我不知道这个软件包,所以我一直用graphviz手动绘制这些模型 - 所以我非常高兴你问这个问题。 – user20650 2014-10-29 08:45:35

+0

前几天我用一种“粗鲁”的方式解决了这个问题,但那样更好:) – 2014-10-29 10:22:19