1

I have a social network of approximately 1,400 cases and partners. I am using igraph to create the network and also extract some metrics (density, average degree, betweenness etc)

I want to analyze the data by component size (create categories for small components (2-3 members), medium components (8-20 members) and large components(more than 20 members)

Using the following code: components<-components(allcases.g) I get some information such as: $membership, $scize and $number.

However, $csize just tells me the size of all of the the different components (total= 250 components), but the size is not linked to the individual vertices.

Does anybody know the best way to link back the component size to each of the vertices in my network?

Thanks!

G5W
  • 36,531
  • 10
  • 47
  • 80
A_P
  • 13
  • 2
  • please see the guidelines on how to create and post a minimal, complete, verifable example - https://stackoverflow.com/help/mcve – Michael Mullany Oct 05 '18 at 23:45

1 Answers1

2

membership tells you which component a node belongs to. As you noted, csize tells you the size of the component. So you can get the size of the components by node using COMP$csize[COMP$membership]. Here is a small example.

library(igraph)
set.seed(1234)
g = erdos.renyi.game(30, 0.15) + 
    erdos.renyi.game(30, 0.15) +
    erdos.renyi.game(20, 0.25) +
    erdos.renyi.game(20, 0.25)
plot(g, vertx.size=6, cex=0.8, margin=-0.2)

COMP = components(g)
COMP$csize[COMP$membership]
  [1] 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
 [26] 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
 [51] 30 30 30 30 30 30 30 30 30 30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
 [76] 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
G5W
  • 36,531
  • 10
  • 47
  • 80
  • Thank you so much. This is exactly what I was looking for. When the vector for size is created, I am assuming it is created in the same order as the data. Therefore, a simple cbind () should allow me to link this characteristic back to the original dataset. – A_P Oct 09 '18 at 18:53
  • Yes, This should make one size value per node. If you want to make it an attribute of the node, you can just use `V(g)$CompSize = COMP$csize[COMP$membership]` – G5W Oct 09 '18 at 19:01