This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to root a tree in R with a polytomy at the root

In R, I have a phylogenetic tree like this, with a polytomy at the root:

library(ape)
t1 = read.tree(text="[&R] (1:1.250,2:1.250,(3:0.750,(4:0.500,5:0.500):0.250):0.500);")

But it is treated as unrooted:

> is.rooted(t1)
[1] FALSE

How can I force it to be rooted at the polytomy?

r phylogenetics

What exactly do you want to do with this if you force to to be rooted? One option is to randomly resolve the polytomy, but that is dangerous if you're doing further downstream analysis?

I want to compare this tree with an alternative (in this example, strictly bifurcating) tree, as (1:0.833,(2:0.225,(3:0.209,(4:0.114,5:0.114):0.095):0.016):0.608);, and calculate distance metrics between them. This is not strictly defined for some common stats, such as the Robinson-Foulds distance, but is for e.g. the Kendall-Colijn metric (treeDist from the treescape package)

2 answers

Emmanuel Paradis has pointed out that the solution is simple - the tree is treated as unrooted because the deepest node has no length. So all I have to do is to place ":0" before the terminal semicolon, and the tree should be treated as rooted.

Glad that you got it sorted out.

Cheers. Always good to get advice from the author of the library :)

You can root it yourself like this (here we set 1 as the root):

library(ape)

t1 = read.tree(text="[&R] (1:1.250,2:1.250,(3:0.750,(4:0.500,5:0.500):0.250):0.500);")

t1 <- root(t1, outgroup=1, resolve.root=TRUE)

is.rooted(t1)
[1] TRUE

par(mfrow=c(1,2))
plot(t1, type="cladogram", main="Rooted at 1")
plot(t1, type="unrooted", main="Unrooted")

Captura_de_tela_de_2018_01_19_15_21_26

Does that maintain the polytomy? I.e. is this the same tree as if it were rooted at 2? From a casual inspection it seems not:

> t1 = read.tree(text="[&R] (1:1.250,2:1.250,(3:0.750,(4:0.500,5:0.500):0.250):0.500);")
> t2 <- root(t1, outgroup=1, resolve.root=TRUE)
> t3 <- root(t1, outgroup=2, resolve.root=TRUE)
> RF.dist(t2,t3, rooted=TRUE)
[1] 2

Log in to answer this question.