Chapter Contents 
Previous 
Next 
The FASTCLUS Procedure 
The following example demonstrates how to use the FASTCLUS procedure to compute disjoint clusters of observations in a SAS data set. The data in this example are measurements taken on 159 fish caught off the coast of Finland; this data set is available from the Data Archive of the Journal of Statistics Education. The complete data set is displayed in Chapter 60, "The STEPDISC Procedure."
The species (bream, parkki, pike, perch, roach, smelt, and whitefish), weight, three different length measurements (measured from the nose of the fish to the beginning of its tail, the notch of its tail, and the end of its tail), height, and width of each fish are tallied. The height and width are recorded as percentages of the third length variable.
Suppose that you want to group empirically the fish measurements into clusters and that you want to associate the clusters with the species. You can use the FASTCLUS procedure to perform a cluster analysis.
The following DATA step creates the SAS data set Fish.
proc format; value specfmt 1='Bream' 2='Roach' 3='Whitefish' 4='Parkki' 5='Perch' 6='Pike' 7='Smelt'; data Fish (drop=HtPct WidthPct); title 'Fish Measurement Data'; input Species Weight Length1 Length2 Length3 HtPct WidthPct @@; if Weight <=0 or Weight = . then delete; Weight3=Weight**(1/3); Height=HtPct*Length3/(Weight3*100); Width=WidthPct*Length3/(Weight3*100); Length1=Length1/Weight3; Length3=Length3/Weight3; logLengthRatio=log(Length3/Length1); format Species specfmt.; symbol = put(Species, specfmt2.); datalines; 1 242.0 23.2 25.4 30.0 38.4 13.4 1 290.0 24.0 26.3 31.2 40.0 13.8 1 340.0 23.9 26.5 31.1 39.8 15.1 1 363.0 26.3 29.0 33.5 38.0 13.3 ... [155 more records] ; run;
The double trailing at sign (@@) in the INPUT statement specifies that observations are input from each line until all values are read. The variables are rescaled in order to adjust for dimensionality. Because the new variables Weight3 logLengthRatio depend on the variable Weight, observations with missing values for Weight are not added to the data set. Consequently, there are 157 observations in the SAS data set Fish.
Variables with larger variances exert a larger influence in calculating the clusters. In the Fish data set, the variables are not measured in the same units and cannot be assumed to have equal variance. Therefore, it is necessary to standardize the variables before performing the cluster analysis.
The following statements standardize the variables and perform a cluster analysis on the standardized data.
proc standard data=Fish out=Stand mean=0 std=1; var Length1 logLengthRatio Height Width Weight3; proc fastclus data=Stand out=Clust maxclusters=7 maxiter=100 ; var Length1 logLengthRatio Height Width Weight3; run;
The STANDARD procedure is first used to standardize all the analytical variables to a mean of 0 and standard deviation of 1. The procedure creates the output data set Stand to contain the transformed variables.
The FASTCLUS procedure then uses the data set Stand as input and creates the data set Clust. This output data set contains the original variables and two new variables, Cluster and Distance. The variable Cluster contains the cluster number to which each observation has been assigned. The variable Distance gives the distance from the observation to its cluster seed.
It is usually desirable to try several values of the MAXCLUSTERS= option. A reasonable beginning for this example is to use MAXCLUSTERS=7, since there are seven species of fish represented in the data set Fish.
The VAR statement specifies the variables used in the cluster analysis.
The results from this analysis are displayed in the following figures.
Figure 27.1 displays the table of initial seeds used for each variable and cluster. The first line in the figure displays the option settings for REPLACE, RADIUS, MAXCLUSTERS, and MAXITER. These options, with the exception of MAXCLUSTERS and MAXITER, are set at their respective default values (REPLACE=FULL, RADIUS=0). Both the MAXCLUSTERS= and MAXITER= options are set in the PROC FASTCLUS statement.
Next, PROC FASTCLUS produces a table of summary statistics for the clusters. Figure 27.2 displays the number of observations in the cluster (frequency) and the root mean square standard deviation. The next two columns display the largest Euclidean distance from the cluster seed to any observation within the cluster and the number of the nearest cluster.
The last column of the table displays the distance between the centroid of the nearest cluster and the centroid of the current cluster. A centroid is the point having coordinates that are the means of all the observations in the cluster.

Figure 27.3 displays the table of statistics for the variables. The table lists for each variable the total standard deviation, the pooled withincluster standard deviation and the R^{2} value for predicting the variable from the cluster. The ratio of betweencluster variance to withincluster variance (R^{2} to 1  R^{2}) appears in the last column.

The pseudo F statistic, approximate expected overall R^{2}, and cubic clustering criterion (CCC) are listed at the bottom of the figure. You can compare values of these statistics by running PROC FASTCLUS with different values for the MAXCLUSTERS= option. The R^{2} and CCC values are not valid for correlated variables.
Values of the cubic clustering criterion greater than 2 or 3 indicate good clusters. Values between 0 and 2 indicate potential clusters, but they should be taken with caution; large negative values may indicate outliers.
PROC FASTCLUS next produces the withincluster means and standard deviations of the variables, displayed in Figure 27.4.

It is useful to study further the clusters calculated by the FASTCLUS procedure. One method is to look at a frequency tabulation of the clusters with other classification variables. The following statements invoke the FREQ procedure to crosstabulate the empirical clusters with the variable Species:
proc freq data=Clust; tables Species*Cluster; run;
These statements produce a frequency table of the variable Cluster versus the variable Species.
Figure 27.5 displays the marked division between clusters.

For cases in which you have three or more clusters, you can use the CANDISC and GPLOT procedures to obtain a graphical check on the distribution of the clusters. In the following statements, the CANDISC and GPLOT procedures are used to compute canonical variables and plot the clusters.
proc candisc data=Clust out=Can noprint; class Cluster; var Length1 logLengthRatio Height Width Weight3; legend1 frame cframe=ligr label=none cborder=black position=center value=(justify=center); axis1 label=(angle=90 rotate=0) minor=none; axis2 minor=none;
proc gplot data=Can; plot Can2*Can1=Cluster/frame cframe=ligr legend=legend1 vaxis=axis1 haxis=axis2; run;
First, the CANDISC procedure is invoked to perform a canonical discriminant analysis using the data set Clust and creating the output SAS data set Can. The NOPRINT option suppresses display of the output. The CLASS statement specifies the variable Cluster to define groups for the analysis. The VAR statement specifies the variables used in the analysis.
Next, the GPLOT procedure plots the two canonical variables from PROC CANDISC, Can1 and Can2. The PLOT statement specifies the variable Cluster as the identification variable.
The resulting plot (Figure 27.6) illustrates the spatial separation of the clusters calculated in the FASTCLUS procedure.
Chapter Contents 
Previous 
Next 
Top 
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.