The CLUSTER Procedure

Example 34.2 Crude Birth and Death Rates

(View the complete code for this example.)

This example uses the SAS data set Poverty created in the section Getting Started: CLUSTER Procedure. The data, from Rouncefield (1995), are birth rates, death rates, and infant death rates for 97 countries. Six cluster analyses are performed with eight methods. Scatter plots showing cluster membership at selected levels are produced instead of tree diagrams.

Each cluster analysis is performed by a macro called ANALYZE. The macro takes two arguments. The first, &METHOD, specifies the value of the METHOD= option to be used in the PROC CLUSTER statement. The second, &NCL, must be specified as a list of integers, separated by blanks, indicating the number of clusters desired in each scatter plot. For example, the first invocation of ANALYZE specifies the AVERAGE method and requests plots of three and eight clusters. When two-stage density linkage is used, the K= and R= options are specified as part of the first argument.

The ANALYZE macro first invokes the CLUSTER procedure with METHOD=&METHOD, where &METHOD represents the value of the first argument to ANALYZE. This part of the macro produces the PROC CLUSTER output shown.

The %DO loop processes &NCL, the list of numbers of clusters to plot. The macro variable &K is a counter that indexes the numbers within &NCL. The %SCAN function picks out the kth number in &NCL, which is then assigned to the macro variable &N. When &K exceeds the number of numbers in &NCL, %SCAN returns a null string. Thus, the %DO loop executes while &N is not equal to a null string. In the %WHILE condition, a null string is indicated by the absence of any nonblank characters between the comparison operator (NE) and the right parenthesis that terminates the condition.

Within the %DO loop, the TREE procedure creates an output data set containing &N clusters. The SGPLOT procedure then produces a scatter plot in which each observation is identified by the number of the cluster to which it belongs. The TITLE2 statement uses double quotes so that &N and &METHOD can be used within the title. At the end of the loop, &K is incremented by 1, and the next number is extracted from &NCL by %SCAN.

title 'Cluster Analysis of Birth and Death Rates';
ods graphics on;

%macro analyze(method,ncl);
   proc cluster data=poverty outtree=tree method=&method print=15 ccc pseudo;
      var birth death;
      title2;
   run;

   %let k=1;
   %let n=%scan(&ncl,&k);
   %do %while(&n NE);

      proc tree data=tree noprint out=out ncl=&n;
         copy birth death;
      run;

      proc sgplot;
         scatter y=death x=birth / group=cluster;
         title2 "Plot of &n Clusters from METHOD=&METHOD";
      run;

      %let k=%eval(&k+1);
      %let n=%scan(&ncl,&k);
   %end;
%mend;

The following statement produces Output 34.2.1, Output 34.2.3, and Output 34.2.4:

%analyze(average, 3 8)

For average linkage, the CCC has peaks at three, eight, ten, and twelve clusters, but the three-cluster peak is lower than the eight-cluster peak. The pseudo F statistic has peaks at three, eight, and twelve clusters. The pseudo statistic drops sharply at three clusters, continues to fall at four clusters, and has a particularly low value at twelve clusters. However, there are not enough data to seriously consider as many as twelve clusters. Scatter plots are given for three and eight clusters. The results are shown in Output 34.2.1 through Output 34.2.4. In Output 34.2.4, the eighth cluster consists of the two outlying observations, Mexico and Korea.

Output 34.2.1: Cluster Analysis for Birth and Death Rates: METHOD=AVERAGE

Cluster Analysis of Birth and Death Rates

The CLUSTER Procedure
Average Linkage Cluster Analysis

Eigenvalues of the Covariance Matrix
 EigenvalueDifferenceProportionCumulative
1189.106588173.1010200.92200.9220
216.005568 0.07801.0000

Root-Mean-Square Total-Sample Standard Deviation10.127

Root-Mean-Square Distance Between Observations20.25399

