The HPCLUS Procedure
Getting Started: HPCLUS Procedure
This example shows how to use the HPCLUS procedure to compute clusters of observations in a SAS data set.
Suppose you want to group the observations in inputData, in which the variables are raw measures on interval scales.
The following SAS DATA step creates the SAS data set inputData, which has four variables: the first two variables are the input variables among which x has missing values, the third variable is the frequency variable, and the last variable is an index variable.
data inputData;
title 'Using PROC HPCLUS to Analyze Data';
drop n;
id=1;
do n=1 to 1000;
x=2*rannor(12345)+20;
y=4*rannor(12345)+20;
freq = 1;
id = id + 1;
output;
end;
do n=1 to 1000;
x=3*rannor(12345)+10;
y=5*rannor(12345)+10;
freq=2;
id = id + 1;
output;
end;
do n=1 to 700;
x=10*rannor(12345);
y=10*rannor(12345);
freq=1;
id = id + 1;
output;
end;
do n=1 to 200;
x=.;
y=10*rannor(12345);
freq=1;
id = id + 1;
output;
end;
run;
The following statements run PROC HPCLUS and output the results to ODS tables:
proc hpclus data=inputData maxclusters=3;
input x y;
freq freq;
run;
Figure 1 shows the values of the parameters that are used in clustering. Because MAXCLUSTERS=3 and the number of clusters is not estimated by default, three clusters are generated. Figure 1 shows the number of clusters and default values for other options.
Figure 1: Model Information
| Model Information | |
|---|---|
| Maximum Iteration | 10 |
| Stop Criterion | Cluster Change |
| Stop Criterion Value | 0 |
| Clusters | 3 |
| Seed Initialization | 12345 |
| Distance | Euclidean |
Figure 2 shows that the "Number of Observations Used" is less than “Number of Observations Read.” By default, the HPCLUS procedure ignores observations that have missing values, and it does not use them in cluster analysis. The two additional rows, "Sum of Frequencies Read" and “Sum of Frequencies Used,” are displayed when the FREQ statement is specified. They provide information about the frequency values that are read and used.
Figure 2: Number of Observations
| Number of Observations Read | 2900 |
|---|---|
| Number of Observations Used | 2700 |
| Sum of Frequencies Read | 3900 |
| Sum of Frequencies Used | 3700 |
Figure 3 shows the statistics for each cluster. For each cluster, this table shows the number of observations; the maximum, minimum, and average distances from that cluster’s centroid to the observations in that cluster; the sum of squares error; and the standard deviation. In addition, Figure 3 displays information about the nearest cluster to that cluster and the distance between their centroids.
Figure 3: Cluster Summary
| Cluster Summary | ||||||||
|---|---|---|---|---|---|---|---|---|
| Cluster | Frequency | Distance from Cluster Centroid to Observation | SSE | Standard Deviation | Nearest Cluster | Distance to Nearest Cluster Centroid | ||
| Maximum | Minimum | Average | ||||||
| 1 | 2042 | 31.8174 | 0.2222 | 5.1753 | 77850.8 | 6.1745 | 2 | 13.8708 |
| 2 | 1157 | 29.2421 | 0.0395 | 4.4134 | 30848.0 | 5.1635 | 1 | 13.8708 |
| 3 | 501 | 30.7357 | 0.7688 | 10.7289 | 75041.2 | 12.2386 | 1 | 18.2334 |
Figure 4 shows the sum of squares error (SSE) for each iteration.
Figure 4: Iteration Statistics
| Iteration Statistics | |
|---|---|
| Iteration Number | SSE |
| 0 | 363065 |
| 1 | 280328 |
| 2 | 236942 |
| 3 | 197374 |
| 4 | 187016 |
| 5 | 184540 |
| 6 | 184026 |
| 7 | 183921 |
| 8 | 183816 |
| 9 | 183754 |
| 10 | 183740 |
Figure 5 and Figure 6 show the statistics for each variable in the INPUT statement. Figure 5 shows the variable statistics for all the observations in the input data set, and Figure 6 shows the variable statistics for the observations that belong to a specific cluster.
Figure 5: Descriptive Statistics
| Descriptive Statistics | ||
|---|---|---|
| Variable | Mean | Standard Deviation |
| x | 11.020648 | 8.189686 |
| y | 10.756547 | 9.180654 |
Figure 6: Within-Cluster Statistics
| Within Cluster Statistics | |||
|---|---|---|---|
| Variable | Cluster | Mean | Standard Deviation |
| x | 1 | 9.6471 | 10.5402 |
| 2 | 19.0775 | 5.8267 | |
| 3 | -1.9872 | 9.0487 | |
| y | 1 | 9.4768 | 11.0994 |
| 2 | 19.6486 | 7.7187 | |
| 3 | -4.5625 | 8.4227 | |