<h1>Terminology</h1>

<p>First, a couple of corrections to your use of terminology. A tree <em>must</em> have branch lengths associated with it to be called a <strong>phylogenetic tree</strong> as it represents both the relationships between OTU/taxa/leaves <em>AND</em> the distances between them (i.e. the branch lengths. A tree where branch lengths have no meaning is called a <strong>cladograms</strong> or a <strong>dendrogram</strong>. You can tell if a tree is a cladogram since all the OUTs/taxa/leaves end at the same position and internal branch lengths are usually (not always) of equal length. Whereas a phylogeny the OTUs/taxa/leaves will typically look "staggered" <em>and</em> internal branches will be of different lengths.</p>

<p>Therefore, If the tree you have estimated, truly doesn't have branch lengths estimated and associated with it, it is actually a cladogram.</p>

<h1>Example Derived from <code>phangorn</code> Vignette</h1>

<pre class="lang-r prettyprint-override"><code>library(phangorn)

# Get example data
fdir &lt;- system.file("extdata/trees", package = "phangorn")
primates &lt;- read.phyDat(file.path(fdir, "primates.dna"), format = "phylip")

# Calculate pairwise distances between OTUs using Maximum Likelihood
dm &lt;- dist.ml(primates)

# Use the distances to cluster the OTUs using UPGMA algorithm
# This creates a dendrogram
treeUPGMA &lt;- upgma(dm)
plot(treeUPGMA, main="UPGMA")
dev.off()
</code></pre>

<p><a href="https://i.sstatic.net/6SHVE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/6SHVE.png" alt="enter image description here"></a></p>

<pre class="lang-r prettyprint-override"><code># Search for different, similar trees to the initial UPGMA tree
# looking for a tree with the lowest parsimony score
# There are 2 search algorithms implemented:
#   optim.parsimony()
#   pratchet()
# These are still cladograms
treePars &lt;- optim.parsimony(treeUPGMA, primates)
treeRatchet &lt;- pratchet(primates, trace = 0)
plot(treePars, main="optim.parsimony()")
plot(treeRatchet, main="pratchet()")
dev.off()
</code></pre>

<p><a href="https://i.sstatic.net/2I82V.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2I82V.png" alt="enter image description here"></a>
<a href="https://i.sstatic.net/2fcvD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2fcvD.png" alt="enter image description here"></a></p>

<pre class="lang-r prettyprint-override"><code># Calculate branch lengths using the most parsimonious tree identified by
# the pratchet() searchh algorithm
phylogeny &lt;- nnls.phylo(treeRatchet, dm)
plot(phylogeny, main="Phylogeny")
dev.off()
</code></pre>

<p><a href="https://i.sstatic.net/b8Qdl.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/b8Qdl.png" alt="enter image description here"></a></p>

<h1>Choices, Choices, Choices</h1>

<p>As you can see from the above example, there are lots of steps to calculating a phylogenetic tree. At each of these steps there may be multiple algorithms to choose from. You choice will depend on the type of data you are analysing, the size of the data set, your available compute resources and the algorithms implemented and available through the tools you use.</p>

<p>Ultimately, you will have to know a fair bit about these algorithms to make an informed choice.</p>

CC BY-SA 4.0
2018-06-20T01:07:37.423Z
2018-06-20T01:07:37.423Z
Nathan S. Watson-Haigh
<p>@Nathan S. Watson-Haigh's answer does give branch lengths, but NOT parsimony branch lengths, which may be what the OP wanted.  <code>nnls.phylo</code> is giving distances calculated from a pairwise distance matrix. To get the parsimony branch lengths (i.e. number of changes mapped on to each branch), score the tree against the dataset using <code>acctran</code>:</p>

<pre><code>treeRatchet &lt;- pratchet(primates)
treeRatchet.BL &lt;- acctran(treeRatchet,primates)
plot(treeRatchet.BL,main='Phylogeny (Parsimony branch lengths)')
</code></pre>

<p><a href="https://i.sstatic.net/c1NYZ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/c1NYZ.png" alt="phylogram with parsimony branch lengths"></a>
Note that the branch lengths in the parsimony phylogram are 'chunkier' than those in the nnls.phylo phylogram -- that's because </p>

<ol>
<li>they are all integers, and </li>
<li>they aren't corrected with reference to a model of substitution that considers multiple hits or base composition.</li>
</ol>

CC BY-SA 4.0
2018-06-26T00:18:00.603Z
2018-06-26T10:14:29.980Z
2018-06-26T10:14:29.980Z
Will Fischer
<p>I am trying to estimate a phylogenetic tree in R with <a href="https://cran.r-project.org/package=ape" rel="nofollow noreferrer">ape</a> and <a href="https://cran.r-project.org/package=phangorn" rel="nofollow noreferrer">phangorn</a>. With <code>pratchet()</code> and <code>optim.parsimony()</code>, I can estimate a phylogenetic tree, but branch lengths are not estimated. Is there a way to estimate a phylogeny with branch lengths with the following made-up data:</p>

<pre><code>x &lt;- data.frame("L1" = c(0,0,1,0,0,0,1,1,1,1,0,0,0,0,1), "L2" = c(0,1,1,0,1,1,0,1,1,0,1,1,0,1,1),"L3" = c(1,1,1,0,0,0,1,1,1,0,0,0,1,1,1), "L4"=c(0,0,1,1,0,0,0,0,1,1,0,0,0,0,1)) 
</code></pre>

CC BY-SA 4.0
2018-06-26T12:35:39.090Z
Don’t quote your identifiers! It’s `L1`, `L2`, etc.; not `"L1"`, `"L2"` …. R unfortunately allows is but this is a language flaw that should not be exploited.
Konrad Rudolph
CC BY-SA 4.0
2018-06-27T23:54:19.463Z
Can you provide a link to further information @konrad-rudolph
Nathan S. Watson-Haigh
CC BY-SA 4.0
2018-06-28T09:43:35.407Z
@NathanS.Watson-Haigh Unfortunately I’m not sure what further information you’re looking for, I’m afraid.
Konrad Rudolph
<r><phylogenetics><phylogeny>
How do I estimate branch length of a maximum parsimony phylogeny in R?
# How do I estimate branch length of a maximum parsimony phylogeny in R?

(Asked by: username_0 on 2018-06-18)

I am trying to estimate a phylogenetic tree in R with ape and phangorn. With pratchet() and optim.parsimony(), I can estimate a phylogenetic tree, but branch lengths are not estimated. Is there a way to estimate a phylogeny with branch lengths with the following made-up data:
x <- data.frame("L1" = c(0,0,1,0,0,0,1,1,1,1,0,0,0,0,1), "L2" = c(0,1,1,0,1,1,0,1,1,0,1,1,0,1,1),"L3" = c(1,1,1,0,0,0,1,1,1,0,0,0,1,1,1), "L4"=c(0,0,1,1,0,0,0,0,1,1,0,0,0,0,1))

**Tags:** r, phylogenetics, phylogeny
> **Comments:**
> **username_1**: Don’t quote your identifiers! It’s `L1`, `L2`, etc.; not `"L1"`, `"L2"` …. R unfortunately allows is but this is a language flaw that should not be exploited.  
> **username_2**: Can you provide a link to further information @konrad-rudolph  
> **username_1**: @NathanS.Watson-Haigh Unfortunately I’m not sure what further information you’re looking for, I’m afraid.  

---

## 2 answers

### Answer by username_3 on 2018-06-26. Score: 2 | Accepted answer

@Nathan S. Watson-Haigh's answer does give branch lengths, but NOT parsimony branch lengths, which may be what the OP wanted.  nnls.phylo is giving distances calculated from a pairwise distance matrix. To get the parsimony branch lengths (i.e. number of changes mapped on to each branch), score the tree against the dataset using acctran:
treeRatchet <- pratchet(primates)
treeRatchet.BL <- acctran(treeRatchet,primates)
plot(treeRatchet.BL,main='Phylogeny (Parsimony branch lengths)')


Note that the branch lengths in the parsimony phylogram are 'chunkier' than those in the nnls.phylo phylogram -- that's because 

they are all integers, and 
they aren't corrected with reference to a model of substitution that considers multiple hits or base composition.


---

### Answer by username_2 on 2018-06-20. Score: 1

Terminology
First, a couple of corrections to your use of terminology. A tree must have branch lengths associated with it to be called a phylogenetic tree as it represents both the relationships between OTU/taxa/leaves AND the distances between them (i.e. the branch lengths. A tree where branch lengths have no meaning is called a cladograms or a dendrogram. You can tell if a tree is a cladogram since all the OUTs/taxa/leaves end at the same position and internal branch lengths are usually (not always) of equal length. Whereas a phylogeny the OTUs/taxa/leaves will typically look "staggered" and internal branches will be of different lengths.
Therefore, If the tree you have estimated, truly doesn't have branch lengths estimated and associated with it, it is actually a cladogram.
Example Derived from phangorn Vignette
library(phangorn)

# Get example data
fdir <- system.file("extdata/trees", package = "phangorn")
primates <- read.phyDat(file.path(fdir, "primates.dna"), format = "phylip")

# Calculate pairwise distances between OTUs using Maximum Likelihood
dm <- dist.ml(primates)

# Use the distances to cluster the OTUs using UPGMA algorithm
# This creates a dendrogram
treeUPGMA <- upgma(dm)
plot(treeUPGMA, main="UPGMA")
dev.off()


# Search for different, similar trees to the initial UPGMA tree
# looking for a tree with the lowest parsimony score
# There are 2 search algorithms implemented:
#   optim.parsimony()
#   pratchet()
# These are still cladograms
treePars <- optim.parsimony(treeUPGMA, primates)
treeRatchet <- pratchet(primates, trace = 0)
plot(treePars, main="optim.parsimony()")
plot(treeRatchet, main="pratchet()")
dev.off()



# Calculate branch lengths using the most parsimonious tree identified by
# the pratchet() searchh algorithm
phylogeny <- nnls.phylo(treeRatchet, dm)
plot(phylogeny, main="Phylogeny")
dev.off()


Choices, Choices, Choices
As you can see from the above example, there are lots of steps to calculating a phylogenetic tree. At each of these steps there may be multiple algorithms to choose from. You choice will depend on the type of data you are analysing, the size of the data set, your available compute resources and the algorithms implemented and available through the tools you use.
Ultimately, you will have to know a fair bit about these algorithms to make an informed choice.


---

