Debian Codegraph @

man/Bk.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/bk_method.R
3 \name{Bk}
4 \alias{Bk}
5 \title{Bk - Calculating Fowlkes-Mallows Index for two dendrogram}
6 \usage{
7 Bk(tree1, tree2, k, warn = dendextend_options("warn"), ...)
8 }
9 \arguments{
10 \item{tree1}{a dendrogram/hclust/phylo object.}
11
12 \item{tree2}{a dendrogram/hclust/phylo object.}
13
14 \item{k}{an integer scalar or vector with the desired number
15 of cluster groups.
16 If missing - the Bk will be calculated for a default k range of
17 2:(nleaves-1).
18 No point in checking k=1/k=n, since both will give Bk=1.}
19
20 \item{warn}{logical (default from dendextend_options("warn") is FALSE).
21 Set if warning are to be issued, it is safer to keep this at TRUE,
22 but for keeping the noise down, the default is FALSE.}
23
24 \item{...}{Ignored (passed to FM_index_R).}
25 }
26 \value{
27 A list (of k's length) of Fowlkes-Mallows index between two dendrogram for
28 a scalar/vector of k values.
29 The names of the lists' items is the k for which it was calculated.
30 }
31 \description{
32 Bk is the calculation of Fowlkes-Mallows index for a series of k cuts
33 for two dendrograms.
34 }
35 \details{
36 From Wikipedia:
37
38 Fowlkes-Mallows index (see references) is an external evaluation method
39 that is used to determine the similarity between two clusterings
40 (clusters obtained after a clustering algorithm). This measure of similarity
41 could be either between two hierarchical clusterings or a clustering and
42 a benchmark classification. A higher the value for the Fowlkes-Mallows index
43 indicates a greater similarity between the clusters and the benchmark
44 classifications.
45 }
46 \examples{
47
48 \dontrun{
49
50 set.seed(23235)
51 ss <- TRUE # sample(1:150, 10 )
52 hc1 <- hclust(dist(iris[ss, -5]), "com")
53 hc2 <- hclust(dist(iris[ss, -5]), "single")
54 tree1 <- as.dendrogram(hc1)
55 tree2 <- as.dendrogram(hc2)
56 # cutree(tree1)
57
58 Bk(hc1, hc2, k = 3)
59 Bk(hc1, hc2, k = 2:10)
60 Bk(hc1, hc2)
61
62 Bk(tree1, tree2, k = 3)
63 Bk(tree1, tree2, k = 2:5)
64
65 system.time(Bk(hc1, hc2, k = 2:5)) # 0.01
66 system.time(Bk(hc1, hc2)) # 1.28
67 system.time(Bk(tree1, tree2, k = 2:5)) # 0.24 # after fixes.
68 system.time(Bk(tree1, tree2, k = 2:10)) # 0.31 # after fixes.
69 system.time(Bk(tree1, tree2)) # 7.85
70 Bk(tree1, tree2, k = 99:101)
71
72 y <- Bk(hc1, hc2, k = 2:10)
73 plot(unlist(y) ~ c(2:10), type = "b", ylim = c(0, 1))
74
75 # can take a few seconds
76 y <- Bk(hc1, hc2)
77 plot(unlist(y) ~ as.numeric(names(y)),
78 main = "Bk plot", pch = 20,
79 xlab = "k", ylab = "FM Index",
80 type = "b", ylim = c(0, 1)
81 )
82 # we are still missing some hypothesis testing here.
83 # for this we'll have the Bk_plot function.
84 }
85 }
86 \references{
87 Fowlkes, E. B.; Mallows, C. L. (1 September 1983).
88 "A Method for Comparing Two Hierarchical Clusterings".
89 Journal of the American Statistical Association 78 (383): 553.
90
91 \url{https://en.wikipedia.org/wiki/Fowlkes-Mallows_index}
92 }
93 \seealso{
94 \link{FM_index}, \link{cor_bakers_gamma}, \link{Bk_plot}
95 }