Programmer Guide/Command Reference/EVAL/haclust: Difference between revisions

From STX Wiki
Jump to navigationJump to search
m (1 revision: Initial import)
No edit summary
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
=====haclust=====
Hierarchical-agglomerative cluster analysis.
Hierarchical-agglomerative cluster analysis.
----
;Usage 1:<code>haclust(<var>d</var>, <var>m</var>)</code>
:;<var>d</var>: A dissimilarity or distance matrix. For N data points this is a NxN matrix (e.g. created using the function [[../dist|dist]])
:;<var>m</var>The cluster method:
::{|class="einrahmen"
!''m'' !! method
|0 ||Single Linkage
|-
|1 ||Complete Linkage
|-
|2 ||Weighted Average Linkage
|-
|3 ||Average Linkage
|-
|4 ||Median
|-
|5 ||Centroid
|-
|6 ||Ward
|}
;Result 1: The result is a cluster hierarchy. This is a 3x(N-1) table containing the merged cluster pairs and the agglomeration niveaus.
----
;Usage 2:<code>haclust(<var>h</var>, <var>c</var>)</code>
:;<var>h</var>:A cluster hierarchy (e.g. computed with Usage 1).
:;<var>c</var>:The number of clusters.
;Result:The created partition, which is a 1xN table containing the group indices.
----
See also: [[../modclust|modclust]]


=====Usage:=====
<code>haclust(<var>d</var>, <var>m</var>)</code>
<code>haclust(<var>h</var>, <var>c</var>)</code>
=====Parameters:=====
;<var>d</var>
:A dissimilarity or distance matrix. For N data points this is a NxN matrix (e.g. created using the <code>EVAL</code> function [[Programmer Guide/Command Reference/EVAL/dist|dist]]).
;<var>m</var>
:The cluster method:
:<code>0</code> Single Linkage
:<code>1</code> Complete Linkage
:<code>2</code> Weighted Average Linkage
:<code>3</code> Average Linkage
:<code>4</code> Median
:<code>5</code> Centroid
:<code>6</code> Ward
;<var>h</var>
:A cluster hierarchy.
;<var>c</var>
:The number of clusters.
=====Result:=====
When using the parameters <var>d</var> and <var>m</var>, the result is a cluster hierarchy. This is a 3x(N-1) table containing the merged cluster pairs and the agglomeration niveaus.
The parameters <var>h</var> and <var>c</var> cause <code>haclust</code> to create a partition, which is a 1xN table containing the group indices.
=====Examples:=====
A simple demonstration of <code>haclust</code> usage.


Example:
<pre>
<pre>
// A simple demonstration of <code>haclust</code> usage.
[macro haclust_example]
[macro haclust_example]
        // create bivariate input data
// create bivariate input data
        #datatable := new table * 2 /p num:x num:y
#datatable := new table * 2 /p num:x num:y
        $#datatable[*,0] := '1;2;1;3;4.5'
$#datatable[*,0] := '1;2;1;3;4.5'
        $#datatable[*,1] := '1;0.5;4;2;4'
$#datatable[*,1] := '1;0.5;4;2;4'
          
          
        // compute distance matrix
// compute distance matrix
        #disttable := eval dist($#datatable)
#disttable := eval dist($#datatable)


        // cluster analysis methods:
// cluster analysis methods:
        // 0 (SL), 1 (CL), 2 (WAL), 3 (AL), 4 (M), 5 (C), 6 (W)
// 0 (SL), 1 (CL), 2 (WAL), 3 (AL), 4 (M), 5 (C), 6 (W)
        #method := 6    // Ward
#method := 6    // Ward


        // nr of clusters
// nr of clusters
        #nclusters := 2
#nclusters := 2


        // compute hierarchy and partition
// compute hierarchy and partition
        #hierarchy := eval haclust($#disttable,$#method)
#hierarchy := eval haclust($#disttable,$#method)
        #partition := eval haclust($#hierarchy,$#nclusters)
#partition := eval haclust($#hierarchy,$#nclusters)


        // show results
// show results
        showitem $#hierarchy
showitem $#hierarchy
        showitem $#partition
showitem $#partition
exit
exit
</pre>
</pre>

Revision as of 13:19, 18 April 2011

Hierarchical-agglomerative cluster analysis.


Usage 1
haclust(d, m)
d
A dissimilarity or distance matrix. For N data points this is a NxN matrix (e.g. created using the function dist)
mThe cluster method
m method 0 Single Linkage
1 Complete Linkage
2 Weighted Average Linkage
3 Average Linkage
4 Median
5 Centroid
6 Ward
Result 1
The result is a cluster hierarchy. This is a 3x(N-1) table containing the merged cluster pairs and the agglomeration niveaus.

Usage 2
haclust(h, c)
h
A cluster hierarchy (e.g. computed with Usage 1).
c
The number of clusters.
Result
The created partition, which is a 1xN table containing the group indices.

See also: modclust


Example:

// A simple demonstration of <code>haclust</code> usage.
[macro haclust_example]
// create bivariate input data
#datatable := new table * 2 /p num:x num:y
$#datatable[*,0] := '1;2;1;3;4.5'
$#datatable[*,1] := '1;0.5;4;2;4'
        
// compute distance matrix
#disttable := eval dist($#datatable)

// cluster analysis methods:
// 0 (SL), 1 (CL), 2 (WAL), 3 (AL), 4 (M), 5 (C), 6 (W)
#method := 6    // Ward

// nr of clusters
#nclusters := 2

// compute hierarchy and partition
#hierarchy := eval haclust($#disttable,$#method)
#partition := eval haclust($#hierarchy,$#nclusters)

// show results
showitem $#hierarchy
showitem $#partition
exit

Navigation menu

Personal tools