首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >semPaths {semPlot}中的排除节点

semPaths {semPlot}中的排除节点
EN

Stack Overflow用户
提问于 2014-10-06 10:41:44
回答 2查看 2.1K关注 0票数 3

我想和R画一条缝路。

我使用semPaths {semPLot}从Mplus中提取的OUT文件。

很明显,它似乎起作用了,但我想删除一些潜在的变量,但我不知道怎么做。

我使用以下语法:

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

代码语言:javascript
复制
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“)

代码语言:javascript
复制
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-10-27 17:25:26

可能有一种更简单的方法来做到这一点(如果这样做是明智的,就忽略它)--您可以这样做的一种方法是在绘图之前从对象中删除节点。

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

代码语言:javascript
复制
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的代码开始附近)

代码语言:javascript
复制
 if (!"semPlotModel" %in% class(object)) 
                    object <- do.call(semPlotModel, c(list(object), modelOpts))  

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

因此,我们的想法是首先创建这个对象,修改它,然后将这个对象传递给semPaths

代码语言:javascript
复制
# 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

代码语言:javascript
复制
s <- semPaths(obj, intercepts = FALSE)

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

票数 3
EN

Stack Overflow用户

发布于 2022-05-26 08:46:23

假设您使用下面的半路径代码打印SEM

代码语言:javascript
复制
semPaths(obj, intercepts = FALSE)%>%
   plot()

您可以使用以下函数删除任何节点的标签:

代码语言:javascript
复制
remove_nodes_and_edges <- function(semPaths_obj,node_tbrm_vec){
   
   relevent_nodes_index <- semPaths_obj$graphAttributes$Nodes$names %in% node_tbrm_vec

   semPaths_obj$graphAttributes$Nodes$width[relevent_nodes_index]=0

   semPaths_obj$graphAttributes$Nodes$height[relevent_nodes_index]=0
   
   semPaths_obj$graphAttributes$Nodes$labels[relevent_nodes_index]=""

   return(semPaths_obj)

}

并以下列方式在绘图管道中使用此函数

代码语言:javascript
复制
semPaths(obj, intercepts = FALSE) %>%
   remove_nodes_and_edges(c("Y1","Y2","Y3")) %>%
   plot()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26214531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档