Cluster History
Number
of
Clusters
Clusters JoinedFreqSemipartial
R-Square
R-SquareApproximate
Expected
R-Square
Cubic
Clustering
Criterion
Pseudo F
Statistic
Pseudo
t-Squared
Norm RMS
Distance
Tie
15CL27CL20180.0035.980.9752.6129218.60.2325 
14CL23CL17280.0034.977.9721.9727117.70.2358 
13CL18CL5480.0015.975.9692.352797.10.2432 
12CL21CL2680.0015.974.9662.852906.10.2493 
11CL19CL24120.0033.971.9622.7828514.80.2767 
10CL22CL16120.0036.967.9572.8428417.40.2858 
9CL15CL28220.0061.961.9512.4527117.50.3353 
8OB23OB6120.0014.960.9433.59302.0.3703 
7CL25CL11170.0098.950.9333.0128423.30.4033 
6CL7CL12250.0122.938.9202.6327314.80.4132 
5CL10CL14400.0303.907.9020.5922582.70.4584 
4CL13CL6330.0244.883.8750.7723422.20.5194 
3CL9CL8240.0182.865.8272.1330027.70.735 
2CL5CL3640.1836.681.697-.552031480.8402 
1CL2CL4970.6810.000.0000.00.2031.3348 


Output 34.2.2: Criteria for the Number of Clusters: METHOD=AVERAGE

Criteria for the Number of Clusters: METHOD=AVERAGE


Output 34.2.3: Plot of Three Clusters: METHOD=AVERAGE

Plot of Three Clusters: METHOD=AVERAGE


Output 34.2.4: Plot of Eight Clusters: METHOD=AVERAGE

Plot of Eight Clusters: METHOD=AVERAGE


The following statement produces Output 34.2.5 and Output 34.2.7:

%analyze(complete, 3)

Complete linkage shows CCC peaks at three, eight and twelve clusters. The pseudo F statistic peaks at three and twelve clusters. The pseudo statistic indicates three clusters.

The scatter plot for three clusters is shown.

Output 34.2.5: Cluster History for Birth and Death Rates: METHOD=COMPLETE

Cluster Analysis of Birth and Death Rates

The CLUSTER Procedure
Complete Linkage Cluster Analysis

Eigenvalues of the Covariance Matrix
 EigenvalueDifferenceProportionCumulative
1189.106588173.1010200.92200.9220
216.005568 0.07801.0000

Root-Mean-Square Total-Sample Standard Deviation10.127

Mean Distance Between Observations17.13099

Cluster History
Number
of
Clusters
Clusters JoinedFreqSemipartial
R-Square
R-SquareApproximate
Expected
R-Square
Cubic
Clustering
Criterion
Pseudo F
Statistic
Pseudo
t-Squared
Norm
Maximum
Distance
Tie
15CL22CL3380.0015.983.9753.803296.10.4092 
14CL56CL1880.0014.981.9723.973316.60.4255 
13CL30CL4480.0019.979.9694.0433019.00.4332 
12OB23OB6120.0014.978.9664.45340.0.4378 
11CL19CL24240.0034.974.9624.1732724.10.4962 
10CL17CL28120.0033.971.9574.1832514.80.5204 
9CL20CL13160.0067.964.9513.3829725.20.5236 
8CL11CL21320.0054.959.9433.4429719.70.6001 
7CL26CL15130.0096.949.9332.9328228.90.7233 
6CL14CL10200.0128.937.9202.4626927.70.8033 
5CL9CL16300.0237.913.9021.2924147.10.8993 
4CL6CL7330.0240.889.8751.3824821.71.2165 
3CL5CL12320.0178.871.8272.5631713.61.2326 
2CL3CL8640.1900.681.697-.552031671.5412 
1CL2CL4970.6810.000.0000.00.2032.5233 


Output 34.2.6: Criteria for the Number of Clusters: METHOD=COMPLETE

Criteria for the Number of Clusters: METHOD=COMPLETE


Output 34.2.7: Plot of Clusters for METHOD=COMPLETE

Plot of Clusters for METHOD=COMPLETE


