The HPCANDISC Procedure

Example 51.1 Analyzing Iris Data with PROC HPCANDISC

(View the complete code for this example.)

The iris data that were 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 in 50 iris specimens from each of three species: Iris setosa, I. versicolor, and I. virginica. The iris data set is available from the Sashelp library.

This example is a canonical discriminant analysis that creates an output data set that contains scores on the canonical variables and plots the canonical variables. The ID statement is specified to add the variable Species from the input data set to the output data set.

The following statements produce Output 51.1.1 through Output 51.1.6:

title 'Fisher (1936) Iris Data';

proc hpcandisc data=sashelp.iris out=outcan distance anova;
   id Species;
   class Species;
   var SepalLength SepalWidth PetalLength PetalWidth;
run;

Output 51.1.1 displays performance information, data access information, and summary information about the observations and the classes in the data set.

Output 51.1.1: Iris Data: Performance, Data Access, and Summary Information

Fisher (1936) Iris Data

The HPCANDISC Procedure

Performance Information
Execution ModeSingle-Machine
Number of Threads4

Data Access Information
DataEngineRolePath
SASHELP.IRISV9InputOn Client
WORK.OUTCANV9OutputOn Client

Total Sample Size150DF Total149
Variables4DF Within Classes147
Class Levels3DF Between Classes2

Number of Observations Read150
Number of Observations Used150

Class Level Information
SpeciesFrequencyWeightProportion
Setosa5050.000000.33333
Versicolor5050.000000.33333
Virginica5050.000000.33333


Output 51.1.2 shows results from the DISTANCE option in the PROC HPCANDISC statement, which display squared Mahalanobis distances between class means.

Output 51.1.2: Iris Data: Squared Mahalanobis Distances and Distance Statistics

Fisher (1936) Iris Data

The HPCANDISC Procedure

Squared Distance to Species
From SpeciesSetosaVersicolorVirginica
Setosa089.86419179.38471
Versicolor89.86419017.20107
Virginica179.3847117.201070

F Statistics, Num DF=4, Den DF=144 for Squared Distance to Species
From SpeciesSetosaVersicolorVirginica
Setosa0550.188891098.27375
Versicolor550.188890105.31265
Virginica1098.27375105.312650

Prob > Mahalanobis Distance for Squared Distance
to Species
From SpeciesSetosaVersicolorVirginica
Setosa1.0000<.0001<.0001
Versicolor<.00011.0000<.0001
Virginica<.0001<.00011.0000


Output 51.1.3 displays univariate and multivariate statistics. The ANOVA option uses univariate statistics to test the hypothesis that the class means are equal. The resulting R-square values range from 0.4008 for SepalWidth to 0.9414 for PetalLength, and each variable is significant at the 0.0001 level. The multivariate test for differences between the class levels (which is displayed by default) is also significant at the 0.0001 level; you would expect this from the highly significant univariate test results.

Output 51.1.3: Iris Data: Univariate and Multivariate Statistics

Fisher (1936) Iris Data

The HPCANDISC Procedure

Univariate Test Statistics
F Statistics, Num DF=2, Den DF=147
VariableLabelTotal
Standard
Deviation
Pooled
Standard
Deviation
Between
Standard
Deviation
R-SquareR-Square
/ (1-Rsq)
F ValuePr > F
SepalLengthSepal Length (mm)8.280665.147897.950610.61871.6226119.26<.0001
SepalWidthSepal Width (mm)4.358663.396883.368220.40080.668849.16<.0001
PetalLengthPetal Length (mm)17.652984.3033420.907000.941416.05661180.16<.0001
PetalWidthPetal Width (mm)7.622382.046508.967350.928913.0613960.01<.0001

Average R-Square
Unweighted0.7224358
Weighted by Variance0.8689444

Multivariate Statistics and F Approximations
S=2 M=0.5 N=71
StatisticValueF ValueNum DFDen DFPr > F
Wilks' Lambda0.023439199.158288<.0001
Pillai's Trace1.19189953.478290<.0001
Hotelling-Lawley Trace32.477320582.208203.4<.0001
Roy's Greatest Root32.1919291166.964145<.0001
NOTE: F Statistic for Roy's Greatest Root is an upper bound.
NOTE: F Statistic for Wilks' Lambda is exact.


Output 51.1.4 displays canonical correlations and eigenvalues. The R square between Can1 and the class variable, 0.969872, is much larger than the corresponding R square for Can2, 0.222027.

