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

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

nodecommunity_1community_2
011
122
222
322
422
532
632
732
822
911
1022
1132
1222
1322
1422
1511
1611
1732
1822
1911
2022
2111
2222
2311
2441
2541
2641
2711
2841
2941
3011
3111
3241
3311


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)

Karate Club Communities (Resolution = 1.0)


Figure 225: Karate Club Communities (Resolution = 0.5)

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

levelresolutioncommunitiesmodularity
11.040.41880
20.520.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

levelresolutioncommunitynodesintra_linksinter_linksdensitycut_ratioconductance
11.011120140.363640.0553360.25926
11.021224140.363640.0530300.22581
11.035640.600000.0275860.25000
11.0467100.466670.0595240.41667
20.511734100.250000.0346020.12821
20.521734100.250000.0346020.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

nodecommunityintensity
010.82353
020.17647
110.12500
120.87500
210.11111
220.88889
310.40000
320.60000
421.00000
521.00000
621.00000
721.00000
821.00000
910.60000
920.40000
1010.50000
1020.50000
1121.00000
1221.00000
1321.00000
1410.20000
1420.80000
1511.00000
1611.00000
1721.00000
1821.00000
1911.00000
2010.33333
2020.66667
2111.00000
2221.00000
2311.00000
2411.00000
2511.00000
2611.00000
2711.00000
2810.75000
2820.25000
2910.66667
2920.33333
3011.00000
3110.75000
3120.25000
3210.83333
3220.16667
3310.91667
3320.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.


Last updated: August 07, 2026