The following statement produces Output 34.2.8 and Output 34.2.10:

%analyze(single, 7 10)

The CCC and pseudo F statistics are not appropriate for use with single linkage because of the method’s tendency to chop off tails of distributions. The pseudo statistic can be used by looking for large values and taking the number of clusters to be one greater than the level at which the large pseudo value is displayed. For these data, there are large values at levels 6 and 9, suggesting seven or ten clusters.

The scatter plots for seven and ten clusters are shown.

Output 34.2.8: Cluster History for Birth and Death Rates: METHOD=SINGLE

Cluster Analysis of Birth and Death Rates

The CLUSTER Procedure
Single Linkage Cluster Analysis

Eigenvalues of the Covariance Matrix
 EigenvalueDifferenceProportionCumulative
1189.106588173.1010200.92200.9220
216.005568 0.07801.0000

Root-Mean-Square Total-Sample Standard Deviation10.127

Mean Distance Between Observations17.13099

Cluster History
Number
of
Clusters
Clusters JoinedFreqSemipartial
R-Square
R-SquareApproximate
Expected
R-Square
Cubic
Clustering
Criterion
Pseudo F
Statistic
Pseudo
t-Squared
Norm
Minimum
Distance
Tie
15CL37CL1980.0014.968.975-2.31786.60.1331 
14CL20CL23150.0059.962.972-3.116218.70.1412 
13CL14CL16190.0054.957.969-3.41558.80.1442 
12CL26OB58310.0014.955.966-2.71654.00.1486 
11OB86CL1840.0003.955.962-1.61833.80.1495 
10CL13CL11230.0088.946.957-2.317011.30.1518 
9CL22CL17300.0235.923.951-4.713145.70.1593T
8CL15CL10310.0210.902.943-5.811721.80.1593 
7CL9OB75310.0052.897.933-4.71304.00.1628 
6CL7CL12620.2023.694.920-1541.32230.1725 
5CL6CL8930.6681.026.902-260.61990.1756 
4CL5OB48940.0056.021.875-240.70.50.1811T
3CL4OB67950.0083.012.827-150.60.80.1811 
2OB23OB6120.0014.011.697-131.0.0.4378 
1CL3CL2970.0109.000.0000.00.1.00.5815 


Output 34.2.9: Criteria for the Number of Clusters: METHOD=SINGLE

Criteria for the Number of Clusters: METHOD=SINGLE


Output 34.2.10: Plot of Clusters for METHOD=SINGLE

Plot of Clusters for METHOD=SINGLE
External File:images/cluex2gd1.png


The following statements produce Output 34.2.11 through Output 34.2.14:

%analyze(two k=10, 3)

%analyze(two k=18, 2)

For kth-nearest-neighbor density linkage, the number of modes as a function of k is as follows (not all of these analyses are shown):

k

 

Modes

3  

 

13

4  

 

6

5-7  

 

4

8-15  

 

3

16-21  

 

2

22+

 

1

Thus, there is strong evidence of three modes and an indication of the possibility of two modes. Uniform-kernel density linkage gives similar results. For K=10 (10th-nearest-neighbor density linkage), the scatter plot for three clusters is shown; and for K=18, the scatter plot for two clusters is shown.

Output 34.2.11: Cluster History for Birth and Death Rates: METHOD=TWOSTAGE K=10

Cluster Analysis of Birth and Death Rates

The CLUSTER Procedure
Two-Stage Density Linkage Clustering

Eigenvalues of the Covariance Matrix
 EigenvalueDifferenceProportionCumulative
1189.106588173.1010200.92200.9220
216.005568 0.07801.0000


K = 10

Root-Mean-Square Total-Sample Standard Deviation10.127

Cluster History
Number
of
Clusters
 FreqSemipartial
