The DISCRIM Procedure

Example 36.4 Linear Discriminant Analysis of Remote-Sensing Data on Crops

(View the complete code for this example.)

In this example, the remote-sensing data are used. In this data set, the observations are grouped into five crops: clover, corn, cotton, soybeans, and sugar beets. Four measures called x1 through x4 make up the descriptive variables.

In the first PROC DISCRIM statement, the DISCRIM procedure uses normal-theory methods (METHOD=NORMAL) assuming equal variances (POOL=YES) in five crops. The PRIORS statement, PRIORS PROP, sets the prior probabilities proportional to the sample sizes. The LIST option lists the resubstitution classification results for each observation (Output 36.4.2). The CROSSVALIDATE option displays cross validation error-rate estimates (Output 36.4.3). The OUTSTAT= option stores the calibration information in a new data set to classify future observations. A second PROC DISCRIM statement uses this calibration information to classify a test data set. Note that the values of the identification variable, xvalues, are obtained by rereading the x1 through x4 fields in the data lines as a single character variable. The following statements produce Output 36.4.1 through Output 36.4.3:

title 'Discriminant Analysis of Remote Sensing Data on Five Crops';

data crops;
   input Crop $ 1-10 x1-x4 xvalues $ 11-21;
   datalines;
Corn      16 27 31 33
Corn      15 23 30 30
Corn      16 27 27 26
Corn      18 20 25 23
Corn      15 15 31 32
Corn      15 32 32 15
Corn      12 15 16 73
Soybeans  20 23 23 25
Soybeans  24 24 25 32
Soybeans  21 25 23 24
Soybeans  27 45 24 12
Soybeans  12 13 15 42
Soybeans  22 32 31 43
Cotton    31 32 33 34
Cotton    29 24 26 28
Cotton    34 32 28 45
Cotton    26 25 23 24
Cotton    53 48 75 26
Cotton    34 35 25 78
Sugarbeets22 23 25 42
Sugarbeets25 25 24 26
Sugarbeets34 25 16 52
Sugarbeets54 23 21 54
Sugarbeets25 43 32 15
Sugarbeets26 54  2 54
Clover    12 45 32 54
Clover    24 58 25 34
Clover    87 54 61 21
Clover    51 31 31 16
Clover    96 48 54 62
Clover    31 31 11 11
Clover    56 13 13 71
Clover    32 13 27 32
Clover    36 26 54 32
Clover    53 08 06 54
Clover    32 32 62 16
;
title2 'Using the Linear Discriminant Function';

proc discrim data=crops outstat=cropstat method=normal pool=yes
   list crossvalidate;
   class Crop;
   priors prop;
   id xvalues;
   var x1-x4;
run;

Output 36.4.1: Linear Discriminant Function on Crop Data

Discriminant Analysis of Remote Sensing Data on Five Crops
Using the Linear Discriminant Function

The DISCRIM Procedure

Total Sample Size36DF Total35
Variables4DF Within Classes31
Classes5DF Between Classes4

Number of Observations Read36
Number of Observations Used36

Class Level Information
CropVariable
Name
FrequencyWeightProportionPrior
Probability
CloverClover1111.00000.3055560.305556
CornCorn77.00000.1944440.194444
CottonCotton66.00000.1666670.166667
SoybeansSoybeans66.00000.1666670.166667
SugarbeetsSugarbeets66.00000.1666670.166667

Pooled Covariance Matrix
Information
Covariance
Matrix Rank
Natural Log of the
Determinant of the
Covariance Matrix
421.30189

Discriminant Analysis of Remote Sensing Data on Five Crops
Using the Linear Discriminant Function

The DISCRIM Procedure

Generalized Squared Distance to Crop
From CropClover Corn Cotton Soybeans Sugarbeets
Clover2.371257.528304.449696.166655.07262
Corn6.624333.275225.467984.313836.47395
Cotton3.237415.159683.583525.018194.87908
Soybeans4.954384.005525.018193.583524.65998
Sugarbeets3.860346.165644.879084.659983.58352

Linear Discriminant Function for Crop
VariableClover Corn Cotton Soybeans Sugarbeets
Constant-10.98457-7.72070-11.46537-7.28260-9.80179
x10.08907-0.041800.024620.00003690.04245
x20.173790.119700.175960.158960.20988
x30.118990.165110.158800.106220.06540
x40.156370.167680.183620.141330.16408


Output 36.4.2: Misclassified Observations: Resubstitution

Discriminant Analysis of Remote Sensing Data on Five Crops
Using the Linear Discriminant Function

The DISCRIM Procedure
Classification Results for Calibration Data: WORK.CROPS
Resubstitution Results using Linear Discriminant Function

