This file was created to calculate modularity and E-I index based on igraph package for the entire dataset of SMRs in the four provinces of Canada involved , but focusing only on the networks build departing from the narratives. We use two files to rebuild the dataset and being able to calculate the indexes:
File graphml from DNA,
Attributes of nodes from the excel imported to Visone to add the nodes attributes.
First, after adding the attributes to Visone, we download all the the adjacency matrices from Visone to use them here.
##Building graphs
After getting the matrices, we build the graphs based on igrpah
At this point we had all the graphs, but we need to add some attributes before making the calculations. The following section do that after opening the files with those attributes
Then we create the functions to merge the data in the graph file
Finally, we complete the merging and verify the results.
At this point we have finished the procedure of transforming adjacency matrices in graphs and we have added the attributes. We are ready to plot the graphs.
## IGRAPH 15e7a77 UNW- 8 8 --
## + attr: name (v/c), alias (v/c), nuclear (v/c), instance (v/c), color
## | (v/c), weight (e/n)
## + edges from 15e7a77 (vertex names):
## [1] 1235--190 508 --584 508 --586 508 --587 508 --588 586 --587 586 --588
## [8] 587 --588
## IGRAPH 5d791c3 UNW- 9 7 --
## + attr: name (v/c), alias (v/c), nuclear (v/c), instance (v/c), color
## | (v/c), weight (e/n)
## + edges from 5d791c3 (vertex names):
## [1] 1151--584 270 --508 270 --764 270 --941 508 --764 508 --941 764 --941
## IGRAPH 2966fee UNW- 5 7 --
## + attr: name (v/c), alias (v/c), nuclear (v/c), instance (v/c), color
## | (v/c), weight (e/n)
## + edges from 2966fee (vertex names):
## [1] 1005--1220 1005--347 1005--358 1005--522 1220--347 1220--522 347 --522
## IGRAPH 9ea9c9c UNW- 15 52 --
## + attr: name (v/c), alias (v/c), nuclear (v/c), instance (v/c), color
## | (v/c), weight (e/n)
## + edges from 9ea9c9c (vertex names):
## [1] 1005--366 1005--522 1005--536 1005--562 1005--565 1005--574 1005--624
## [8] 1176--354 1176--522 1176--536 1176--562 1176--565 1176--596 1176--613
## [15] 1176--728 354 --366 354 --522 354 --536 354 --562 354 --565 354 --596
## [22] 354 --613 354 --728 366 --522 366 --536 366 --562 366 --565 366 --574
## [29] 366 --613 366 --624 522 --536 522 --562 522 --565 522 --574 522 --596
## [36] 522 --613 522 --624 536 --562 536 --565 536 --574 536 --596 536 --624
## [43] 546 --606 546 --728 562 --565 562 --574 562 --613 562 --624 565 --596
## + ... omitted several edges
## IGRAPH 6f2a959 UNW- 11 22 --
## + attr: name (v/c), alias (v/c), nuclear (v/c), instance (v/c), color
## | (v/c), weight (e/n)
## + edges from 6f2a959 (vertex names):
## [1] 1005--347 1005--358 1005--366 1005--522 1005--966 347 --358 347 --520
## [8] 347 --522 347 --565 358 --366 358 --520 358 --522 358 --565 358 --966
## [15] 366 --520 366 --565 520 --522 520 --565 522 --565 522 --966 565 --966
## [22] 728 --950
## IGRAPH 52609c3 UNW- 4 1 --
## + attr: name (v/c), alias (v/c), nuclear (v/c), instance (v/c), color
## | (v/c), weight (e/n)
## + edge from 52609c3 (vertex names):
## [1] 408--65
## IGRAPH 2fc1892 UNW- 23 109 --
## + attr: name (v/c), alias (v/c), nuclear (v/c), instance (v/c), color
## | (v/c), weight (e/n)
## + edges from 2fc1892 (vertex names):
## [1] 1036--535 1036--557 1036--612 1036--626 237 --347 237 --358 237 --411
## [8] 237 --413 237 --532 237 --566 237 --578 237 --581 237 --582 237 --589
## [15] 237 --590 237 --591 237 --690 237 --694 311 --347 311 --413 311 --582
## [22] 347 --358 347 --411 347 --413 347 --532 347 --566 347 --578 347 --581
## [29] 347 --582 347 --589 347 --590 347 --591 347 --690 347 --694 358 --411
## [36] 358 --413 358 --532 358 --566 358 --578 358 --581 358 --582 358 --589
## [43] 358 --590 358 --591 358 --690 358 --694 391 --535 391 --557 391 --612
## + ... omitted several edges
## IGRAPH 48fb804 UNW- 24 150 --
## + attr: name (v/c), alias (v/c), nuclear (v/c), instance (v/c), color
## | (v/c), weight (e/n)
## + edges from 48fb804 (vertex names):
## [1] 1000--104 1000--1040 1000--174 1000--234 1000--342 1000--354
## [7] 1000--411 1000--413 1000--532 1000--581 1000--694 1007--1017
## [13] 1007--1070 1007--234 1007--342 1007--354 1007--408 1007--411
## [19] 1007--532 1007--581 1007--694 1017--1070 1017--234 1017--354
## [25] 1017--408 1017--411 1017--532 1017--581 104 --1040 104 --1070
## [31] 104 --234 104 --342 104 --391 104 --408 104 --411 104 --413
## [37] 104 --502 104 --532 104 --581 104 --65 104 --694 104 --792
## + ... omitted several edges
## IGRAPH 84495bb UNW- 5 3 --
## + attr: name (v/c), alias (v/c), nuclear (v/c), instance (v/c), color
## | (v/c), weight (e/n)
## + edges from 84495bb (vertex names):
## [1] 215--476 215--860 476--860
## IGRAPH a8bcc0e UNW- 12 35 --
## + attr: name (v/c), alias (v/c), nuclear (v/c), instance (v/c), color
## | (v/c), weight (e/n)
## + edges from a8bcc0e (vertex names):
## [1] 312--476 312--527 312--529 312--545 312--575 312--580 312--76 312--988
## [9] 476--527 476--529 476--545 476--570 476--580 476--600 476--76 476--988
## [17] 527--529 527--545 527--575 527--580 527--600 527--76 527--988 529--545
## [25] 529--570 529--575 529--76 545--570 545--580 545--76 545--988 570--76
## [33] 580--76 580--988 600--988
## IGRAPH 905b0da UNW- 17 80 --
## + attr: name (v/c), alias (v/c), nuclear (v/c), instance (v/c), color
## | (v/c), weight (e/n)
## + edges from 905b0da (vertex names):
## [1] 1002--183 1002--205 1002--476 1002--76 1002--860 1002--911 1178--570
## [8] 1178--962 183 --205 183 --290 183 --476 183 --527 183 --570 183 --575
## [15] 183 --76 183 --860 183 --883 183 --911 183 --962 183 --988 205 --290
## [22] 205 --476 205 --527 205 --570 205 --575 205 --76 205 --860 205 --883
## [29] 205 --911 205 --988 290 --476 290 --527 290 --570 290 --575 290 --76
## [36] 290 --860 290 --883 290 --911 290 --988 476 --527 476 --545 476 --570
## [43] 476 --575 476 --76 476 --860 476 --883 476 --911 476 --988 527 --570
## + ... omitted several edges
Using different packages we calculate the modularity and e-i index using nuclear as the attribute. for each period.
Modularity measures coalition polarization. It ranges from 0 to 1.
Values close to 0 mean shows low polarization between groups. And there differences within each coalition
Values close to 0.5 do not show any association.
Values close to 1 show high polarization between groups. Coalitions are compacted internally and show a great difference to others coalitions.
## Warning in cluster_edge_betweenness(grafo, weights = E(grafo)$weight): At
## vendor/cigraph/src/community/edge_betweenness.c:504 : Membership vector will be
## selected based on the highest modularity score.
## Warning in cluster_edge_betweenness(grafo, weights = E(grafo)$weight): At
## vendor/cigraph/src/community/edge_betweenness.c:504 : Membership vector will be
## selected based on the highest modularity score.
## Warning in cluster_edge_betweenness(grafo, weights = E(grafo)$weight): At
## vendor/cigraph/src/community/edge_betweenness.c:504 : Membership vector will be
## selected based on the highest modularity score.
## Warning in cluster_edge_betweenness(grafo, weights = E(grafo)$weight): At
## vendor/cigraph/src/community/edge_betweenness.c:504 : Membership vector will be
## selected based on the highest modularity score.
## Warning in cluster_edge_betweenness(grafo, weights = E(grafo)$weight): At
## vendor/cigraph/src/community/edge_betweenness.c:504 : Membership vector will be
## selected based on the highest modularity score.
## Warning in cluster_edge_betweenness(grafo, weights = E(grafo)$weight): At
## vendor/cigraph/src/community/edge_betweenness.c:504 : Membership vector will be
## selected based on the highest modularity score.
## Warning in cluster_edge_betweenness(grafo, weights = E(grafo)$weight): At
## vendor/cigraph/src/community/edge_betweenness.c:504 : Membership vector will be
## selected based on the highest modularity score.
## Warning in cluster_edge_betweenness(grafo, weights = E(grafo)$weight): At
## vendor/cigraph/src/community/edge_betweenness.c:504 : Membership vector will be
## selected based on the highest modularity score.
## Warning in cluster_edge_betweenness(grafo, weights = E(grafo)$weight): At
## vendor/cigraph/src/community/edge_betweenness.c:504 : Membership vector will be
## selected based on the highest modularity score.
## Warning in cluster_edge_betweenness(grafo, weights = E(grafo)$weight): At
## vendor/cigraph/src/community/edge_betweenness.c:504 : Membership vector will be
## selected based on the highest modularity score.
## Warning in cluster_edge_betweenness(grafo, weights = E(grafo)$weight): At
## vendor/cigraph/src/community/edge_betweenness.c:504 : Membership vector will be
## selected based on the highest modularity score.
| GraphName | Modularity |
|---|---|
| gABph1 | NaN |
| gABph2 | 0.2187500 |
| gABph3 | 0.2448980 |
| gNBph1 | 0.0000000 |
| gNBph2 | 0.1035503 |
| gNBph3 | 0.0867769 |
| gONph1 | 0.0000000 |
| gONph2 | 0.2543136 |
| gONph3 | 0.0329556 |
| gSKph1 | 0.0000000 |
| gSKph2 | 0.0391837 |
| gSKph3 | 0.0084375 |
Average modularity is NaN
E-i index measures homophily based on a given attribute, in this case we select attitude toward nuclear. E-I index ranges from −1 (represents complete homophilly) to 1 (represents complete heterophilly).
| GraphName | EIIndex |
|---|---|
| gABph1 | NaN |
| gABph2 | -1.0000000 |
| gABph3 | -1.0000000 |
| gNBph1 | -1.0000000 |
| gNBph2 | -0.5384615 |
| gNBph3 | -1.0000000 |
| gONph1 | -1.0000000 |
| gONph2 | -0.5045872 |
| gONph3 | -0.5200000 |
| gSKph1 | 0.3333333 |
| gSKph2 | -1.0000000 |
| gSKph3 | -0.2250000 |
Average EI index is NaN