Debian Codegraph @

man/Bk_plot.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/bk_method.R
3 \name{Bk_plot}
4 \alias{Bk_plot}
5 \title{Bk plot - ploting the Fowlkes-Mallows Index of two dendrogram for various k's}
6 \usage{
7 Bk_plot(
8 tree1,
9 tree2,
10 k,
11 add_E = TRUE,
12 rejection_line_asymptotic = TRUE,
13 rejection_line_permutation = FALSE,
14 R = 1000,
15 k_permutation,
16 conf.level = 0.95,
17 p.adjust.methods = c("none", "bonferroni"),
18 col_line_Bk = 1,
19 col_line_asymptotic = 2,
20 col_line_permutation = 4,
21 warn = dendextend_options("warn"),
22 main = "Bk plot",
23 xlab = "k (number of clusters)",
24 ylab = "Bk (Fowlkes-Mallows Index)",
25 xlim,
26 ylim = c(0, 1),
27 try_cutree_hclust = TRUE,
28 ...
29 )
30 }
31 \arguments{
32 \item{tree1}{a dendrogram/hclust/phylo object.}
33
34 \item{tree2}{a dendrogram/hclust/phylo object.}
35
36 \item{k}{an integer scalar or vector with the desired number
37 of cluster groups.
38 If missing - the Bk will be calculated for a default k range of
39 2:(nleaves-1).
40 No point in checking k=1/k=n, since both will give Bk=1.}
41
42 \item{add_E}{logical (TRUE). Should we add a line of the Expected Bk value
43 for each k, under the null hypothesis of no relation between the clusterings?}
44
45 \item{rejection_line_asymptotic}{logical (TRUE). Should we add a line of
46 the one sided rejection region based on the asymptotic distribution
47 of Bk values, for each k, under the null hypothesis of no relation
48 between the clusterings?}
49
50 \item{rejection_line_permutation}{logical (FALSE). Should we add a line of
51 the one sided rejection region based on the asymptotic distribution
52 of Bk values, for each k, under the null hypothesis of no relation
53 between the clusterings?}
54
55 \item{R}{integer (Default is 1000). The number of Bk permutation to perform
56 for each k. Applicable only if rejection_line_permutation is TRUE.}
57
58 \item{k_permutation}{the k's to be used for permutation (sometimes we might
59 be only interested in some k's and it is not important to run the simulation
60 for all possible ks). If missing - k itself will be used.}
61
62 \item{conf.level}{the level of one sided confidence interval used for creation
63 of the rejection lines.}
64
65 \item{p.adjust.methods}{a character scalar of either "none" (default), or
66 "bonferroni". This controls the multiple correction method to use for the
67 critical rejection values. Currently only the Bonferroni method
68 is implemented (based on the number of different k values).}
69
70 \item{col_line_Bk}{the color of the Bk line.}
71
72 \item{col_line_asymptotic}{the color of the rejection asymptotic Bk line.}
73
74 \item{col_line_permutation}{the color of the rejection asymptotic Bk line.}
75
76 \item{warn}{logical (default from dendextend_options("warn") is FALSE).
77 Set if warning are to be issued, it is safer to keep this at TRUE,
78 but for keeping the noise down, the default is FALSE.
79 If set to TRUE, extra checks are made to varify that the two clusters have
80 the same size and the same labels.}
81
82 \item{main}{passed to \link{plot}.}
83
84 \item{xlab}{passed to \link{plot}.}
85
86 \item{ylab}{passed to \link{plot}.}
87
88 \item{xlim}{passed to \link{plot}. If missign, xlim is from 2 to nleaves-1}
89
90 \item{ylim}{passed to \link{plot}.}
91
92 \item{try_cutree_hclust}{logical (TRUE). Since cutree for hclust is MUCH
93 faster than for dendrogram - Bk_plot will first try to change the dendrogram
94 into an hclust object. If it will fail (for example, with unbranched trees),
95 it will continue using the cutree.dendrogram functions.
96 If try_cutree_hclust=FALSE, it will force to use cutree.dendrogram and
97 not cutree.hclust.}
98
99 \item{...}{Ignored.}
100 }
101 \value{
102 After plotting the Bk plot.
103 Returns (invisible) the output of the elements used for constructing the plot:
104 The Bk values, Bk permutations (if used), Bk theoratical values, etc.
105 }
106 \description{
107 Bk is the calculation of Fowlkes-Mallows index for a series of k cuts
108 for two dendrograms.
109 A Bk plot is simply a scatter plot of Bk versus k.
110 This plot helps in identifiying the similarity between two dendrograms in
111 different levels of k (number of clusters).
112 }
113 \details{
114 From Wikipedia:
115
116 Fowlkes-Mallows index (see references) is an external evaluation method
117 that is used to determine the similarity between two clusterings
118 (clusters obtained after a clustering algorithm). This measure of similarity
119 could be either between two hierarchical clusterings or a clustering and
120 a benchmark classification. A higher the value for the Fowlkes-Mallows index
121 indicates a greater similarity between the clusters and the benchmark
122 classifications.
123
124 The default Bk plot comes with a line with dots (type "b") of the Bk values.
125 Also with a fragmented (lty=2) line (of the same color) of the expected Bk
126 line under H0,
127 And a solid red line of the upper critical Bk values for rejection
128 }
129 \examples{
130
131 \dontrun{
132
133 set.seed(23235)
134 ss <- TRUE # sample(1:150, 10 )
135 hc1 <- hclust(dist(iris[ss, -5]), "com")
136 hc2 <- hclust(dist(iris[ss, -5]), "single")
137 # tree1 <- as.treerogram(hc1)
138 # tree2 <- as.treerogram(hc2)
139 # cutree(tree1)
140
141 Bk_plot(hc1, hc2, k = 2:20, xlim = c(2, 149))
142 Bk_plot(hc1, hc2)
143
144 Bk_plot(hc1, hc2, k = 3)
145 Bk_plot(hc1, hc2, k = 3:10)
146 Bk_plot(hc1, hc2)
147 Bk_plot(hc1, hc2, p.adjust.methods = "bonferroni") # higher rejection lines
148
149 # this one can take a bit of time:
150 Bk_plot(hc1, hc2,
151 rejection_line_permutation = TRUE,
152 k_permutation = c(2, 4, 6, 8, 10, 20, 30, 40, 50), R = 100
153 )
154 # we can see that the permutation line is VERY close to the asymptotic line.
155 # This is great since it means one can often use the asymptotic results
156 # Without having to do many simulations.
157
158 # works just as well for dendrograms:
159 dend1 <- as.dendrogram(hc1)
160 dend2 <- as.dendrogram(hc2)
161 Bk_plot(dend1, dend2, k = 2:3, try_cutree_hclust = FALSE) # slower than hclust, but works...
162 Bk_plot(hc1, dend2, k = 2:3, try_cutree_hclust = FALSE) # slower than hclust, but works...
163 Bk_plot(dend1, dend1, k = 2:3, try_cutree_hclust = TRUE) # slower than hclust, but works...
164 Bk_plot(hc1, hc1, k = 2:3) # slower than hclust, but works...
165 # for some reason it can't turn dend2 back to hclust :(
166 a <- Bk_plot(hc1, hc2, k = 2:3, try_cutree_hclust = TRUE) # slower than hclust, but works...
167
168 hc1_mixed <- as.hclust(sample(as.dendrogram(hc1)))
169 Bk_plot(
170 tree1 = hc1, tree2 = hc1_mixed,
171 add_E = FALSE,
172 rejection_line_permutation = TRUE, k_permutation = c(2, 4, 6, 8, 10, 20, 30, 40, 50), R = 100
173 )
174 }
175 }
176 \references{
177 Fowlkes, E. B.; Mallows, C. L. (1 September 1983).
178 "A Method for Comparing Two Hierarchical Clusterings".
179 Journal of the American Statistical Association 78 (383): 553.
180
181 \url{https://en.wikipedia.org/wiki/Fowlkes-Mallows_index}
182 }
183 \seealso{
184 \code{\link{FM_index}}, \link{Bk}, \link{Bk_permutations}
185 }