dendextendRcpp_heights_per_k.dendrogram: Which height will result in which k for a dendrogram

Description Usage Arguments Value Examples

Description

This is the Rcpp version of the heights_per_k.dendrogram from the dendextend R package. It is intended to override that function in order to get a speed gain of ranging from 10 times faster (for a tree with 3 leaves), to 130 times (!) faster (for a tree with 150 leaves).

Usage

1

Arguments

tree

a dendrogram.

...

not used.

Value

a vector of heights, with its names being the k clusters that will result for cutting the dendrogram at each height.

Examples

 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
## Not run: 

dend = as.dendrogram(hclust(dist(iris[1:150,-5])))

# plutral heightS
dendextendRcpp_heights_per_k.dendrogram(dend,1)
dendextendRcpp_heights_per_k.dendrogram(dend,.5)
dendextendRcpp_heights_per_k.dendrogram(dend,0.05)
dendextendRcpp_heights_per_k.dendrogram(dend,0)
dendextendRcpp_heights_per_k.dendrogram(dend,-1)

dendextendRcpp_heights_per_k.dendrogram(dend,c(1,.5,.2,0,-1))

\dontrun{
require(microbenchmark)
dend = as.dendrogram(hclust(dist(iris[1:150,-5])))
dend = as.dendrogram(hclust(dist(iris[1:30,-5])))
dend = as.dendrogram(hclust(dist(iris[1:3,-5])))
microbenchmark(
   #    dendextendRcpp::heights_per_k.dendrogram(dend),
   dendextendRcpp::dendextendRcpp_heights_per_k.dendrogram(dend),
   dendextend::old_heights_per_k.dendrogram(dend)
)
# improvment is 10 times faster (in Rcpp) for a tree of size 3
# 76 times faster for a tree of size 30
# And:
# 134 times faster for a tree of size 150!!
}

## End(Not run)

dendextendRcpp documentation built on Jan. 15, 2017, 6:37 p.m.