Debian Codegraph @

man/untangle_step_rotate_1side.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/untangle.R
3 \name{untangle_step_rotate_1side}
4 \alias{untangle_step_rotate_1side}
5 \title{Stepwise untangle one tree compared to another}
6 \usage{
7 untangle_step_rotate_1side(
8 dend1,
9 dend2_fixed,
10 L = 1.5,
11 direction = c("forward", "backward"),
12 k_seq = NULL,
13 dend_heights_per_k,
14 leaves_matching_method = c("labels", "order"),
15 ...
16 )
17 }
18 \arguments{
19 \item{dend1}{a dendrogram object. The one we will rotate to best fit
20 dend2_fixed.}
21
22 \item{dend2_fixed}{a dendrogram object. This one is kept fixed.}
23
24 \item{L}{the distance norm to use for measuring the distance between the
25 two trees. It can be any positive number,
26 often one will want to use 0, 1, 1.5, 2 (see 'details' in \link{entanglement}).}
27
28 \item{direction}{a character scalar, either "forward" (default) or "backward".
29 Impacts the direction of clustering that are tried. Either from 2 and up
30 (in case of "forward"), or from nleaves to down (in case of "backward")
31
32 If k_seq is not NULL, then it overrides "direction".}
33
34 \item{k_seq}{a sequence of k clusters to go through for improving
35 dend1. If NULL (default), then we use the "direction" parameter.}
36
37 \item{dend_heights_per_k}{a numeric vector of values which indicate which height will produce which number of clusters (k)}
38
39 \item{leaves_matching_method}{a character scalar passed to \link{entanglement}.
40 It can be either "order" or "labels" (default). If using "labels",
41 then we use the labels for matching the leaves order value.
42 And if "order" then we use the old leaves order value for matching the
43 leaves order value.
44
45 Using "order" is faster, but "labels" is safer. "order" will assume that
46 the original two trees had their labels and order values MATCHED.
47
48 Hence, it is best to make sure that the trees used here have the same labels
49 and the SAME values matched to these values - and then use "order" (for
50 fastest results).
51
52 If "order" is used, the function first calls \link{match_order_by_labels}
53 in order to make sure that the two trees have their labels synced with
54 their leaves order values.}
55
56 \item{...}{not used}
57 }
58 \value{
59 A dendlist with
60 1) dend1 after it was rotated to best fit dend2_fixed.
61 2) dend2_fixed.
62 }
63 \description{
64 Given a fixed tree and a tree we wish to rotate, this function goes
65 through all of the k number of clusters (from 2 onward), and each time
66 rotates the branch which was introduced in the new k'th cluster.
67 This rotated tree is compared with the fixed tree, and if it has a better
68 entanglement, it will be used for the following iterations.
69
70 This is a greedy forward selection algorithm for rotating the tree and
71 looking for a better match.
72
73 This is useful for finding good trees for a \link{tanglegram}.
74 }
75 \examples{
76
77 \dontrun{
78 dend1 <- USArrests[1:10, ] \%>\%
79 dist() \%>\%
80 hclust() \%>\%
81 as.dendrogram()
82 set.seed(3525)
83 dend2 <- shuffle(dend1)
84 tanglegram(dend1, dend2)
85 entanglement(dend1, dend2, L = 2) # 0.4727
86
87 dend2_corrected <- untangle_step_rotate_1side(dend2, dend1)[[1]]
88 tanglegram(dend1, dend2_corrected) # FIXED.
89 entanglement(dend1, dend2_corrected, L = 2) # 0
90 }
91 }
92 \seealso{
93 \link{tanglegram}, \link{match_order_by_labels},
94 \link{entanglement}, \link{flip_leaves}, \link{all_couple_rotations_at_k},
95 \link{untangle_step_rotate_2side}.
96 }