Debian Codegraph @

man/FM_index.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/bk_method.R
3 \name{FM_index}
4 \alias{FM_index}
5 \title{Calculating Fowlkes-Mallows Index}
6 \usage{
7 FM_index(
8 A1_clusters,
9 A2_clusters,
10 assume_sorted_vectors = FALSE,
11 warn = dendextend_options("warn"),
12 ...
13 )
14 }
15 \arguments{
16 \item{A1_clusters}{a numeric vector of cluster grouping (numeric) of items,
17 with a name attribute of item name for each element from group A1.
18 These are often obtained by using some k cut on a dendrogram.}
19
20 \item{A2_clusters}{a numeric vector of cluster grouping (numeric) of items,
21 with a name attribute of item name for each element from group A2.
22 These are often obtained by using some k cut on a dendrogram.}
23
24 \item{assume_sorted_vectors}{logical (FALSE). Can we assume to two group
25 vectors are sorter so that they have the same order of items?
26 IF FALSE (default), then the vectors will be sorted based on their
27 name attribute.}
28
29 \item{warn}{logical (default from dendextend_options("warn") is FALSE).
30 Set if warning are to be issued, it is safer to keep this at TRUE,
31 but for keeping the noise down, the default is FALSE.}
32
33 \item{...}{Ignored}
34 }
35 \value{
36 The Fowlkes-Mallows index between two vectors of clustering groups.
37
38 Includes the attributes E_FM and V_FM for the relevant expectancy and
39 variance under the null hypothesis of no-relation.
40 }
41 \description{
42 Calculating Fowlkes-Mallows index.
43
44 The \code{FM_index_R} function calculates the expectancy and variance of the FM Index
45 under the null hypothesis of no relation.
46 }
47 \details{
48 From Wikipedia:
49
50 Fowlkes-Mallows index (see references) is an external evaluation method
51 that is used to determine the similarity between two clusterings
52 (clusters obtained after a clustering algorithm). This measure of similarity
53 could be either between two hierarchical clusterings or a clustering and
54 a benchmark classification. A higher the value for the Fowlkes-Mallows index
55 indicates a greater similarity between the clusters and the benchmark
56 classifications.
57 }
58 \examples{
59
60 \dontrun{
61
62 set.seed(23235)
63 ss <- TRUE # sample(1:150, 10 )
64 hc1 <- hclust(dist(iris[ss, -5]), "com")
65 hc2 <- hclust(dist(iris[ss, -5]), "single")
66 # dend1 <- as.dendrogram(hc1)
67 # dend2 <- as.dendrogram(hc2)
68 # cutree(dend1)
69
70 FM_index(cutree(hc1, k = 3), cutree(hc1, k = 3)) # 1 with EV
71
72 # checking speed gains
73 library(microbenchmark)
74 microbenchmark(
75 FM_index(cutree(hc1, k = 3), cutree(hc1, k = 3)),
76 FM_index(cutree(hc1, k = 3), cutree(hc1, k = 3),
77 assume_sorted_vectors = TRUE
78 ),
79 FM_index(cutree(hc1, k = 3), cutree(hc1, k = 3),
80 assume_sorted_vectors = TRUE
81 )
82 )
83 # C code is 1.2-1.3 times faster.
84
85 set.seed(1341)
86 FM_index(cutree(hc1, k = 3), sample(cutree(hc1, k = 3)),
87 assume_sorted_vectors = TRUE
88 ) # 0.38037
89 FM_index(cutree(hc1, k = 3), sample(cutree(hc1, k = 3)),
90 assume_sorted_vectors = FALSE
91 ) # 1 again :)
92 FM_index(cutree(hc1, k = 3), cutree(hc2, k = 3)) # 0.8059
93 FM_index(cutree(hc1, k = 30), cutree(hc2, k = 30)) # 0.4529
94
95 fo <- function(k) FM_index(cutree(hc1, k), cutree(hc2, k))
96 lapply(1:4, fo)
97 ks <- 1:150
98 plot(sapply(ks, fo) ~ ks, type = "b", main = "Bk plot for the iris dataset")
99 }
100 }
101 \references{
102 Fowlkes, E. B.; Mallows, C. L. (1 September 1983).
103 "A Method for Comparing Two Hierarchical Clusterings".
104 Journal of the American Statistical Association 78 (383): 553.
105
106 \url{https://en.wikipedia.org/wiki/Fowlkes-Mallows_index}
107 }
108 \seealso{
109 \link{cor_bakers_gamma}
110 }