| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/cor_bakers_gamma.R |
| 3 |
\name{cor_bakers_gamma} |
| 4 |
\alias{cor_bakers_gamma} |
| 5 |
\alias{cor_bakers_gamma.dendrogram} |
| 6 |
\alias{cor_bakers_gamma.hclust} |
| 7 |
\alias{cor_bakers_gamma.dendlist} |
| 8 |
\alias{cor_bakers_gamma.default} |
| 9 |
\title{Baker's Gamma correlation coefficient} |
| 10 |
\usage{ |
| 11 |
cor_bakers_gamma(dend1, ...) |
| 12 |
|
| 13 |
\method{cor_bakers_gamma}{default}(dend1, dend2, ...) |
| 14 |
|
| 15 |
\method{cor_bakers_gamma}{dendrogram}( |
| 16 |
dend1, |
| 17 |
dend2, |
| 18 |
use_labels_not_values = TRUE, |
| 19 |
to_plot = FALSE, |
| 20 |
warn = dendextend_options("warn"), |
| 21 |
... |
| 22 |
) |
| 23 |
|
| 24 |
\method{cor_bakers_gamma}{hclust}( |
| 25 |
dend1, |
| 26 |
dend2, |
| 27 |
use_labels_not_values = TRUE, |
| 28 |
to_plot = FALSE, |
| 29 |
warn = dendextend_options("warn"), |
| 30 |
... |
| 31 |
) |
| 32 |
|
| 33 |
\method{cor_bakers_gamma}{dendlist}(dend1, which = c(1L, 2L), ...) |
| 34 |
} |
| 35 |
\arguments{ |
| 36 |
\item{dend1}{a tree (dendrogram/hclust/phylo)} |
| 37 |
|
| 38 |
\item{...}{Passed to \link[dendextend]{cutree}.} |
| 39 |
|
| 40 |
\item{dend2}{a tree (dendrogram/hclust/phylo)} |
| 41 |
|
| 42 |
\item{use_labels_not_values}{logical (TRUE). Should labels be used in the |
| 43 |
k matrix when using cutree? Set to FALSE will make the function a bit faster |
| 44 |
BUT, it assumes the two trees have the exact same leaves order values for |
| 45 |
each labels. This can be assured by using \link{match_order_by_labels}.} |
| 46 |
|
| 47 |
\item{to_plot}{logical (FALSE). Passed to \link{bakers_gamma_for_2_k_matrix}} |
| 48 |
|
| 49 |
\item{warn}{logical (default from dendextend_options("warn") is FALSE). |
| 50 |
Set if warning are to be issued, it is safer to keep this at TRUE, |
| 51 |
but for keeping the noise down, the default is FALSE. |
| 52 |
should a warning be issued when using \link[dendextend]{cutree}?} |
| 53 |
|
| 54 |
\item{which}{an integer vector of length 2, indicating |
| 55 |
which of the trees in the dendlist object should be plotted (relevant for dendlist)} |
| 56 |
} |
| 57 |
\value{ |
| 58 |
Baker's Gamma association Index between two trees (a number between -1 to 1) |
| 59 |
} |
| 60 |
\description{ |
| 61 |
Calculate Baker's Gamma correlation coefficient for two trees |
| 62 |
(also known as Goodman-Kruskal-gamma index). |
| 63 |
|
| 64 |
Assumes the labels in the two trees fully match. If they do not |
| 65 |
please first use \link{intersect_trees} to have them matched. |
| 66 |
|
| 67 |
WARNING: this can be quite slow for medium/large trees. |
| 68 |
} |
| 69 |
\details{ |
| 70 |
Baker's Gamma (see reference) is a measure of accosiation (similarity) |
| 71 |
between two trees of heirarchical clustering (dendrograms). |
| 72 |
|
| 73 |
It is calculated by taking two items, and see what is the heighst |
| 74 |
possible level of k (number of cluster groups created when cutting the tree) |
| 75 |
for which the two item still belongs to the same tree. That k is returned, |
| 76 |
and the same is done for these two items for the second tree. |
| 77 |
There are n over 2 combinations of such pairs of items from the items in |
| 78 |
the tree, and all of these numbers are calculated for each of the two trees. |
| 79 |
Then, these two sets of numbers (a set for the items in each tree) |
| 80 |
are paired according to the pairs of items compared, and a spearman |
| 81 |
correlation is calculated. |
| 82 |
|
| 83 |
The value can range between -1 to 1. With near 0 values meaning that |
| 84 |
the two trees are not statistically similar. |
| 85 |
For exact p-value one should result to a permutation test. One such option |
| 86 |
will be to permute over the labels of one tree many times, and calculating |
| 87 |
the distriubtion under the null hypothesis (keeping the trees topologies |
| 88 |
constant). |
| 89 |
|
| 90 |
Notice that this measure is not affected by the height of a branch but only |
| 91 |
of its relative position compared with other branches. |
| 92 |
} |
| 93 |
\examples{ |
| 94 |
|
| 95 |
\dontrun{ |
| 96 |
|
| 97 |
set.seed(23235) |
| 98 |
ss <- sample(1:150, 10) |
| 99 |
hc1 <- hclust(dist(iris[ss, -5]), "com") |
| 100 |
hc2 <- hclust(dist(iris[ss, -5]), "single") |
| 101 |
dend1 <- as.dendrogram(hc1) |
| 102 |
dend2 <- as.dendrogram(hc2) |
| 103 |
# cutree(dend1) |
| 104 |
|
| 105 |
cor_bakers_gamma(hc1, hc2) |
| 106 |
cor_bakers_gamma(dend1, dend2) |
| 107 |
|
| 108 |
dend1 <- match_order_by_labels(dend1, dend2) # if you are not sure |
| 109 |
cor_bakers_gamma(dend1, dend2, use_labels_not_values = FALSE) |
| 110 |
|
| 111 |
library(microbenchmark) |
| 112 |
microbenchmark( |
| 113 |
with_labels = cor_bakers_gamma(dend1, dend2, try_cutree_hclust = FALSE), |
| 114 |
with_values = cor_bakers_gamma(dend1, dend2, |
| 115 |
use_labels_not_values = FALSE, try_cutree_hclust = FALSE |
| 116 |
), |
| 117 |
times = 10 |
| 118 |
) |
| 119 |
|
| 120 |
|
| 121 |
cor_bakers_gamma(dend1, dend1, use_labels_not_values = FALSE) |
| 122 |
cor_bakers_gamma(dend1, dend1, use_labels_not_values = TRUE) |
| 123 |
} |
| 124 |
|
| 125 |
} |
| 126 |
\references{ |
| 127 |
Baker, F. B., Stability of Two Hierarchical Grouping Techniques Case |
| 128 |
1: Sensitivity to Data Errors. Journal of the American Statistical |
| 129 |
Association, 69(346), 440 (1974). |
| 130 |
} |
| 131 |
\seealso{ |
| 132 |
\link{cor_cophenetic} |
| 133 |
} |