R-Square
R-SquareApproximate
Expected
R-Square
Cubic
Clustering
Criterion
Pseudo F
Statistic
Pseudo
t-Squared
Normalized
Fusion Density
Maximum Density
in Each Cluster
Tie
Clusters JoinedLesserGreater
15CL16OB94220.0015.921.975-1168.41.49.22346.792715.3069 
14CL19OB49280.0021.919.972-1172.41.88.73695.933433.4385 
13CL15OB52230.0024.917.969-1076.92.38.58475.965115.3069 
12CL13OB96240.0018.915.966-9.383.01.67.92525.472415.3069 
11CL12OB93250.0025.912.962-8.589.52.27.89135.440115.3069 
10CL11OB78260.0031.909.957-7.796.92.57.7875.408215.3069 
9CL10OB76270.0026.907.951-6.71072.17.71335.440115.3069 
8CL9OB77280.0023.904.943-5.51201.77.42564.901715.3069 
7CL8OB43290.0022.902.933-4.11381.66.9274.476415.3069 
6CL7OB87300.0043.898.920-2.71603.14.9322.997715.3069 
5CL6OB82310.0055.892.902-1.11913.73.73312.156015.3069 
4CL22OB61370.0079.884.8750.9323710.63.17131.6308100.0 
3CL14OB23290.0126.872.8272.6032010.42.06541.074433.4385 
2CL4CL3660.2129.659.697-1.318317212.40933.4385100.0 
1CL2CL5970.6588.000.0000.00.18310.07115.3069100.0 


3 modal clusters have been formed.


Output 34.2.12: Cluster History for Birth and Death Rates: METHOD=TWOSTAGE K=18

Cluster Analysis of Birth and Death Rates

The CLUSTER Procedure
Two-Stage Density Linkage Clustering

Eigenvalues of the Covariance Matrix
 EigenvalueDifferenceProportionCumulative
1189.106588173.1010200.92200.9220
216.005568 0.07801.0000


K = 18

Root-Mean-Square Total-Sample Standard Deviation10.127

Cluster History
Number
of
Clusters
 FreqSemipartial
R-Square
R-SquareApproximate
Expected
R-Square
Cubic
Clustering
Criterion
Pseudo F
Statistic
Pseudo
t-Squared
Normalized
Fusion Density
Maximum Density
in Each Cluster
Tie
Clusters JoinedLesserGreater
15CL16OB72460.0107.799.975-2123.33.010.1187.744523.4457 
14CL15OB94470.0098.789.972-2123.92.79.6767.125723.4457 
13CL14OB51480.0037.786.969-2025.61.09.4096.839823.4457T
12CL13OB96490.0099.776.966-1926.72.69.4096.839823.4457 
11CL12OB76500.0114.764.962-1927.92.98.81366.313823.4457 
10CL11OB77510.0021.762.957-1831.00.58.65936.075123.4457 
9CL10OB78520.0103.752.951-1733.32.58.60076.097623.4457 
8CL9OB43530.0034.748.943-1637.80.88.49645.916023.4457 
7CL8OB93540.0109.737.933-1542.12.68.3675.791323.4457 
6CL7OB88550.0110.726.920-1348.32.67.9165.367923.4457 
5CL6OB87560.0120.714.902-1257.52.76.69174.341523.4457 
4CL20OB61390.0077.707.875-9.874.78.36.25783.2882100.0 
3CL5OB82570.0138.693.827-5.01063.05.36053.283423.4457 
2CL3OB23580.0117.681.697-.542032.53.26871.756823.4457 
1CL2CL4970.6812.000.0000.00.20313.76423.4457100.0 


2 modal clusters have been formed.


Output 34.2.13: Plot of Clusters for METHOD=TWOSTAGE K=10

Plot of Clusters for METHOD=TWOSTAGE K=10


Output 34.2.14: Plot of Clusters for METHOD=TWOSTAGE K=18

Plot of Clusters for METHOD=TWOSTAGE K=18


In summary, most of the clustering methods indicate three or eight clusters. Most methods agree at the three-cluster level, but at the other levels, there is considerable disagreement about the composition of the clusters. The presence of numerous ties also complicates the analysis; see Example 34.4.