Posterior Probability of Membership in Crop
xvaluesFrom CropClassified into
Crop
Clover Corn Cotton Soybeans Sugarbeets
16 27 31 33CornCorn 0.08940.40540.17630.23920.0897
15 23 30 30CornCorn 0.07690.45580.14210.25300.0722
16 27 27 26CornCorn 0.09820.34220.13650.30730.1157
18 20 25 23CornCorn 0.10520.36340.10780.32810.0955
15 15 31 32CornCorn 0.05880.57540.11730.20870.0398
15 32 32 15CornSoybeans*0.09720.32780.13180.34200.1011
12 15 16 73CornCorn 0.04540.52380.18490.13760.1083
20 23 23 25SoybeansSoybeans 0.13300.28040.11760.33050.1385
24 24 25 32SoybeansSoybeans 0.17680.24830.15860.26600.1502
21 25 23 24SoybeansSoybeans 0.14810.24310.12000.33180.1570
27 45 24 12SoybeansSugarbeets*0.23570.05470.10160.27210.3359
12 13 15 42SoybeansCorn*0.05490.47490.09200.27680.1013
22 32 31 43SoybeansCotton*0.14740.26060.26240.18480.1448
31 32 33 34CottonClover*0.28150.15180.23770.17670.1523
29 24 26 28CottonSoybeans*0.25210.18420.15290.25490.1559
34 32 28 45CottonClover*0.31250.10230.24040.13570.2091
26 25 23 24CottonSoybeans*0.21210.18090.12450.30450.1780
53 48 75 26CottonClover*0.48370.03910.43840.02230.0166
34 35 25 78CottonCotton 0.22560.07940.38100.05920.2548
22 23 25 42SugarbeetsCorn*0.14210.30660.19010.22310.1381
25 25 24 26SugarbeetsSoybeans*0.19690.20500.13540.29600.1667
34 25 16 52SugarbeetsSugarbeets 0.29280.08710.16650.14790.3056
54 23 21 54SugarbeetsClover*0.62150.01940.12500.04960.1845
25 43 32 15SugarbeetsSoybeans*0.22580.11350.16460.27700.2191
26 54 2 54SugarbeetsSugarbeets 0.08500.00810.05210.06610.7887
12 45 32 54CloverCotton*0.06930.26630.33940.14600.1789
24 58 25 34CloverSugarbeets*0.16470.03760.16800.14520.4845
87 54 61 21CloverClover 0.93280.00030.04780.00250.0165
51 31 31 16CloverClover 0.66420.02050.08720.09590.1322
96 48 54 62CloverClover 0.92150.00020.06040.00070.0173
31 31 11 11CloverSugarbeets*0.25250.04020.04730.30120.3588
56 13 13 71CloverClover 0.61320.02120.12260.04080.2023
32 13 27 32CloverClover 0.26690.26160.15120.22600.0943
36 26 54 32CloverCotton*0.26500.26450.34950.09180.0292
53 08 06 54CloverClover 0.59140.02370.06760.07810.2392
32 32 62 16CloverCotton*0.21630.31800.33270.11250.0206

* Misclassified observation


Discriminant Analysis of Remote Sensing Data on Five Crops
Using the Linear Discriminant Function

The DISCRIM Procedure
Classification Summary for Calibration Data: WORK.CROPS
Resubstitution Summary using Linear Discriminant Function

Number of Observations and Percent Classified into Crop
From CropClover Corn Cotton Soybeans SugarbeetsTotal
Clover
6
54.55
0
0.00
3
27.27
0
0.00
2
18.18
11
100.00
Corn
0
0.00
6
85.71
0
0.00
1
14.29
0
0.00
7
100.00
Cotton
3
50.00
0
0.00
1
16.67
2
33.33
0
0.00
6
100.00
Soybeans
0
0.00
1
16.67
1
16.67
3
50.00
1
16.67
6
100.00
Sugarbeets
1
16.67
1
16.67
0
0.00
2
33.33
2
33.33
6
100.00
Total
10
27.78
8
22.22
5
13.89
8
22.22
5
13.89
36
100.00
Priors
0.30556
 
0.19444
 
0.16667
 
0.16667
 
0.16667
 
 
 

Error Count Estimates for Crop
 Clover Corn Cotton Soybeans SugarbeetsTotal
Rate0.45450.14290.83330.50000.66670.5000
Priors0.30560.19440.16670.16670.1667 


Output 36.4.3: Misclassified Observations: Cross Validation

Discriminant Analysis of Remote Sensing Data on Five Crops
Using the Linear Discriminant Function

The DISCRIM Procedure
Classification Summary for Calibration Data: WORK.CROPS
Cross-validation Summary using Linear Discriminant Function

