| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/entanglement.R |
| 3 |
\name{entanglement} |
| 4 |
\alias{entanglement} |
| 5 |
\alias{entanglement.hclust} |
| 6 |
\alias{entanglement.phylo} |
| 7 |
\alias{entanglement.dendlist} |
| 8 |
\alias{entanglement.dendrogram} |
| 9 |
\title{Measures entanglement between two trees} |
| 10 |
\usage{ |
| 11 |
entanglement(dend1, ...) |
| 12 |
|
| 13 |
\method{entanglement}{hclust}(dend1, dend2, ...) |
| 14 |
|
| 15 |
\method{entanglement}{phylo}(dend1, dend2, ...) |
| 16 |
|
| 17 |
\method{entanglement}{dendlist}(dend1, which = c(1L, 2L), ...) |
| 18 |
|
| 19 |
\method{entanglement}{dendrogram}( |
| 20 |
dend1, |
| 21 |
dend2, |
| 22 |
L = 1.5, |
| 23 |
leaves_matching_method = c("labels", "order"), |
| 24 |
... |
| 25 |
) |
| 26 |
} |
| 27 |
\arguments{ |
| 28 |
\item{dend1}{a tree object (of class dendrogram/hclust/phylo).} |
| 29 |
|
| 30 |
\item{...}{not used} |
| 31 |
|
| 32 |
\item{dend2}{a tree object (of class dendrogram/hclust/phylo).} |
| 33 |
|
| 34 |
\item{which}{an integer vector of length 2, indicating |
| 35 |
which of the trees in a dendlist object should have |
| 36 |
their entanglement calculated} |
| 37 |
|
| 38 |
\item{L}{the distance norm to use for measuring the distance between the |
| 39 |
two trees. It can be any positive number, often one will want to |
| 40 |
use 0, 1, 1.5, 2 (see 'details' for more).} |
| 41 |
|
| 42 |
\item{leaves_matching_method}{a character scalar, either "order" |
| 43 |
or "labels" (default) . If using "labels", then we use the labels for |
| 44 |
matching the leaves order value (safer). |
| 45 |
|
| 46 |
And if "order" then we use the old leaves order value for matching the |
| 47 |
leaves order value. |
| 48 |
|
| 49 |
Using "order" is faster, but "labels" is safer. "order" will assume that |
| 50 |
the original two trees had their labels and order values MATCHED. |
| 51 |
|
| 52 |
Hence, it is best to make sure that the trees used here have the same labels |
| 53 |
and the SAME values matched to these values - and then use "order" (for |
| 54 |
fastest results).} |
| 55 |
} |
| 56 |
\value{ |
| 57 |
The number of leaves in the tree |
| 58 |
} |
| 59 |
\description{ |
| 60 |
Measures the entanglement between two trees. |
| 61 |
Entanglement is a measure between 1 (full entanglement) and 0 |
| 62 |
(no entanglement). The exact behavior of the number depends on the L norm |
| 63 |
which is chosen. |
| 64 |
} |
| 65 |
\details{ |
| 66 |
Entanglement is measured by giving the left tree's labels the values of |
| 67 |
1 till tree size, and than match these numbers with the right tree. |
| 68 |
Now, entanglement is the L norm distance between these two vectors. |
| 69 |
That is, we take the sum of the absolute difference (each one in the power |
| 70 |
of L). e.g: \code{sum(abs(x-y)^L)}. |
| 71 |
And this is devided by the "worst case" entanglement level (e.g: |
| 72 |
when the right tree is the complete reverse of the left tree). |
| 73 |
|
| 74 |
L tells us which panelty level we are at (L0, L1, L2, partial L's etc). |
| 75 |
L>1 means that we give a big panelty for sharp angles. |
| 76 |
While L->0 means that any time something is not a streight horizontal line, |
| 77 |
it gets a large penalty |
| 78 |
If L=0.1 it means that we much prefer streight lines over non streight lines |
| 79 |
} |
| 80 |
\examples{ |
| 81 |
|
| 82 |
\dontrun{ |
| 83 |
dend1 <- iris[, -5] \%>\% |
| 84 |
dist() \%>\% |
| 85 |
hclust("com") \%>\% |
| 86 |
as.dendrogram() |
| 87 |
dend2 <- iris[, -5] \%>\% |
| 88 |
dist() \%>\% |
| 89 |
hclust("sin") \%>\% |
| 90 |
as.dendrogram() |
| 91 |
dend12 <- dendlist(dend1, dend2) |
| 92 |
tanglegram(dend12) |
| 93 |
|
| 94 |
entanglement(dend12) |
| 95 |
entanglement(dend12, L = 0) |
| 96 |
entanglement(dend12, L = 0.25) |
| 97 |
entanglement(dend1, dend2, L = 0) # 1 |
| 98 |
entanglement(dend1, dend2, L = 0.25) # 0.97 |
| 99 |
entanglement(dend1, dend2, L = 1) # 0.93 |
| 100 |
entanglement(dend1, dend2, L = 2) # 0.88 |
| 101 |
|
| 102 |
# a somewhat better tanglegram |
| 103 |
tanglegram(sort(dend1), sort(dend2)) |
| 104 |
# and alos a MUCH better entanglement |
| 105 |
entanglement(sort(dend1), sort(dend2), L = 1.5) # 0.0811 |
| 106 |
# but not that much, for L=0.25 |
| 107 |
entanglement(sort(dend1), sort(dend2), L = .25) # 0.579 |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
################## |
| 112 |
################## |
| 113 |
################## |
| 114 |
# massing up the order of leaves is dangerous: |
| 115 |
entanglement(dend1, dend2, 1.5, "order") # 0.91 |
| 116 |
order.dendrogram(dend2) <- seq_len(nleaves(dend2)) |
| 117 |
# this 0.95 number is NO LONGER correct!! |
| 118 |
entanglement(dend1, dend2, 1.5, "order") # 0.95 |
| 119 |
# but if we use the "labels" method - we still get the correct number: |
| 120 |
entanglement(dend1, dend2, 1.5, "labels") # 0.91 |
| 121 |
|
| 122 |
# however, we can fix our dend2, as follows: |
| 123 |
dend2 <- match_order_by_labels(dend2, dend1) |
| 124 |
# Now that labels and order are matched - entanglement is back at working fine: |
| 125 |
entanglement(dend1, dend2, 1.5, "order") # 0.91 |
| 126 |
} |
| 127 |
} |
| 128 |
\seealso{ |
| 129 |
\link{tanglegram}, \link{match_order_by_labels}. |
| 130 |
} |