The TREE Procedure

Example 126.1 Mammals’ Teeth

(View the complete code for this example.)

The following statements produce a data set that contains the numbers of different kinds of teeth for a variety of mammals:

data teeth;
   title 'Mammals'' Teeth';
   input mammal & $16. v1-v8 @@;
   label v1='Right Top Incisors'
         v2='Right Bottom Incisors'
         v3='Right Top Canines'
         v4='Right Bottom Canines'
         v5='Right Top Premolars'
         v6='Right Bottom Premolars'
         v7='Right Top Molars'
         v8='Right Bottom Molars';
   datalines;
Brown Bat         2 3 1 1 3 3 3 3   Mole              3 2 1 0 3 3 3 3
Silver Hair Bat   2 3 1 1 2 3 3 3   Pigmy Bat         2 3 1 1 2 2 3 3
House Bat         2 3 1 1 1 2 3 3   Red Bat           1 3 1 1 2 2 3 3
Pika              2 1 0 0 2 2 3 3   Rabbit            2 1 0 0 3 2 3 3
Beaver            1 1 0 0 2 1 3 3   Groundhog         1 1 0 0 2 1 3 3
Gray Squirrel     1 1 0 0 1 1 3 3   House Mouse       1 1 0 0 0 0 3 3
Porcupine         1 1 0 0 1 1 3 3   Wolf              3 3 1 1 4 4 2 3
Bear              3 3 1 1 4 4 2 3   Raccoon           3 3 1 1 4 4 3 2
Marten            3 3 1 1 4 4 1 2   Weasel            3 3 1 1 3 3 1 2
Wolverine         3 3 1 1 4 4 1 2   Badger            3 3 1 1 3 3 1 2
River Otter       3 3 1 1 4 3 1 2   Sea Otter         3 2 1 1 3 3 1 2
Jaguar            3 3 1 1 3 2 1 1   Cougar            3 3 1 1 3 2 1 1
Fur Seal          3 2 1 1 4 4 1 1   Sea Lion          3 2 1 1 4 4 1 1
Grey Seal         3 2 1 1 3 3 2 2   Elephant Seal     2 1 1 1 4 4 1 1
Reindeer          0 4 1 0 3 3 3 3   Elk               0 4 1 0 3 3 3 3
Deer              0 4 0 0 3 3 3 3   Moose             0 4 0 0 3 3 3 3
;

The following statements use the CLUSTER procedure to cluster the mammals by average linkage and use ODS Graphics and the TREE procedure to produce a horizontal tree diagram that uses the average-linkage distance as its height axis:

ods graphics on;

proc cluster method=average std pseudo noeigen outtree=tree;
   id mammal;
   var v1-v8;
run;
proc tree horizontal;
   label _name_ = 'Animal';
run;

Output 126.1.1 displays the information about how the clusters are joined. For example, the cluster history shows that the mammals 'Wolf' and 'Bear' form cluster 29, which is merged with 'Raccoon' to form cluster 11.

Output 126.1.1: Output from PROC CLUSTER

Mammals' Teeth

The CLUSTER Procedure
Average Linkage Cluster Analysis


The data have been standardized to mean 0 and variance 1

Root-Mean-Square Total-Sample Standard Deviation1

Root-Mean-Square Distance Between Observations4

Cluster History
Number
of
Clusters
Clusters JoinedFreqPseudo F
Statistic
Pseudo
t-Squared
Norm RMS
Distance
Tie
31BeaverGroundhog2..0T
30Gray SquirrelPorcupine2..0T
29WolfBear2..0T
28MartenWolverine2..0T
27WeaselBadger2..0T
26JaguarCougar2..0T
25Fur SealSea Lion2..0T
24ReindeerElk2..0T
23DeerMoose2..0 
22Pigmy BatRed Bat2281.0.2289 
21CL28River Otter3139.0.2292 
20CL31CL30483.2.0.2357T
19Brown BatSilver Hair Bat276.7.0.2357T
18PikaRabbit273.2.0.2357 
17CL27Sea Otter367.4.0.2462 
16CL22House Bat362.91.70.2859 
15CL21CL17647.46.80.3328 
14CL25Elephant Seal345.0.0.3362 
13CL19CL16540.83.50.3672 
12CL15Grey Seal738.92.80.4078 
11CL29Raccoon338.0.0.423 
10CL18CL20634.510.30.4339 
9CL12CL26930.07.30.5071 
8CL24CL23428.7.0.5473 
7CL9CL141225.77.00.5668 
6CL10House Mouse728.34.10.5792 
5CL11CL71526.86.90.6621 
4CL13Mole631.97.20.7156 
3CL4CL81031.012.70.8799 
2CL3CL61727.816.11.0316 
1CL2CL532.27.81.1938 


Output 126.1.2 shows the tree diagram produced by PROC CLUSTER.

Output 126.1.2: Dendrogram from PROC CLUSTER

Dendrogram from PROC CLUSTER


