-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProc_Stepdisc_Candisc_Cluster_sas_codes.c
93 lines (79 loc) · 2.8 KB
/
Proc_Stepdisc_Candisc_Cluster_sas_codes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
proc format;
value location_name
1='Adogba'
2='Ajiboda'
3='Apete'
4='Egbeda'
5='Moleta'
6='Oje'
7='Sasa';
run;
data duck_data;
title 'Duck Biometric Data';
input Sex $ Location Shank_colour $ Bill_colour $ Bean_colour $ Crest $ Eye_colour $ Head_Length Neck_Length Body_Length Wing_Length Shank_Length Toe_Length Thigh_Length Bill_Length Breast_Length Breast_width Weight @@;
format Location location_name;
datalines;
/*data available on request*/
;
/*Stepwise Discriminant Analysis*/
title 'Duck Characterisation Data';
proc stepdisc data=duck_data;
class Location;
run;
/*PROC STEPDISC determined that Neck_Length, Wing_Length, Weight, Toe_Length, and Head_Length were the most discriminating variables*/
/*Canonical Discriminant Analysis*/
title 'Duck Characterisation Data';
proc candisc data=duck_data ncan=3 out=outcanduck;
ods exclude tstruc bstruc pstruc tcoef pcoef;
class Location;
var Neck_Length Wing_Length Weight Toe_Length Head_Length;
run;
/*discriminant analysis*/
proc discrim data=duck_data ncan=3 out=outcanduck ANOVA DISTANCE CROSSVALIDATE LIST CROSSLIST CANONICAL;
class Location;
var Neck_Length Wing_Length Weight Toe_Length Head_Length;
run;
/*canonical discriminant function illustrating the distribution of ducks among the different locations in ibadan*/
proc template;
define statgraph scatter;
begingraph / attrpriority=none;
entrytitle 'Distribution of Ducks Among Different Geographical Locations';
layout overlayequated / equatetype=fit
xaxisopts=(label='Canonical Variable 1')
yaxisopts=(label='Canonical Variable 2');
scatterplot x=Can1 y=Can2 / group=location name='ducks'
markerattrs=(size=6px);
layout gridded / autoalign=(topright);
discretelegend 'ducks' / border=false opaque=false;
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data=outcanduck template=scatter;
run;
/*Cluster procedure*/
/*Macro show is used to get the cluster results*/
/*--- First, define macro show ---*/
%macro show;
proc freq;
tables cluster*Location / nopercent norow nocol plot=none;
run;
proc candisc noprint out=can;
class cluster;
var Neck_Length Wing_Length Weight Toe_Length Head_Length;
run;
proc sgplot data=can;
scatter y=can2 x=can1 / group=cluster;
run;
%mend;
title2 'By Ward''s Method';
ods graphics on;
proc cluster data=duck_data method=ward print=15 ccc pseudo;
var Neck_Length Wing_Length Weight Toe_Length Head_Length;
copy Location;
run;
proc tree noprint ncl=3 out=out;
copy Neck_Length Wing_Length Weight Toe_Length Head_Length Location;
run;
%show;