Debian Codegraph @

man/cutree_1k.dendrogram.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/cutree.dendrogram.R
3 \name{cutree_1k.dendrogram}
4 \alias{cutree_1k.dendrogram}
5 \title{cutree for dendrogram (by 1 k value only!)}
6 \usage{
7 cutree_1k.dendrogram(
8 dend,
9 k,
10 dend_heights_per_k = NULL,
11 use_labels_not_values = TRUE,
12 order_clusters_as_data = TRUE,
13 warn = dendextend_options("warn"),
14 ...
15 )
16 }
17 \arguments{
18 \item{dend}{a dendrogram object}
19
20 \item{k}{numeric scalar (not a vector!) with the number of clusters
21 the tree should be cut into.}
22
23 \item{dend_heights_per_k}{a named vector that resulted from running.
24 \code{heights_per_k.dendrogram}. When running the function many times,
25 supplying this object will help improve the running time.}
26
27 \item{use_labels_not_values}{logical, defaults to TRUE. If the actual labels of the
28 clusters do not matter - and we want to gain speed (say, 10 times faster) -
29 then use FALSE (gives the "leaves order" instead of their labels.).
30 This is passed to \code{cutree_1h.dendrogram}.}
31
32 \item{order_clusters_as_data}{logical, defaults to TRUE. There are two ways by which
33 to order the clusters: 1) By the order of the original data. 2) by the order of the
34 labels in the dendrogram. In order to be consistent with \link[stats]{cutree}, this is set
35 to TRUE.
36 This is passed to \code{cutree_1h.dendrogram}.}
37
38 \item{warn}{logical (default from dendextend_options("warn") is FALSE).
39 Set if warning are to be issued, it is safer to keep this at TRUE,
40 but for keeping the noise down, the default is FALSE.
41 Should the function send a warning in case the desried k is not available?}
42
43 \item{...}{(not currently in use)}
44 }
45 \value{
46 \code{cutree_1k.dendrogram} returns an integer vector with group
47 memberships.
48
49 In case there exists no such k for which exists a relevant split of the
50 dendrogram, a warning is issued to the user, and NA is returned.
51 }
52 \description{
53 Cuts a dendrogram tree into several groups
54 by specifying the desired number of clusters k (only a single k value!).
55
56 In case there exists no such k for which exists a relevant split of the
57 dendrogram, a warning is issued to the user, and NA is returned.
58 }
59 \examples{
60 hc <- hclust(dist(USArrests[c(1, 6, 13, 20, 23), ]), "ave")
61 dend <- as.dendrogram(hc)
62 cutree(hc, k = 3) # on hclust
63 cutree_1k.dendrogram(dend, k = 3) # on a dendrogram
64
65 labels(dend)
66
67 # the default (ordered by original data's order)
68 cutree_1k.dendrogram(dend, k = 3, order_clusters_as_data = TRUE)
69
70 # A different order of labels - order by their order in the tree
71 cutree_1k.dendrogram(dend, k = 3, order_clusters_as_data = FALSE)
72
73
74 # make it faster
75 \dontrun{
76 library(microbenchmark)
77 dend_ks <- heights_per_k.dendrogram
78 microbenchmark(
79 cutree_1k.dendrogram = cutree_1k.dendrogram(dend, k = 4),
80 cutree_1k.dendrogram_no_labels = cutree_1k.dendrogram(dend,
81 k = 4, use_labels_not_values = FALSE
82 ),
83 cutree_1k.dendrogram_no_labels_per_k = cutree_1k.dendrogram(dend,
84 k = 4, use_labels_not_values = FALSE,
85 dend_heights_per_k = dend_ks
86 )
87 )
88 # the last one is the fastest...
89 }
90
91 }
92 \seealso{
93 \code{\link{hclust}}, \code{\link{cutree}},
94 \code{\link{cutree_1h.dendrogram}}
95 }
96 \author{
97 Tal Galili
98 }