NETWORK Procedure
Example 2.6 Community Detection on Zachary’s Karate Club Data
This example uses Zachary’s Karate Club data (Zachary 1977), which describes social network friendships between 34 members of a karate club at a US university in the 1970s. This is one of the standard publicly available data tables for testing community detection algorithms. It contains 34 nodes and 78 links. The graph is shown in Figure 223.
Figure 223: Zachary’s Karate Club Graph

You can represent the graph by using the following links data table, mylib.LinkSetIn:
data mylib.LinkSetIn;
input from to @@;
datalines;
0 9 0 10 0 14 0 15 0 16 0 19 0 20 0 21
0 23 0 24 0 27 0 28 0 29 0 30 0 31 0 32
0 33 2 1 3 1 3 2 4 1 4 2 4 3 5 1
6 1 7 1 7 5 7 6 8 1 8 2 8 3 8 4
9 1 9 3 10 3 11 1 11 5 11 6 12 1 13 1
13 4 14 1 14 2 14 3 14 4 17 6 17 7 18 1
18 2 20 1 20 2 22 1 22 2 26 24 26 25 28 3
28 24 28 25 29 3 30 24 30 27 31 2 31 9 32 1
32 25 32 26 32 29 33 3 33 9 33 15 33 16 33 19
33 21 33 23 33 24 33 30 33 31 33 32
;
The following statements use the RESOLUTIONLIST= option to represent resolution levels (1, 0.5) in community detection on the Karate Club data. For more information about resolution levels, see the section Resolution List.
proc network
links = mylib.LinkSetIn
outNodes = mylib.NodeSetOut;
community
resolutionList = 1.0 0.5
outLevel = mylib.CommLevelOut
outCommunity = mylib.CommOut
outOverlap = mylib.CommOverlapOut
outCommLinks = mylib.CommLinksOut;
run;
The output data table mylib.NodeSetOut contains the community identifier of each node, as shown in Output 2.6.1.
Output 2.6.1: Community Nodes Output
| node | community_1 | community_2 |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 2 | 2 |
| 2 | 2 | 2 |
| 3 | 2 | 2 |
| 4 | 2 | 2 |
| 5 | 3 | 2 |
| 6 | 3 | 2 |
| 7 | 3 | 2 |
| 8 | 2 | 2 |
| 9 | 1 | 1 |
| 10 | 2 | 2 |
| 11 | 3 | 2 |
| 12 | 2 | 2 |
| 13 | 2 | 2 |
| 14 | 2 | 2 |
| 15 | 1 | 1 |
| 16 | 1 | 1 |
| 17 | 3 | 2 |
| 18 | 2 | 2 |
| 19 | 1 | 1 |
| 20 | 2 | 2 |
| 21 | 1 | 1 |
| 22 | 2 | 2 |
| 23 | 1 | 1 |
| 24 | 4 | 1 |
| 25 | 4 | 1 |
| 26 | 4 | 1 |
| 27 | 1 | 1 |
| 28 | 4 | 1 |
| 29 | 4 | 1 |
| 30 | 1 | 1 |
| 31 | 1 | 1 |
| 32 | 4 | 1 |
| 33 | 1 | 1 |
The column community_1 contains the community identifier of each node when the resolution value is 1.0; the column community_2 contains the community identifier of each node when the resolution value is 0.5. Different node colors are used to represent different communities in Figure 224 and Figure 225. As you can see from the figures, four communities at resolution 1.0 are merged into two communities at resolution 0.5.
Figure 224: Karate Club Communities (Resolution = 1.0)

Figure 225: Karate Club Communities (Resolution = 0.5)