Number of Observations and Percent Classified into Crop
From CropClover Corn Cotton Soybeans SugarbeetsTotal
Clover
4
36.36
3
27.27
1
9.09
0
0.00
3
27.27
11
100.00
Corn
0
0.00
4
57.14
1
14.29
2
28.57
0
0.00
7
100.00
Cotton
3
50.00
0
0.00
0
0.00
2
33.33
1
16.67
6
100.00
Soybeans
0
0.00
1
16.67
1
16.67
3
50.00
1
16.67
6
100.00
Sugarbeets
2
33.33
1
16.67
0
0.00
2
33.33
1
16.67
6
100.00
Total
9
25.00
9
25.00
3
8.33
9
25.00
6
16.67
36
100.00
Priors
0.30556
 
0.19444
 
0.16667
 
0.16667
 
0.16667
 
 
 

Error Count Estimates for Crop
 Clover Corn Cotton Soybeans SugarbeetsTotal
Rate0.63640.42861.00000.50000.83330.6667
Priors0.30560.19440.16670.16670.1667 


Next, you can use the calibration information stored in the Cropstat data set to classify a test data set. The TESTLIST option lists the classification results for each observation in the test data set. The following statements produce Output 36.4.4 and Output 36.4.5:

data test;
   input Crop $ 1-10 x1-x4 xvalues $ 11-21;
   datalines;
Corn      16 27 31 33
Soybeans  21 25 23 24
Cotton    29 24 26 28
Sugarbeets54 23 21 54
Clover    32 32 62 16
;
title2 'Classification of Test Data';

proc discrim data=cropstat testdata=test testout=tout testlist;
   class Crop;
   testid xvalues;
   var x1-x4;
run;

proc print data=tout;
   title 'Discriminant Analysis of Remote Sensing Data on Five Crops';
   title2 'Output Classification Results of Test Data';
run;

Output 36.4.4: Classification of Test Data

Discriminant Analysis of Remote Sensing Data on Five Crops
Classification of Test Data

The DISCRIM Procedure
Classification Results for Test Data: WORK.TEST
Classification Results using Linear Discriminant Function

Posterior Probability of Membership in Crop
xvaluesFrom CropClassified into
Crop
Clover Corn Cotton Soybeans Sugarbeets
16 27 31 33CornCorn 0.08940.40540.17630.23920.0897
21 25 23 24SoybeansSoybeans 0.14810.24310.12000.33180.1570
29 24 26 28CottonSoybeans*0.25210.18420.15290.25490.1559
54 23 21 54SugarbeetsClover*0.62150.01940.12500.04960.1845
32 32 62 16CloverCotton*0.21630.31800.33270.11250.0206

* Misclassified observation


Discriminant Analysis of Remote Sensing Data on Five Crops
Classification of Test Data

The DISCRIM Procedure
Classification Summary for Test Data: WORK.TEST
Classification Summary using Linear Discriminant Function

Observation Profile for Test Data
Number of Observations Read5
Number of Observations Used5

Number of Observations and Percent Classified into Crop
From CropClover Corn Cotton Soybeans SugarbeetsTotal
Clover
0
0.00
0
0.00
1
100.00
0
0.00
0
0.00
1
100.00
Corn
0
0.00
1
100.00
0
0.00
0
0.00
0
0.00
1
100.00
Cotton
0
0.00
0
0.00
0
0.00
1
100.00
0
0.00
1
100.00
Soybeans
0
0.00
0
0.00
0
0.00
1
100.00
0
0.00
1
100.00
Sugarbeets
1
100.00
0
0.00
0
0.00
0
0.00
0
0.00
1
100.00
Total
1
20.00
1
20.00
1
20.00
2
40.00
0
0.00
5
100.00
Priors
0.30556
 
0.19444
 
0.16667
 
0.16667
 
0.16667
 
 
 

Error Count Estimates for Crop
 Clover Corn Cotton Soybeans SugarbeetsTotal
Rate1.00000.00001.00000.00001.00000.6389
Priors0.30560.19440.16670.16670.1667 


Output 36.4.5: Output Data Set of the Classification Results for Test Data

Discriminant Analysis of Remote Sensing Data on Five Crops
Output Classification Results of Test Data

ObsCropx1x2x3x4xvaluesCloverCornCottonSoybeansSugarbeets_INTO_
1Corn1627313316 27 31 330.089350.405430.176320.239180.08972Corn
2Soybeans2125232421 25 23 240.148110.243080.119990.331840.15698Soybeans
3Cotton2924262829 24 26 280.252130.184200.152940.254860.15588Soybeans
4Sugarbeets5423215454 23 21 540.621500.019370.124980.049620.18452Clover
5Clover3232621632 32 62 160.216330.317990.332660.112460.02056Cotton