Output 126.1.3 shows the corresponding tree diagram produced by PROC TREE.

Output 126.1.3: Tree Diagram of Mammal Teeth Clusters

Tree Diagram of Mammal Teeth Clusters


As you view the diagram in Output 126.1.3 from left to right, objects and clusters are progressively joined until a single, all-encompassing cluster is formed at the right (or root) of the tree. Clusters exist at each level of the diagram, and every vertical line connects leaves and branches into progressively larger clusters. For example, the five bats form a cluster at the 0.6 level, while the next cluster consists only of the mole. The mammals 'Reindeer', 'Elk', 'Deer', and 'Moose' form the next cluster at the 0.6 level, the mammals 'Pika' through 'House Mouse' are in the fourth cluster, the mammals 'Wolf', 'Bear', and 'Raccoon' form the fifth cluster, and the last cluster contains the mammals 'Marten' through 'Elephant Seal'.

The following statements create the same tree with line printer graphics in a vertical orientation:

options ps=40;
proc tree lineprinter;
run;

The line printer plot is not displayed.

The next statements sort the clusters at each branch in order of formation and use the number of clusters as the height axis:

proc tree sort height=n horizontal;
   label _name_ = 'Animal';
run;

The resulting tree is displayed in Output 126.1.4.

Output 126.1.4: PROC TREE with SORT and HEIGHT= Options

PROC TREE with SORT and HEIGHT= Options


Because the CLUSTER procedure always produces binary trees, the number of internal (root and branch) nodes in the tree is one less than the number of leaves. Therefore 31 clusters are formed from the 32 mammals in the input data set. These are represented by the 31 vertical line segments in the tree diagram, each at a different value along the horizontal axis.

As you examine the tree from left to right, the first vertical line segment is where 'Beaver' and 'Groundhog' are clustered and the number of clusters is 31. The next cluster is formed from 'Gray Squirrel' and 'Porcupine'. The third contains 'Wolf' and 'Bear'. Note how the tree graphically displays the clustering order information that was presented in tabular form by the CLUSTER procedure in Output 126.1.1.

The same clusters as in Output 126.1.3 can be seen at the six-cluster level of the tree diagram in Output 126.1.4, although the SORT and HEIGHT= options make them appear in a different order.

The following statements create these six clusters and save the result in the output data set part:

proc tree noprint out=part nclusters=6;
   id mammal;
   copy v1-v8;
run;

proc sort;
   by cluster;
run;

PROC TREE with the NOPRINT option displays no output but creates an output data set that indicates the cluster to which each observation belongs at the six-cluster level in the tree. The following statements print the data set part, with the results shown in Output 126.1.5:

proc print label uniform;
   id mammal;
   var v1-v8;
   format v1-v8 1.;
   by cluster;
run;

Output 126.1.5: PROC TREE OUT= Data Set

Mammals' Teeth

mammalRight
Top Incisors
Right
Bottom
Incisors
Right
Top Canines
Right
Bottom
Canines
Right
Top Premolars
Right
Bottom
Premolars
Right
Top Molars
Right
Bottom
Molars
Beaver11002133
Groundhog11002133
Gray Squirrel11001133
Porcupine11001133
Pika21002233
Rabbit21003233
House Mouse11000033

mammalRight
Top Incisors
Right
Bottom
Incisors
Right
Top Canines
Right
Bottom
Canines
Right
Top Premolars
Right
Bottom
Premolars
Right
Top Molars
Right
Bottom
Molars
Wolf33114423
Bear33114423
Raccoon33114432

mammalRight
Top Incisors
Right
Bottom
Incisors
Right
Top Canines
Right
Bottom
Canines
Right
Top Premolars
Right
Bottom
Premolars
Right
Top Molars
Right
Bottom
Molars
Marten33114412
Wolverine33114412
Weasel33113312
Badger33113312
Jaguar33113211
Cougar33113211
Fur Seal32114411
Sea Lion32114411
River Otter33114312
Sea Otter32113312
Elephant Seal21114411
Grey Seal32113322

mammalRight
Top Incisors
Right
Bottom
Incisors
Right
Top Canines
Right
Bottom
Canines
Right
Top Premolars
Right
Bottom
Premolars
Right
Top Molars
Right
Bottom
Molars
Reindeer04103333
Elk04103333
Deer04003333
Moose04003333

mammalRight
Top Incisors
Right
Bottom
Incisors
Right
Top Canines
Right
Bottom
Canines
Right
Top Premolars
Right
Bottom
Premolars
Right
Top Molars
Right
Bottom
Molars
Pigmy Bat23112233
Red Bat13112233
Brown Bat23113333
Silver Hair Bat23112333
House Bat23111233

mammalRight
Top Incisors
Right
Bottom
Incisors
Right
Top Canines
Right
Bottom
Canines
Right
Top Premolars
Right
Bottom
Premolars
Right
Top Molars
Right
Bottom
Molars
Mole32103333


Last updated: October 28, 2020