| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/bk_method.R |
| 3 |
\name{FM_index_R} |
| 4 |
\alias{FM_index_R} |
| 5 |
\title{Calculating Fowlkes-Mallows index in R} |
| 6 |
\usage{ |
| 7 |
FM_index_R( |
| 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} |
| 45 |
function also calculates the expectancy and variance of the FM Index |
| 46 |
under the null hypothesis of no relation. |
| 47 |
} |
| 48 |
\details{ |
| 49 |
From Wikipedia: |
| 50 |
|
| 51 |
Fowlkes-Mallows index (see references) is an external evaluation method |
| 52 |
that is used to determine the similarity between two clusterings |
| 53 |
(clusters obtained after a clustering algorithm). This measure of similarity |
| 54 |
could be either between two hierarchical clusterings or a clustering and |
| 55 |
a benchmark classification. A higher the value for the Fowlkes-Mallows index |
| 56 |
indicates a greater similarity between the clusters and the benchmark |
| 57 |
classifications. |
| 58 |
} |
| 59 |
\examples{ |
| 60 |
|
| 61 |
\dontrun{ |
| 62 |
|
| 63 |
set.seed(23235) |
| 64 |
ss <- TRUE # sample(1:150, 10 ) |
| 65 |
hc1 <- hclust(dist(iris[ss, -5]), "com") |
| 66 |
hc2 <- hclust(dist(iris[ss, -5]), "single") |
| 67 |
# dend1 <- as.dendrogram(hc1) |
| 68 |
# dend2 <- as.dendrogram(hc2) |
| 69 |
# cutree(dend1) |
| 70 |
|
| 71 |
FM_index_R(cutree(hc1, k = 3), cutree(hc1, k = 3)) # 1 |
| 72 |
set.seed(1341) |
| 73 |
FM_index_R(cutree(hc1, k = 3), |
| 74 |
sample(cutree(hc1, k = 3)), |
| 75 |
assume_sorted_vectors = TRUE) # 0.38037 |
| 76 |
FM_index_R(cutree(hc1, k = 3), |
| 77 |
sample(cutree(hc1, k = 3)), |
| 78 |
assume_sorted_vectors = FALSE) # 1 again :) |
| 79 |
FM_index_R(cutree(hc1, k = 3), |
| 80 |
cutree(hc2, k = 3)) # 0.8059 |
| 81 |
FM_index_R(cutree(hc1, k = 30), |
| 82 |
cutree(hc2, k = 30)) # 0.4529 |
| 83 |
|
| 84 |
fo <- function(k) FM_index_R(cutree(hc1, k), cutree(hc2, k)) |
| 85 |
lapply(1:4, fo) |
| 86 |
ks <- 1:150 |
| 87 |
plot(sapply(ks, fo) ~ ks, type = "b", main = "Bk plot for the iris dataset") |
| 88 |
|
| 89 |
clu_1 <- cutree(hc2, k = 100) # this is a lie - since this one is NOT well defined! |
| 90 |
clu_2 <- cutree(as.dendrogram(hc2), k = 100) # We see that we get a vector of NAs for this... |
| 91 |
|
| 92 |
FM_index_R(clu_1, clu_2) # NA |
| 93 |
} |
| 94 |
} |
| 95 |
\references{ |
| 96 |
Fowlkes, E. B.; Mallows, C. L. (1 September 1983). |
| 97 |
"A Method for Comparing Two Hierarchical Clusterings". |
| 98 |
Journal of the American Statistical Association 78 (383): 553. |
| 99 |
|
| 100 |
\url{https://en.wikipedia.org/wiki/Fowlkes-Mallows_index} |
| 101 |
} |
| 102 |
\seealso{ |
| 103 |
\link{cor_bakers_gamma} |
| 104 |
} |