5

我试图弄清楚如何使用 graph.adjacency 使用相关矩阵(值 -1 到 1)创建一个图形,但只有图形文件中包含最强相关的边,即 <-.8 或 >。 8

这是成功为我提供了完整数据集的网络的代码:

corrdata<-read.csv("spearmancorr.csv",header=FALSE)
cor_mat<-as.matrix(corrdata)
diag(cor_mat)<-0
graph<-graph.adjacency(cor_mat,weighted=TRUE,mode="lower")

我尝试使用 delete.edges 将网络减少到至少 >.8 来测试它,但生成的文件仍然显示边缘权重低于 0.8

graph.copy <- delete.edges(graph, which(E(graph)$weight !<0.8)-1)
write.graph(graph.copy, file="gsig80.graphml", format="graphml")

关于如何获取我想要的图形文件的任何建议?

4

1 回答 1

5

You can delete the edges from the graph if you want to, or delete them from the matrix in the first place. E.g.

cor_mat[ cor_mat < .8 ] <- 0
diag(cor_mat) <- 0
graph <- graph.adjacency(cor_mat, weighted=TRUE, mode="lower")

Here is how to delete them from the graph, after creating it:

graph <- delete.edges(graph, E(graph)[ weight < 0.8 ])
于 2013-11-14T02:28:57.267 回答