一个例子:贝叶斯判别法
data d522;
input group x1-x7 @@;
cards;
1 166 15.8 24.5 700 112 179 513
1 185 15.7 31.5 701 125 184 427
1 193 9.8 25.9 541 163 128 642
1 159 14.2 39.7 896 99.2 239 726
1 226 16.2 23.8 606 152 70.3 218
1 171 9.29 9.29 307 187 45.5 257
1 201 13.3 26.6 551 101 49.4 141
1 147 14.5 30 659 102 154 680
1 172 8.85 7.86 551 75.7 98.4 318
1 156 11.5 32.5 639 107 103 552
1 132 15.9 17.7 578 92.4 1314 1372
1 182 11.3 11.3 767 111 264 672
1 186 9.26 37.1 958 233 73 347
1 162 8.23 27.1 625 108 62.4 465
1 150 6.63 21 627 140 179 639
1 159 10.7 11.7 612 190 98.5 390
1 117 16.1 7.04 988 95.5 136 572
1 181 10.1 4.04 1437 184 101 542
1 146 20.7 23.8 1232 128 150 1092
1 42.3 10.3 9.7 629 93.7 439 888
1 28.2 12.4 53.1 370 44.1 454 852
1 154 13.8 53.3 621 105 160 723
1 179 12.2 17.9 1139 150 45.2 218
1 13.5 3.36 16.8 135 32.6 51.6 182
1 175 5.84 24.9 807 123 55.6 126
1 113 15.8 47.3 626 53.6 168 627
1 50.5 11.6 6.3 608 58.9 58.9 139
1 78.6 14.6 9.7 421 70.8 133 464
1 90 3.27 8.17 622 52.3 770 852
1 178 28.8 32.4 992 112 70.2 169
2 213 19.1 36.2 2220 249 40 168
2 170 13.9 29.8 1285 226 47.9 330
2 162 13.2 19.8 1521 166 36.2 133
2 203 13 90.8 1544 162 98.9 394
2 167 13.1 14.1 2278 212 46.3 134
2 164 12.9 18.6 2993 197 36.3 94.5
2 167 15 27 2056 260 64.6 237
2 158 14.4 37 1025 101 44.6 72.5
2 133 22.8 31 1633 401 180 899
2 156 135 322 6747 1090 228 810
2 169 8 308 1068 99.1 53 289
2 247 17.3 8.65 2554 241 77.9 373
2 166 8.1 62.8 1233 252 134 649
2 209 6.43 86.9 2157 288 74 219
2 182 6.49 61.7 3870 432 143 367
2 235 15.6 23.4 1806 166 68.8 188
2 173 19.1 17 2497 295 65.8 287
2 151 19.7 64.2 2031 403 182 874
2 191 65.4 35 5361 392 137 688
2 223 24.4 86 3603 353 97.7 479
2 221 20.1 155 3172 368 150 739
2 217 25 28.2 2343 373 110 494
2 164 22.2 35.5 2212 281 153 549
2 173 8.99 36 1624 216 103 257
2 202 18.6 17.7 3785 225 31 67.3
2 182 17.3 24.8 3073 246 50.7 109
2 211 24 17 3836 428 73.5 351
2 246 21.5 93.2 2112 354 71.7 195
2 164 16.1 38 2135 152 64.3 240
2 179 21 35 1560 226 47.9 330
;
proc print data = d522;
run:
proc discrim data = d522 pool = no distance list;
class group;
* priors '1'=0.5 '2'=0.5;
var x1-x7;
run;
quit;
The DISCRIM Procedure
Observations 60 DF Total 59
Variables 7 DF Within Classes 58
Classes 2 DF Between Classes 1
Class Level Information
Variable Prior
group Name Frequency Weight Proportion Probability
1 _1 30 30.0000 0.500000 0.500000
2 _2 30 30.0000 0.500000 0.500000
Within Covariance Matrix Information
Natural Log of the
Covariance Determinant of the
group Matrix Rank Covariance Matrix
1 7 55.34429
2 7 59.53696
The DISCRIM Procedure
Pairwise Squared Distances Between Groups
2 _ _ -1 _ _
D (i|j) = (X - X )' COV (X - X )
i j j i j
Squared Distance to group
From group 1 2
1 0 44.56025
2 102.26139 0
Pairwise Generalized Squared Distances Between Groups
2 _ _ -1 _ _
D (i|j) = (X - X )' COV (X - X ) + ln |COV |
i j j i j j
Generalized Squared Distance to group
From group 1 2
1 55.34429 104.09721
2 157.60568 59.53696
SAS 系统 2011年08月19日 星期五 下午02时56分12秒 32
The DISCRIM Procedure
Classification Results for Calibration Data: WORK.D522
Resubstitution Results using Quadratic Discriminant Function
The DISCRIM Procedure
Classification Results for Calibration Data: WORK.D522
Resubstitution Results using Quadratic Discriminant Function
Generalized Squared Distance Function
2 _ -1 _
D (X) = (X-X )' COV (X-X ) + ln |COV |
j j j j j
Posterior Probability of Membership in Each group
2 2
Pr(j|X) = exp(-.5 D (X)) / SUM exp(-.5 D (X))
j k k
Posterior Probability of Membership in group
From Classified
Obs group into group 1 2
1 1 1 1.0000 0.0000
2 1 1 1.0000 0.0000
3 1 1 0.9786 0.0214
4 1 1 1.0000 0.0000
5 1 1 0.9972 0.0028
6 1 1 0.7502 0.2498
7 1 1 0.9776 0.0224
8 1 1 0.9999 0.0001
9 1 1 0.9822 0.0178
10 1 1 0.9918 0.0082
11 1 1 1.0000 0.0000
12 1 1 1.0000 0.0000
13 1 2 * 0.0519 0.9481
14 1 1 0.9887 0.0113
15 1 1 1.0000 0.0000
16 1 1 0.8693 0.1307
17 1 1 0.9995 0.0005
18 1 2 * 0.1625 0.8375
19 1 1 1.0000 0.0000
20 1 1 1.0000 0.0000
21 1 1 1.0000 0.0000
22 1 1 0.9990 0.0010
23 1 1 0.6796 0.3204
24 1 1 1.0000 0.0000
25 1 1 0.7177 0.2823
SAS 系统 2011年08月19日 星期五 下午02时56分12秒 33
The DISCRIM Procedure
Classification Results for Calibration Data: WORK.D522
Resubstitution Results using Quadratic Discriminant Function
Classification Results for Calibration Data: WORK.D522
Resubstitution Results using Quadratic Discriminant Function
Posterior Probability of Membership in group
From Classified
Obs group into group 1 2
26 1 1 1.0000 0.0000
27 1 1 1.0000 0.0000
28 1 1 1.0000 0.0000
29 1 1 1.0000 0.0000
30 1 1 0.8429 0.1571
31 2 2 0.0000 1.0000
32 2 2 0.0510 0.9490
33 2 2 0.0023 0.9977
34 2 2 0.0000 1.0000
35 2 2 0.0000 1.0000
36 2 2 0.0000 1.0000
37 2 2 0.0000 1.0000
38 2 2 0.4474 0.5526
39 2 2 0.0000 1.0000
40 2 2 0.0000 1.0000
41 2 2 0.0000 1.0000
42 2 2 0.0000 1.0000
43 2 2 0.0000 1.0000
44 2 2 0.0000 1.0000
45 2 2 0.0000 1.0000
46 2 2 0.0005 0.9995
47 2 2 0.0000 1.0000
48 2 2 0.0000 1.0000
49 2 2 0.0000 1.0000
50 2 2 0.0000 1.0000
51 2 2 0.0000 1.0000
52 2 2 0.0000 1.0000
53 2 2 0.0000 1.0000
54 2 2 0.0000 1.0000
55 2 2 0.0000 1.0000
56 2 2 0.0000 1.0000
57 2 2 0.0000 1.0000
58 2 2 0.0000 1.0000
59 2 2 0.0000 1.0000
60 2 2 0.0006 0.9994
* Misclassified observation
SAS 系统 2011年08月19日 星期五 下午02时56分12秒 34
The DISCRIM Procedure
Classification Summary for Calibration Data: WORK.D522
Resubstitution Summary using Quadratic Discriminant Function
Generalized Squared Distance Function
2 _ -1 _
D (X) = (X-X )' COV (X-X ) + ln |COV |
j j j j j
The DISCRIM Procedure
Classification Summary for Calibration Data: WORK.D522
Resubstitution Summary using Quadratic Discriminant Function
Generalized Squared Distance Function
2 _ -1 _
D (X) = (X-X )' COV (X-X ) + ln |COV |
j j j j j
Posterior Probability of Membership in Each group
2 2
Pr(j|X) = exp(-.5 D (X)) / SUM exp(-.5 D (X))
j k k
Number of Observations and Percent Classified into group
From group 1 2 Total
1 28 2 30
93.33 6.67 100.00
2 0 30 30
0.00 100.00 100.00
Total 28 32 60
46.67 53.33 100.00
Priors 0.5 0.5
Error Count Estimates for group
1 2 Total
Rate 0.0667 0.0000 0.0333
Priors 0.5000 0.5000
data ds1;
input group x1-x7 @@;
cards;
1 166 15.8 24.5 700 112 179 513
1 185 15.7 31.5 701 125 184 427
1 193 9.8 25.9 541 163 128 642
1 159 14.2 39.7 896 99.2 239 726
1 226 16.2 23.8 606 152 70.3 218
1 171 9.29 9.29 307 187 45.5 257
1 201 13.3 26.6 551 101 49.4 141
1 147 14.5 30 659 102 154 680
1 172 8.85 7.86 551 75.7 98.4 318
1 156 11.5 32.5 639 107 103 552
1 132 15.9 17.7 578 92.4 1314 1372
1 182 11.3 11.3 767 111 264 672
1 186 9.26 37.1 958 233 73 347
1 162 8.23 27.1 625 108 62.4 465
1 150 6.63 21 627 140 179 639
1 159 10.7 11.7 612 190 98.5 390
1 117 16.1 7.04 988 95.5 136 572
1 181 10.1 4.04 1437 184 101 542
1 146 20.7 23.8 1232 128 150 1092
1 42.3 10.3 9.7 629 93.7 439 888
1 28.2 12.4 53.1 370 44.1 454 852
1 154 13.8 53.3 621 105 160 723
1 179 12.2 17.9 1139 150 45.2 218
1 13.5 3.36 16.8 135 32.6 51.6 182
1 175 5.84 24.9 807 123 55.6 126
1 113 15.8 47.3 626 53.6 168 627
1 50.5 11.6 6.3 608 58.9 58.9 139
1 78.6 14.6 9.7 421 70.8 133 464
1 90 3.27 8.17 622 52.3 770 852
1 178 28.8 32.4 992 112 70.2 169
2 213 19.1 36.2 2220 249 40 168
2 170 13.9 29.8 1285 226 47.9 330
2 162 13.2 19.8 1521 166 36.2 133
2 203 13 90.8 1544 162 98.9 394
2 167 13.1 14.1 2278 212 46.3 134
2 164 12.9 18.6 2993 197 36.3 94.5
2 167 15 27 2056 260 64.6 237
2 158 14.4 37 1025 101 44.6 72.5
2 133 22.8 31 1633 401 180 899
2 156 135 322 6747 1090 228 810
2 169 8 308 1068 99.1 53 289
2 247 17.3 8.65 2554 241 77.9 373
2 166 8.1 62.8 1233 252 134 649
2 209 6.43 86.9 2157 288 74 219
2 182 6.49 61.7 3870 432 143 367
2 235 15.6 23.4 1806 166 68.8 188
2 173 19.1 17 2497 295 65.8 287
2 151 19.7 64.2 2031 403 182 874
2 191 65.4 35 5361 392 137 688
2 223 24.4 86 3603 353 97.7 479
2 221 20.1 155 3172 368 150 739
2 217 25 28.2 2343 373 110 494
2 164 22.2 35.5 2212 281 153 549
2 173 8.99 36 1624 216 103 257
2 202 18.6 17.7 3785 225 31 67.3
2 182 17.3 24.8 3073 246 50.7 109
2 211 24 17 3836 428 73.5 351
2 246 21.5 93.2 2112 354 71.7 195
2 164 16.1 38 2135 152 64.3 240
2 179 21 35 1560 226 47.9 330
;
data ds2;/*unknown*/
input id x1-x7@@;
cards;
1 58.2 5.42 29.7 323 138 179 513
2 106 1.87 40.5 542 177 184 427
3 152 0.8 12.5 1332 176 128 646
4 85.5 1.7 3.99 503 62.3 238 762.6
5 144 0.7 15.1 547 79.7 71 218.5
6 85.7 1.09 4.2 790 170 45.8 257.9
7 144 0.3 9.11 417 552 49.5 141.5
8 170 4.16 9.32 943 260 155 680.8
9 176 0.57 27.3 318 133 99.4 318.8
10 192 7.06 32.9 1969 343 103 553
11 188 8.28 22.6 1208 231 1314 1372
12 153 5.87 34.8 328 163 264 672.5
13 143 2.84 15.7 265 123 73 347.5
14 213 19.1 36.2 2220 249 62 465.8
15 192 20.1 23.8 1606 156 40 168
16 171 10.5 30.5 672 145 47 330.5
17 162 13.2 19.8 1521 166 36.2 133
18 203 13 90.8 1544 162 98.9 394.5
19 164 20.1 28.9 1062 161 47.3 134.5
20 167 13.1 14.1 2278 212 36.5 96.5
21 164 12.9 18.6 2993 197 65.5 237.8
22 167 15 27 2056 260 44.8 72
23 158 14.4 37 1025 101 180 899.5
24 133 22.8 31.3 1633 401 228 289
25 169 8 30.8 1068 99.1 53 817
26 247 17.3 8.65 2554 241 77.5 373.5
27 185 3.9 31.3 1211 190 134 649.8
28 209 6.43 86.9 2157 288 74 219.8
29 182 6.49 61.7 3870 432 143 367.5
30 235 15.6 23.4 1806 166 68.9 188
;
proc print data=ds1;var x1-x7;by group;
proc means data=ds1;var x1-x7;class group;
proc glm data=ds1;
class group;
model x1-x7=roup;
manova h= group/printe printh;
proc discrim data = ds1 pool=yes distance manova testdata=ds1 testlist;
class group;
priors proportional;
var x1-x7;
run;
proc discrim data=ss1 testdata=ds2 testlist;
class group car x1-x7;
run;