Group: | Cluster analysis |
See also: | agglom |
Function: | tree | |
Description: | generates from a binary tree an output for plotting. |
Usage: | g = tree (t, cut {, opt}) | |
Input: | ||
t | n x 2 matrix produced from agglom | |
cut | scalar the cut-off value for the tree | |
opt | text matrix of optional parameters | |
Output: | ||
g.points | m x 2 matrix for drawing trees via show | |
g.index | m x 1 matrix of indices |
The 'cut' value gives the level for the 'NaN' values. If
the cut value is larger than 1.5 only the subtree to 1.5
will drawn. The internal used comparison operator is
SMALLER. If the tree is going up the optional parameter
GREATER can be used for cutting. Try the other optional
parameters by yourself:
LEFT (default) the branches of the tree are
left centered
CENTER centered
RIGHT right centered
YAXIS (default) the branches are parallel to the
y-axis
XAXIS x-axis
SMALLER (default) the cut-value is checked with
tree-value smaller as cut
GREATER tree-value greater as cut
SQUARE (default) the tree is drawn with
open rectangles
TRIANGLE open triangles
proc()=main() ; load the swiss banknote data x=read("bank2") ; compute the euclidean distance between banknotes i=0 d=0.*matrix(rows(x),rows(x)) while(i.<cols(x)) i = i+1 d = d+(x[,i] - x[,i]')^2 endo d = sqrt(d) ; use the WARD method to cluster the data t = agglom(d, "WARD", 3) ; generate now the dendrogram for drawing g = tree(t.g, 0) g=g.points; build lines l = 5.*(1:rows(g)/5) +(0:4)' - 4 setmaskl(g, l, 0, 1, 1) setmaskp(g, 0, 0, 0) ; create a display for drawing d = createdisplay(1,1) ; show the dendrogram show(d, 1, 1, g) endp ; main()
shows as result the dendogram for all 200 swiss banknote data