3

我需要计算我在 R 中制作的网络的一个巨大组件,但是这个网站上给出的代码(http://lists.gnu.org/archive/html/igraph-help/2009-08/msg00064.html ) 导致奇怪的输出。我需要巨大的组件来计算接近度(根据大学老师的说法)

giant.component <- function(graph) {
cl <- clusters(graph)
induced.subgraph(graph, which(cl$membership == which.max(cl$csize)-1)-1)}
G <- giant.component(as.igraph(Q))

结果:

IGRAPH U-W- 0 0 -- 
+ attr: frame.color (v/c), label.color (v/c), label (v/c), shape
(v/c), color (v/c), size (v/n), size2 (v/n), weight (e/n),
arrow.mode (e/n), curved (e/n), color (e/c), label (e/c), lty
(e/n), width (e/n)

Csardi 建议的代码改编导致以下代码和结果:

model5 <- matrix(c(0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0), 5, 5, byrow = TRUE) 
C <- qgraph(model5, labels = c("X1", "X2", "X3", "X4", "X5"), vsize = 20, esize = 10, asize = 10, layout = "circle") 

giant.component <- function(graph) { 
cl <- clusters(graph) 
induced.subgraph(graph, which(cl$membership == which.max(cl$csize)))} 
G <- giant.component(as.igraph(C)) 
G <- qgraph(C)

IGRAPH D-W- 5 7 -- 
+ attr: frame.color (v/c), label.color (v/c), label (v/c), shape
(v/c), color (v/c), size (v/n), size2 (v/n), weight (e/n),
arrow.mode (e/n), curved (e/n), color (e/c), lty (e/n), width (e/n) 
4

1 回答 1

6

较旧(0.6 之前)版本的 igraph 索引顶点(以及其他所有内容)从零开始,而较新版本使用基于 1 的索引。因此,您需要将代码更新为:

...
induced.subgraph(graph, which(cl$membership == which.max(cl$csize)))}
...

(未经测试,因为您没有提供示例数据集。)

于 2013-06-09T18:33:23.130 回答