Output 51.1.4: Iris Data: Canonical Correlations and Eigenvalues

Fisher (1936) Iris Data

The HPCANDISC Procedure

 Canonical
Correlation
Adjusted
Canonical
Correlation
Approximate
Standard
Error
Squared
Canonical
Correlation
Eigenvalues of Inv(E)*H
= CanRsq/(1-CanRsq)
Test of H0: The canonical correlations in the current row and all that follow are zero
 EigenvalueDifferenceProportionCumulativeLikelihood
Ratio
Approximate
F Value
Num DFDen DFPr > F
10.9848210.9845080.0024680.96987232.191931.90650.99120.99120.02343863199.158288<.0001
20.4711970.4614450.0637340.2220270.2854 0.00881.00000.7779733713.793145<.0001


Output 51.1.5 displays correlations between canonical and original variables.

Output 51.1.5: Iris Data: Correlations between Canonical and Original Variables

Fisher (1936) Iris Data

The HPCANDISC Procedure

Total Canonical Structure
VariableLabelCan1Can2
SepalLengthSepal Length (mm)0.791890.21759
SepalWidthSepal Width (mm)-0.530760.75799
PetalLengthPetal Length (mm)0.984950.04604
PetalWidthPetal Width (mm)0.972810.22290

Between Canonical Structure
VariableLabelCan1Can2
SepalLengthSepal Length (mm)0.991470.13035
SepalWidthSepal Width (mm)-0.825660.56417
PetalLengthPetal Length (mm)0.999750.02236
PetalWidthPetal Width (mm)0.994040.10898

Pooled Within Canonical Structure
VariableLabelCan1Can2
SepalLengthSepal Length (mm)0.222600.31081
SepalWidthSepal Width (mm)-0.119010.86368
PetalLengthPetal Length (mm)0.706070.16770
PetalWidthPetal Width (mm)0.633180.73724


Output 51.1.6 displays canonical coefficients. The raw canonical coefficients for the first canonical variable, Can1, show that the class levels differ most widely on the linear combination of the centered variables: .

Output 51.1.6: Iris Data: Canonical Coefficients

Fisher (1936) Iris Data

The HPCANDISC Procedure

Total-Sample Standardized Canonical Coefficients
VariableLabelCan1Can2
SepalLengthSepal Length (mm)-0.686780.01996
SepalWidthSepal Width (mm)-0.668830.94344
PetalLengthPetal Length (mm)3.88580-1.64512
PetalWidthPetal Width (mm)2.142242.16414

Pooled Within-Class Standardized Canonical Coefficients
VariableLabelCan1Can2
SepalLengthSepal Length (mm)-0.426950.01241
SepalWidthSepal Width (mm)-0.521240.73526
PetalLengthPetal Length (mm)0.94726-0.40104
PetalWidthPetal Width (mm)0.575160.58104

Raw Canonical Coefficients
VariableLabelCan1Can2
SepalLengthSepal Length (mm)-0.082940.00241
SepalWidthSepal Width (mm)-0.153450.21645
PetalLengthPetal Length (mm)0.22012-0.09319
PetalWidthPetal Width (mm)0.281050.28392


Output 51.1.7 displays class means on canonical variables.

Output 51.1.7: Iris Data: Canonical Means

Class Means on Canonical Variables
SpeciesCan1Can2
Setosa-7.607600.21513
Versicolor1.82505-0.72790
Virginica5.782550.51277


The TEMPLATE and SGRENDER procedures are used to create a plot of the first two canonical variables. The following statements produce Output 51.1.8:

proc template;
   define statgraph scatter;
      begingraph;
         entrytitle 'Fisher (1936) Iris Data';
         layout overlayequated / equatetype=fit
            xaxisopts=(label='Canonical Variable 1')
            yaxisopts=(label='Canonical Variable 2');
            scatterplot x=Can1 y=Can2 / group=species name='iris';
            layout gridded / autoalign=(topleft);
               discretelegend 'iris' / border=false opaque=false;
            endlayout;
         endlayout;
      endgraph;
   end;
run;

proc sgrender data=outcan template=scatter;
run;

Output 51.1.8: Iris Data: Plot of First Two Canonical Variables

 Iris Data: Plot of First Two Canonical Variables


The plot of canonical variables in Output 51.1.8 shows that of the two canonical variables, Can1 has more discriminatory power.