| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/bk_method.R |
| 3 |
\name{FM_index_permutation} |
| 4 |
\alias{FM_index_permutation} |
| 5 |
\title{Calculating Fowlkes-Mallows Index under H0} |
| 6 |
\usage{ |
| 7 |
FM_index_permutation( |
| 8 |
A1_clusters, |
| 9 |
A2_clusters, |
| 10 |
warn = dendextend_options("warn"), |
| 11 |
... |
| 12 |
) |
| 13 |
} |
| 14 |
\arguments{ |
| 15 |
\item{A1_clusters}{a numeric vector of cluster grouping (numeric) of items, |
| 16 |
with a name attribute of item name for each element from group A1. |
| 17 |
These are often obtained by using some k cut on a dendrogram.} |
| 18 |
|
| 19 |
\item{A2_clusters}{a numeric vector of cluster grouping (numeric) of items, |
| 20 |
with a name attribute of item name for each element from group A2. |
| 21 |
These are often obtained by using some k cut on a dendrogram.} |
| 22 |
|
| 23 |
\item{warn}{logical (default from dendextend_options("warn") is FALSE). |
| 24 |
Set if warning are to be issued, it is safer to keep this at TRUE, |
| 25 |
but for keeping the noise down, the default is FALSE.} |
| 26 |
|
| 27 |
\item{...}{Ignored} |
| 28 |
} |
| 29 |
\value{ |
| 30 |
The Fowlkes-Mallows index between two vectors of clustering groups. |
| 31 |
Under H0. (a double without attr) |
| 32 |
} |
| 33 |
\description{ |
| 34 |
Calculating Fowlkes-Mallows index under the null hypothesis of no relation |
| 35 |
between the clusterings (random order of the items labels). |
| 36 |
} |
| 37 |
\examples{ |
| 38 |
|
| 39 |
\dontrun{ |
| 40 |
|
| 41 |
set.seed(23235) |
| 42 |
ss <- TRUE # sample(1:150, 10 ) |
| 43 |
hc1 <- hclust(dist(iris[ss, -5]), "com") |
| 44 |
hc2 <- hclust(dist(iris[ss, -5]), "single") |
| 45 |
# dend1 <- as.dendrogram(hc1) |
| 46 |
# dend2 <- as.dendrogram(hc2) |
| 47 |
# cutree(dend1) |
| 48 |
|
| 49 |
# small k |
| 50 |
A1_clusters <- cutree(hc1, k = 3) # will give a right tailed distribution |
| 51 |
# large k |
| 52 |
A1_clusters <- cutree(hc1, k = 50) # will give a discrete distribution |
| 53 |
# "medium" k |
| 54 |
A1_clusters <- cutree(hc1, k = 25) # gives almost the normal distribution! |
| 55 |
A2_clusters <- A1_clusters |
| 56 |
|
| 57 |
R <- 10000 |
| 58 |
set.seed(414130) |
| 59 |
FM_index_H0 <- replicate(R, FM_index_permutation(A1_clusters, A2_clusters)) # can take 10 sec |
| 60 |
plot(density(FM_index_H0), main = "FM Index distribution under H0\n (10000 permutation)") |
| 61 |
abline(v = mean(FM_index_H0), col = 1, lty = 2) |
| 62 |
|
| 63 |
|
| 64 |
# The permutation distribution is with a heavy right tail: |
| 65 |
# Source of the skew functions is based on: library(psych) |
| 66 |
|
| 67 |
skew <- function (x, na.rm = TRUE) { |
| 68 |
x <- na.omit(x) |
| 69 |
sum((x - mean(x))^3)/(length(x) * sd(x)^3) |
| 70 |
} |
| 71 |
skew(FM_index_H0) # 1.254 |
| 72 |
|
| 73 |
|
| 74 |
mean(FM_index_H0) |
| 75 |
var(FM_index_H0) |
| 76 |
the_FM_index <- FM_index(A1_clusters, A2_clusters) |
| 77 |
the_FM_index |
| 78 |
our_dnorm <- function(x) { |
| 79 |
dnorm(x, |
| 80 |
mean = attr(the_FM_index, "E_FM"), |
| 81 |
sd = sqrt(attr(the_FM_index, "V_FM")) |
| 82 |
) |
| 83 |
} |
| 84 |
# our_dnorm(0.35) |
| 85 |
curve(our_dnorm, |
| 86 |
col = 4, |
| 87 |
from = -1, to = 1, n = R, add = TRUE |
| 88 |
) |
| 89 |
abline(v = attr(the_FM_index, "E_FM"), col = 4, lty = 2) |
| 90 |
|
| 91 |
legend("topright", legend = c("asymptotic", "permutation"), fill = c(4, 1)) |
| 92 |
} |
| 93 |
} |
| 94 |
\references{ |
| 95 |
Fowlkes, E. B.; Mallows, C. L. (1 September 1983). |
| 96 |
"A Method for Comparing Two Hierarchical Clusterings". |
| 97 |
Journal of the American Statistical Association 78 (383): 553. |
| 98 |
|
| 99 |
\url{https://en.wikipedia.org/wiki/Fowlkes-Mallows_index} |
| 100 |
} |
| 101 |
\seealso{ |
| 102 |
\link{cor_bakers_gamma}, |
| 103 |
\code{\link{FM_index_R}}, \code{\link{FM_index}} |
| 104 |
} |