The output data table mylib.CommLevelOut contains the number of communities and the corresponding modularity values found at each resolution level. It is shown in Output 2.6.2.
Output 2.6.2: Community Level Summary Output
| level | resolution | communities | modularity |
|---|---|---|---|
| 1 | 1.0 | 4 | 0.41880 |
| 2 | 0.5 | 2 | 0.37179 |
The output data table mylib.CommOut contains the number of nodes in each community, as shown in Output 2.6.3.
Output 2.6.3: Community Number of Nodes Output
| level | resolution | community | nodes | intra_links | inter_links | density | cut_ratio | conductance |
|---|---|---|---|---|---|---|---|---|
| 1 | 1.0 | 1 | 11 | 20 | 14 | 0.36364 | 0.055336 | 0.25926 |
| 1 | 1.0 | 2 | 12 | 24 | 14 | 0.36364 | 0.053030 | 0.22581 |
| 1 | 1.0 | 3 | 5 | 6 | 4 | 0.60000 | 0.027586 | 0.25000 |
| 1 | 1.0 | 4 | 6 | 7 | 10 | 0.46667 | 0.059524 | 0.41667 |
| 2 | 0.5 | 1 | 17 | 34 | 10 | 0.25000 | 0.034602 | 0.12821 |
| 2 | 0.5 | 2 | 17 | 34 | 10 | 0.25000 | 0.034602 | 0.12821 |
The output data table mylib.CommOverlapOut contains the intensity of each node that belongs to multiple communities. It is shown in Output 2.6.4. Note that only the communities in the last resolution level (the smallest resolution value) appear as output in this data table. In this example, Node 0 belongs to two communities, with 82.3% of its links connecting to Community 1 and 17.6% of its links connecting to Community 2.
Output 2.6.4: Community Overlap Output
| node | community | intensity |
|---|---|---|
| 0 | 1 | 0.82353 |
| 0 | 2 | 0.17647 |
| 1 | 1 | 0.12500 |
| 1 | 2 | 0.87500 |
| 2 | 1 | 0.11111 |
| 2 | 2 | 0.88889 |
| 3 | 1 | 0.40000 |
| 3 | 2 | 0.60000 |
| 4 | 2 | 1.00000 |
| 5 | 2 | 1.00000 |
| 6 | 2 | 1.00000 |
| 7 | 2 | 1.00000 |
| 8 | 2 | 1.00000 |
| 9 | 1 | 0.60000 |
| 9 | 2 | 0.40000 |
| 10 | 1 | 0.50000 |
| 10 | 2 | 0.50000 |
| 11 | 2 | 1.00000 |
| 12 | 2 | 1.00000 |
| 13 | 2 | 1.00000 |
| 14 | 1 | 0.20000 |
| 14 | 2 | 0.80000 |
| 15 | 1 | 1.00000 |
| 16 | 1 | 1.00000 |
| 17 | 2 | 1.00000 |
| 18 | 2 | 1.00000 |
| 19 | 1 | 1.00000 |
| 20 | 1 | 0.33333 |
| 20 | 2 | 0.66667 |
| 21 | 1 | 1.00000 |
| 22 | 2 | 1.00000 |
| 23 | 1 | 1.00000 |
| 24 | 1 | 1.00000 |
| 25 | 1 | 1.00000 |
| 26 | 1 | 1.00000 |
| 27 | 1 | 1.00000 |
| 28 | 1 | 0.75000 |
| 28 | 2 | 0.25000 |
| 29 | 1 | 0.66667 |
| 29 | 2 | 0.33333 |
| 30 | 1 | 1.00000 |
| 31 | 1 | 0.75000 |
| 31 | 2 | 0.25000 |
| 32 | 1 | 0.83333 |
| 32 | 2 | 0.16667 |
| 33 | 1 | 0.91667 |
| 33 | 2 | 0.08333 |
The output data table mylib.CommLinksOut shows how the communities are interconnected. It is shown in Output 2.6.5. In this example, when the resolution value is 1, the link weight between Communities 1 and 2 is 7, and the link weight between Communities 2 and 3 is 4.
Output 2.6.5: Community Links Output
| level | resolution | from_community | to_community | link_weight |
|---|---|---|---|---|
| 1 | 1.0 | 1 | 2 | 7 |
| 1 | 1.0 | 1 | 4 | 7 |
| 1 | 1.0 | 2 | 3 | 4 |
| 1 | 1.0 | 2 | 4 | 3 |
| 2 | 0.5 | 1 | 2 | 10 |