In this next example, PROC DISCRIM uses normal-theory methods (METHOD=NORMAL) assuming unequal variances (POOL=NO) for the remote-sensing data. The PRIORS statement, PRIORS PROP, sets the prior probabilities proportional to the sample sizes. The CROSSVALIDATE option displays cross validation error-rate estimates. Note that the total error count estimate by cross validation (0.5556) is much larger than the total error count estimate by resubstitution (0.1111). The following statements produce Output 36.4.6:

title2 'Using Quadratic Discriminant Function';

proc discrim data=crops method=normal pool=no crossvalidate;
   class Crop;
   priors prop;
   id xvalues;
   var x1-x4;
run;

Output 36.4.6: Quadratic Discriminant Function on Crop Data

Discriminant Analysis of Remote Sensing Data on Five Crops
Using Quadratic Discriminant Function

The DISCRIM Procedure

Total Sample Size36DF Total35
Variables4DF Within Classes31
Classes5DF Between Classes4

Number of Observations Read36
Number of Observations Used36

Class Level Information
CropVariable
Name
FrequencyWeightProportionPrior
Probability
CloverClover1111.00000.3055560.305556
CornCorn77.00000.1944440.194444
CottonCotton66.00000.1666670.166667
SoybeansSoybeans66.00000.1666670.166667
SugarbeetsSugarbeets66.00000.1666670.166667

Within Covariance Matrix Information
CropCovariance
Matrix Rank
Natural Log of the
Determinant of the
Covariance Matrix
Clover423.64618
Corn411.13472
Cotton413.23569
Soybeans412.45263
Sugarbeets417.76293

Discriminant Analysis of Remote Sensing Data on Five Crops
Using Quadratic Discriminant Function

The DISCRIM Procedure

Generalized Squared Distance to Crop
From CropClover Corn Cotton Soybeans Sugarbeets
Clover26.017431320104.18297194.1054631.40816
Corn27.7380914.40994150.5076338.3625225.55421
Cotton26.38544588.8623216.8192152.0326637.15560
Soybeans27.0713446.4213141.0163116.0361523.15920
Sugarbeets26.80188332.1156343.98280107.9567621.34645

Discriminant Analysis of Remote Sensing Data on Five Crops
Using Quadratic Discriminant Function

The DISCRIM Procedure
Classification Summary for Calibration Data: WORK.CROPS
Resubstitution Summary using Quadratic Discriminant Function

Number of Observations and Percent Classified into Crop
From CropClover Corn Cotton Soybeans SugarbeetsTotal
Clover
9
81.82
0
0.00
0
0.00
0
0.00
2
18.18
11
100.00
Corn
0
0.00
7
100.00
0
0.00
0
0.00
0
0.00
7
100.00
Cotton
0
0.00
0
0.00
6
100.00
0
0.00
0
0.00
6
100.00
Soybeans
0
0.00
0
0.00
0
0.00
6
100.00
0
0.00
6
100.00
Sugarbeets
0
0.00
0
0.00
1
16.67
1
16.67
4
66.67
6
100.00
Total
9
25.00
7
19.44
7
19.44
7
19.44
6
16.67
36
100.00
Priors
0.30556
 
0.19444
 
0.16667
 
0.16667
 
0.16667
 
 
 

Error Count Estimates for Crop
 Clover Corn Cotton Soybeans SugarbeetsTotal
Rate0.18180.00000.00000.00000.33330.1111
Priors0.30560.19440.16670.16670.1667 

Discriminant Analysis of Remote Sensing Data on Five Crops
Using Quadratic Discriminant Function

The DISCRIM Procedure
Classification Summary for Calibration Data: WORK.CROPS
Cross-validation Summary using Quadratic Discriminant Function

Number of Observations and Percent Classified into Crop
From CropClover Corn Cotton Soybeans SugarbeetsTotal
Clover
9
81.82
0
0.00
0
0.00
0
0.00
2
18.18
11
100.00
Corn
3
42.86
2
28.57
0
0.00
0
0.00
2
28.57
7
100.00
Cotton
3
50.00
0
0.00
2
33.33
0
0.00
1
16.67
6
100.00
Soybeans
3
50.00
0
0.00
0
0.00
2
33.33
1
16.67
6
100.00
Sugarbeets
3
50.00
0
0.00
1
16.67
1
16.67
1
16.67
6
100.00
Total
21
58.33
2
5.56
3
8.33
3
8.33
7
19.44
36
100.00
Priors
0.30556
 
0.19444
 
0.16667
 
0.16667
 
0.16667
 
 
 

Error Count Estimates for Crop
 Clover Corn Cotton Soybeans SugarbeetsTotal
Rate0.18180.71430.66670.66670.83330.5556
Priors0.30560.19440.16670.16670.1667