@@ -40,6 +40,58 @@ decode_all_communities <- function(graph,
4040 return (o )
4141}
4242
43+ get_component_stats <- function (x ) {
44+
45+ # what is he
46+ community_id <- V(x )$ community [1 ]
47+
48+ # number of nodes per component
49+ count_n <- table(V(x )$ component_id )
50+
51+ # components has more than one node
52+ i <- which(count_n > 1 )
53+ stats_components <- c()
54+ if (length(i )> 0 ) {
55+ stats_components <- lapply(X = names(i ), g = x , FUN = function (x , g ) {
56+ o <- subgraph(g , vids = which(V(g )$ component_id == x ))
57+
58+ ncweight <- E(o )$ ncweight
59+ if (length(ncweight )== 0 ) {
60+ ncweight <- NA
61+ }
62+ nweight <- E(o )$ nweight
63+ if (length(nweight )== 0 ) {
64+ nweight <- NA
65+ }
66+
67+ return (data.frame (component_id = x ,
68+ community = V(o )$ community [1 ],
69+ mean_ncweight = mean(ncweight ),
70+ mean_nweight = mean(nweight ),
71+ n_nodes = length(o ),
72+ n_edges = length(E(o )),
73+ n_clique_edges = length(o )* (length(o )- 1 )/ 2 ,
74+ diameter = diameter(o )))
75+ })
76+ stats_components <- do.call(rbind , stats_components )
77+ }
78+
79+ i <- which(count_n == 1 )
80+ stats_singletons <- c()
81+ if (length(i )> 0 ) {
82+ stats_singletons <- data.frame (component_id = names(i ),
83+ community = community_id ,
84+ mean_ncweight = NA ,
85+ mean_nweight = NA ,
86+ n_nodes = 1 ,
87+ n_edges = 0 ,
88+ n_clique_edges = 0 ,
89+ diameter = 0 )
90+ }
91+
92+ return (rbind(stats_components , stats_singletons ))
93+ }
94+
4395check_graph <- function (graph ) {
4496 if (missing(graph )) {
4597 stop(" missing graph" )
0 commit comments