The FASTCLUS Procedure

Example 39.2 Outliers

(View the complete code for this example.)

This example involves data artificially generated to contain two clusters and several severe outliers. A preliminary analysis specifies 20 clusters and outputs an OUTSEED= data set to be used for a diagnostic plot. The exact number of initial clusters is not important; similar results could be obtained with 10 or 50 initial clusters. Examination of the plot suggests that clusters with more than five (again, the exact number is not important) observations can yield good seeds for the main analysis. A DATA step deletes clusters with five or fewer observations, and the remaining cluster means provide seeds for the next PROC FASTCLUS analysis.

Two clusters are requested; the LEAST= option specifies the mean absolute deviation criterion (LEAST=1). Values of the LEAST= option less than 2 reduce the effect of outliers on cluster centers.

The next analysis also requests two clusters; the STRICT= option is specified to prevent outliers from distorting the results. The STRICT= value is chosen to be close to the _GAP_ and _RADIUS_ values of the larger clusters in the diagnostic plot; the exact value is not critical.

A final PROC FASTCLUS run assigns the outliers to clusters.

The following SAS statements implement these steps, and the results are displayed in Output 39.2.3 through Output 39.2.8. First, an artificial data set is created with two clusters and some outliers. Then PROC FASTCLUS is run with many clusters to produce an OUTSEED= data set. A diagnostic plot using the variables _GAP_ and _RADIUS_ is then produced using the SGSCATTER procedure. The results from these steps are shown in Output 39.2.1 and Output 39.2.2.

title 'Using PROC FASTCLUS to Analyze Data with Outliers';
data x;
   drop n;
   do n=1 to 100;
      x=rannor(12345)+2;
      y=rannor(12345);
      output;
   end;
   do n=1 to 100;
      x=rannor(12345)-2;
      y=rannor(12345);
      output;
   end;
   do n=1 to 10;
      x=10*rannor(12345);
      y=10*rannor(12345);
      output;
   end;
run;

title2 'Preliminary PROC FASTCLUS Analysis with 20 Clusters';
proc fastclus data=x outseed=mean1 maxc=20 maxiter=0 summary;
   var x y;
run;

proc sgscatter data=mean1;
   compare y=(_gap_ _radius_) x=_freq_;
run;

Output 39.2.1: Preliminary Analysis of Data with Outliers Using PROC FASTCLUS

Using PROC FASTCLUS to Analyze Data with Outliers
Preliminary PROC FASTCLUS Analysis with 20 Clusters

The FASTCLUS Procedure
Replace=FULL Radius=0 Maxclusters=20 Maxiter=0

Criterion Based on Final Seeds =0.6873

Cluster Summary
ClusterFrequencyRMS Std DeviationMaximum Distance
from Seed
to Observation
Radius
Exceeded
Nearest ClusterDistance Between
Cluster Centroids
180.47531.1924 191.7205
21.0 66.2847
3440.62521.6774 51.4386
41.0 205.2130
5380.56031.4528 31.4386
620.05420.1085 26.2847
71.0 142.5094
820.64801.2961 11.8450
91.0 79.4534
101.0 184.2514
111.0 164.7582
12200.59111.6291 161.5601
1350.66821.4244 31.9553
141.0 72.5094
1550.40741.2678 31.7609
16220.41681.5139 191.4936
1780.40311.4794 51.5564
181.0 104.2514
19450.64751.6285 161.4936
2030.57191.3642 151.8999

Pseudo F Statistic =207.58

Observed Over-All R-Squared =0.95404

Approximate Expected Over-All R-Squared =0.96103

Cubic Clustering Criterion =-2.503


WARNING: The two values above are invalid for correlated variables.


Output 39.2.2: Preliminary Analysis of Data with Outliers: Plot Using and PROC SGSCATTER

Preliminary Analysis of Data with Outliers: Plot Using and PROC SGSCATTER


In the following SAS statements, a DATA step is used to remove low frequency clusters, then the FASTCLUS procedure is run again, selecting seeds from the high frequency clusters in the previous analysis using LEAST=1 clustering criterion. The results are shown in Output 39.2.3 and Output 39.2.4.

data seed;
   set mean1;
   if _freq_>5;
run;

title2 'PROC FASTCLUS Analysis Using LEAST= Clustering Criterion';
title3 'Values < 2 Reduce Effect of Outliers on Cluster Centers';
proc fastclus data=x seed=seed maxc=2 least=1 out=out;
   var x y;
run;

proc sgplot data=out;
   scatter y=y x=x / group=cluster;
run;

Output 39.2.3: Analysis of Data with Outliers Using the LEAST= Option

Using PROC FASTCLUS to Analyze Data with Outliers
PROC FASTCLUS Analysis Using LEAST= Clustering Criterion
Values < 2 Reduce Effect of Outliers on Cluster Centers

The FASTCLUS Procedure
Replace=FULL Radius=0 Maxclusters=2 Maxiter=20 Converge=0.0001 Least=1

Initial Seeds
Clusterxy
12.794174248-0.065970836
2-2.027300384-2.051208579

Minimum Distance Between Initial Seeds =6.806712

Preliminary L(1) Scale Estimate =2.796579

Number of Bins =100

