Example 35.1 Fisher’s Iris Data
The iris data published by Fisher (1936) have been widely used for examples in discriminant analysis and cluster analysis. The sepal length, sepal width, petal length, and petal width are measured in millimeters on 50 iris specimens from each of three species, Iris setosa, I. versicolor, and I. virginica. Mezzich and Solomon (1980) discuss a variety of cluster analysis of the iris data.
In this example, the FASTCLUS procedure is used to find two and then three clusters. In the following code, an output data set is created, and PROC FREQ is invoked to compare the clusters with the species classification. See Output 35.1.1 and Output 35.1.2 for these results.
For three clusters, you can use the CANDISC procedure to compute canonical variables for plotting the clusters. See Output 35.1.3 and Output 35.1.4 for the results.
proc format;
value specname
1='Setosa '
2='Versicolor'
3='Virginica ';
run;
data iris;
title 'Fisher (1936) Iris Data';
input SepalLength SepalWidth PetalLength PetalWidth Species @@;
format Species specname.;
label SepalLength='Sepal Length in mm.'
SepalWidth ='Sepal Width in mm.'
PetalLength='Petal Length in mm.'
PetalWidth ='Petal Width in mm.';
symbol = put(species, specname10.);
datalines;
50 33 14 02 1 64 28 56 22 3 65 28 46 15 2 67 31 56 24 3
63 28 51 15 3 46 34 14 03 1 69 31 51 23 3 62 22 45 15 2
59 32 48 18 2 46 36 10 02 1 61 30 46 14 2 60 27 51 16 2
65 30 52 20 3 56 25 39 11 2 65 30 55 18 3 58 27 51 19 3
68 32 59 23 3 51 33 17 05 1 57 28 45 13 2 62 34 54 23 3
... more lines ...
55 23 40 13 2 66 30 44 14 2 68 28 48 14 2 54 34 17 02 1
51 37 15 04 1 52 35 15 02 1 58 28 51 24 3 67 30 50 17 2
63 33 60 25 3 53 37 15 02 1
;
proc fastclus data=iris maxc=2 maxiter=10 out=clus;
var SepalLength SepalWidth PetalLength PetalWidth;
run;
proc freq;
tables cluster*species;
run;
proc fastclus data=iris maxc=3 maxiter=10 out=clus;
var SepalLength SepalWidth PetalLength PetalWidth;
run;
proc freq;
tables cluster*Species;
run;
proc candisc anova out=can;
class cluster;
var SepalLength SepalWidth PetalLength PetalWidth;
title2 'Canonical Discriminant Analysis of Iris Clusters';
run;
proc sgplot data=Can;
scatter y=Can2 x=Can1 /group=Cluster ;
title2 'Plot of Canonical Variables Identified by Cluster';
run;
Output 35.1.1
Fisher’s Iris Data: PROC FASTCLUS with MAXC=2 andPROC FREQ
The FASTCLUS Procedure
Replace=FULL Radius=0 Maxclusters=2 Maxiter=10 Converge=0.02
43.00000000 |
30.00000000 |
11.00000000 |
1.00000000 |
77.00000000 |
26.00000000 |
69.00000000 |
23.00000000 |
11.0638 |
0.1904 |
0.3163 |
5.3780 |
0.0596 |
0.0264 |
5.0718 |
0.0174 |
0.00766 |
Convergence criterion is satisfied. |
53 |
3.7050 |
21.1621 |
|
2 |
39.2879 |
97 |
5.6779 |
24.6430 |
|
1 |
39.2879 |
8.28066 |
5.49313 |
0.562896 |
1.287784 |
4.35866 |
3.70393 |
0.282710 |
0.394137 |
17.65298 |
6.80331 |
0.852470 |
5.778291 |
7.62238 |
3.57200 |
0.781868 |
3.584390 |
10.69224 |
5.07291 |
0.776410 |
3.472463 |
WARNING: The two values above are invalid for correlated variables.
50.05660377 |
33.69811321 |
15.60377358 |
2.90566038 |
63.01030928 |
28.86597938 |
49.58762887 |
16.95876289 |
3.427350930 |
4.396611045 |
4.404279486 |
2.105525249 |
6.336887455 |
3.267991438 |
7.800577673 |
4.155612484 |
Output 35.1.2
Fisher’s Iris Data: PROC FASTCLUS with MAXC=3 and PROC FREQ
The FASTCLUS Procedure
Replace=FULL Radius=0 Maxclusters=3 Maxiter=10 Converge=0.02
58.00000000 |
40.00000000 |
12.00000000 |
2.00000000 |
77.00000000 |
38.00000000 |
67.00000000 |
22.00000000 |
49.00000000 |
25.00000000 |
45.00000000 |
17.00000000 |
6.7591 |
0.2652 |
0.3205 |
0.2985 |
3.7097 |
0 |
0.0459 |
0.0317 |
3.6427 |
0 |
0.0182 |
0.0124 |
Convergence criterion is satisfied. |
50 |
2.7803 |
12.4803 |
|
3 |
33.5693 |
38 |
4.0168 |
14.9736 |
|
3 |
17.9718 |
62 |
4.0398 |
16.9272 |
|
2 |
17.9718 |
8.28066 |
4.39488 |
0.722096 |
2.598359 |
4.35866 |
3.24816 |
0.452102 |
0.825156 |
17.65298 |
4.21431 |
0.943773 |
16.784895 |
7.62238 |
2.45244 |
0.897872 |
8.791618 |
10.69224 |
3.66198 |
0.884275 |
7.641194 |
WARNING: The two values above are invalid for correlated variables.
50.06000000 |
34.28000000 |
14.62000000 |
2.46000000 |
68.50000000 |
30.73684211 |
57.42105263 |
20.71052632 |
59.01612903 |
27.48387097 |
43.93548387 |
14.33870968 |
3.524896872 |
3.790643691 |
1.736639965 |
1.053855894 |
4.941550255 |
2.900924461 |
4.885895746 |
2.798724562 |
4.664100551 |
2.962840548 |
5.088949673 |
2.974997167 |
Output 35.1.3
Fisher’s Iris Data using PROC CANDISC
_1 |
50 |
50.0000 |
0.333333 |
_2 |
38 |
38.0000 |
0.253333 |
_3 |
62 |
62.0000 |
0.413333 |
The CANDISC Procedure
Sepal Length in mm. |
8.2807 |
4.3949 |
8.5893 |
0.7221 |
2.5984 |
190.98 |
<.0001 |
Sepal Width in mm. |
4.3587 |
3.2482 |
3.5774 |
0.4521 |
0.8252 |
60.65 |
<.0001 |
Petal Length in mm. |
17.6530 |
4.2143 |
20.9336 |
0.9438 |
16.7849 |
1233.69 |
<.0001 |
Petal Width in mm. |
7.6224 |
2.4524 |
8.8164 |
0.8979 |
8.7916 |
646.18 |
<.0001 |
0.03222337 |
164.55 |
8 |
288 |
<.0001 |
1.25669612 |
61.29 |
8 |
290 |
<.0001 |
21.06722883 |
377.66 |
8 |
203.4 |
<.0001 |
20.63266809 |
747.93 |
4 |
145 |
<.0001 |
The CANDISC Procedure
0.976613 |
0.976123 |
0.003787 |
0.953774 |
20.6327 |
20.1981 |
0.9794 |
0.9794 |
0.03222337 |
164.55 |
8 |
288 |
<.0001 |
0.550384 |
0.543354 |
0.057107 |
0.302923 |
0.4346 |
|
0.0206 |
1.0000 |
0.69707749 |
21.00 |
3 |
145 |
<.0001 |
The CANDISC Procedure
Sepal Length in mm. |
0.831965 |
0.452137 |
Sepal Width in mm. |
-0.515082 |
0.810630 |
Petal Length in mm. |
0.993520 |
0.087514 |
Petal Width in mm. |
0.966325 |
0.154745 |
Sepal Length in mm. |
0.956160 |
0.292846 |
Sepal Width in mm. |
-0.748136 |
0.663545 |
Petal Length in mm. |
0.998770 |
0.049580 |
Petal Width in mm. |
0.995952 |
0.089883 |
Sepal Length in mm. |
0.339314 |
0.716082 |
Sepal Width in mm. |
-0.149614 |
0.914351 |
Petal Length in mm. |
0.900839 |
0.308136 |
Petal Width in mm. |
0.650123 |
0.404282 |
The CANDISC Procedure
Sepal Length in mm. |
0.047747341 |
1.021487262 |
Sepal Width in mm. |
-0.577569244 |
0.864455153 |
Petal Length in mm. |
3.341309573 |
-1.283043758 |
Petal Width in mm. |
0.996451144 |
0.900476563 |
Sepal Length in mm. |
0.0253414487 |
0.5421446856 |
Sepal Width in mm. |
-.4304161258 |
0.6442092294 |
Petal Length in mm. |
0.7976741592 |
-.3063023132 |
Petal Width in mm. |
0.3205998034 |
0.2897207865 |
Sepal Length in mm. |
0.0057661265 |
0.1233581748 |
Sepal Width in mm. |
-.1325106494 |
0.1983303556 |
Petal Length in mm. |
0.1892773419 |
-.0726814163 |
Petal Width in mm. |
0.1307270927 |
0.1181359305 |
-6.131527227 |
0.244761516 |
4.931414018 |
0.861972277 |
1.922300462 |
-0.725693908 |
Output 35.1.4
Plot of Fisher’s Iris Data using PROC CANDISC
Copyright © SAS Institute Inc. All rights reserved.