# let's simulate two trees
set.seed(1)
treeA <- rtree(30,br = NULL)
treeB <- rtree(30,br = NULL)
if (FALSE) {
# visualize the difference between these two trees
library(phytools)
plot(cophylo(treeA,treeB))
# what is the Robinson-Foulds (RF) distance between these trees?
library(phangorn)
treedist(treeA,treeB)
}
# The RF distance is less intuitive when
# we consider a tree that isn't well-resolved
# let's simulate the worst resolved tree possible: a star tree
treeC <- stree(30)
if (FALSE) {
# plot the tanglegram between A and C
plot(cophylo(treeA,treeC))
# however the RF distance is *not* zero
# even though the only difference is a difference in resolution
treedist(treeA,treeC)
}
# the contradiction difference (CD) ignores differences in resolution
# Tree C (the star tree) has zero CD between it and trees A and B
identical(treeContradiction(treeA,treeC),0) # should be zero distance
identical(treeContradiction(treeB,treeC),0) # should be zero distance
# two identical trees also have zero CD between them (as you'd hope)
identical(treeContradiction(treeA,treeA),0) # should be zero distance
#' and here's the CD between A and B
treeContradiction(treeA,treeB) # should be non-zero distance
# a less ideal property of the CD is that two taxon on opposite ends of the
# moving from side of the topology to the other of an otherwise identical tree
# will return the maximum contradiction difference possible (i.e., ` = 1`)
# an example
treeAA <- read.tree(text = "(A,(B,(C,(D,(E,F)))));")
treeBB <- read.tree(text = "(E,(B,(C,(D,(A,F)))));")
if (FALSE) {
plot(cophylo(treeAA,treeBB))
}
treeContradiction(treeAA,treeBB)
if (FALSE) {
# Note however also a property of RF distance too:
treedist(treeAA,treeBB)
}
Run the code above in your browser using DataLab