Iteration History
IterationCriterionMaximum Bin SizeRelative Change in Cluster
Seeds
1 2
11.39830.22630.40910.6696
21.07760.02260.005110.0452
31.07710.002260.002290.00234
41.07710.0003960.0002530.000144
51.07710.00039600

Convergence criterion is satisfied.

Criterion Based on Final Seeds =1.0771

Cluster Summary
ClusterFrequencyMean Absolute
Deviation
Maximum Distance
from Seed
to Observation
Radius
Exceeded
Nearest ClusterDistance Between
Cluster Medians
11021.127824.1622 24.2585
21081.049414.8292 14.2585

Cluster Medians
Clusterxy
11.9230238870.222482918
2-1.826721743-0.286253041

Mean Absolute Deviations from Final
Seeds
Clusterxy
11.1134652611.142120480
20.8903318351.208370913


Output 39.2.4: Analysis Plot of Data with Outliers

Analysis Plot of Data with Outliers


The FASTCLUS procedure is run again, selecting seeds from high frequency clusters in the previous analysis. STRICT= prevents outliers from distorting the results. The results are shown in Output 39.2.5 and Output 39.2.6.

title2 'PROC FASTCLUS Analysis Using STRICT= to Omit Outliers';
proc fastclus data=x seed=seed
     maxc=2 strict=3.0 out=out outseed=mean2;
   var x y;
run;

proc sgplot data=out;
   scatter y=y  x=x / group=cluster;
run;

Output 39.2.5: Cluster Analysis with Outliers Omitted: PROC FASTCLUS SGPLOT

Using PROC FASTCLUS to Analyze Data with Outliers
PROC FASTCLUS Analysis Using STRICT= to Omit Outliers

The FASTCLUS Procedure
Replace=FULL Radius=0 Strict=3 Maxclusters=2 Maxiter=1

Initial Seeds
Clusterxy
12.794174248-0.065970836
2-2.027300384-2.051208579

Criterion Based on Final Seeds =0.9515

Cluster Summary
ClusterFrequencyRMS Std DeviationMaximum Distance
from Seed
to Observation
Radius
Exceeded
Nearest ClusterDistance Between
Cluster Centroids
1990.95012.9589 23.7666
2990.92902.8011 13.7666


12 Observation(s) were not assigned to a cluster  because the minimum distance to a cluster seed  exceeded the STRICT= value.

Statistics for Variables
VariableTotal STDWithin STDR-SquareRSQ/(1-RSQ)
x2.068540.870980.8236094.669219
y1.021131.003520.0390930.040683
OVER-ALL1.631190.939590.6698912.029303

Pseudo F Statistic =397.74

Approximate Expected Over-All R-Squared =0.60615

Cubic Clustering Criterion =3.197


WARNING: The two values above are invalid for correlated variables.

Cluster Means
Clusterxy
11.8251114320.141211701
2-1.919910712-0.261558725

Cluster Standard Deviations
Clusterxy
10.8895492711.006965219
20.8520005881.000062579


Output 39.2.6: Cluster Analysis with Outliers Omitted: Plot Using PROC SGPLOT

Cluster Analysis with Outliers Omitted: Plot Using PROC SGPLOT


Finally, the FASTCLUS procedure is run one more time with zero iterations to assign outliers and tails to clusters. The results are show in Output 39.2.7 and Output 39.2.8.

title2 'Final PROC FASTCLUS Analysis Assigning Outliers to Clusters';
proc fastclus data=x seed=mean2 maxc=2 maxiter=0 out=out;
   var x y;
run;

proc sgplot data=out;
   scatter y=y x=x / group=cluster;
run;

Output 39.2.7: Cluster Analysis with Outliers Omitted: PROC FASTCLUS

Using PROC FASTCLUS to Analyze Data with Outliers
Final PROC FASTCLUS Analysis Assigning Outliers to Clusters

The FASTCLUS Procedure
Replace=FULL Radius=0 Maxclusters=2 Maxiter=0

Initial Seeds
Clusterxy
11.8251114320.141211701
2-1.919910712-0.261558725

Criterion Based on Final Seeds =2.0594

Cluster Summary
ClusterFrequencyRMS Std DeviationMaximum Distance
from Seed
to Observation
Radius
Exceeded
Nearest ClusterDistance Between
Cluster Centroids
11032.256917.9426 24.3753
21071.837111.7362 14.3753

Statistics for Variables
VariableTotal STDWithin STDR-SquareRSQ/(1-RSQ)
x2.927211.955290.5559501.252000
y2.152482.147540.0093470.009435
OVER-ALL2.569222.053670.3641190.572621

Pseudo F Statistic =119.11

Approximate Expected Over-All R-Squared =0.49090

Cubic Clustering Criterion =-5.338


WARNING: The two values above are invalid for correlated variables.

Cluster Means
Clusterxy
12.2800174690.263940765
2-2.075547895-0.151348765

Cluster Standard Deviations
Clusterxy
12.4122648612.089922815
21.3793558782.201567557


Output 39.2.8: Cluster Analysis with Outliers Omitted: Plot Using PROC SGPLOT

Cluster Analysis with Outliers Omitted: Plot Using PROC SGPLOT