Calculating the likelihood of a particular phylogenetic tree sounds complicated and it's easy to get lost in the details, but is really just a matter of bookkeeping. That's why we have computers! This example is taken from my all-time favorite Bioinformatics textbook (Higgs & Attwood).

Let's work with the tree shown above. We're considering one particular site in a sequence alignment from a set of OTUs (operational taxonomic units), where the observed nucleotides are as shown. The identities of the internal nodes are unknown and each could be any one of the four nucleotides. (I've shown the same tree several times at different places in the post for reference).

Consider first the node labeled X. In general, the branches from X to A and from X to G may be different in length. Suppose the first one is described by t

_{1}and the second by t

_{2}.

We have a particular model of sequence evolution for this site, encapsulated in a transition-probability matrix (as discussed here), which allows us to calculate the probabilities for all 4 possibilities with no change:

and all 12 possible changes:

The identity of X isn't known, it

*might*be any of

`{A,C,G,T}`

. Starting with A, then we can calculate the probabilities for the two branches as:The probability of the observed data for both of these two terminal nodes with the model that X = A, is the

*likelihood*that X = A,

*given the data*. Namely:

In the same way:

Of course, the total probability for X =

`{A,C,G,T}`

is the sum:which has to equal 1, since X must be one of the four nucleotides.

Repeated multiplication leads to various difficulties which are avoided by using logarithms. So typically we would talk about the log likelihood, for example the log of L(X=C). All of the calculations shown below as multiplications would be done in practice by adding the logarithm of each term.

### Working up the tree

Now consider node Y and its branch to X, with a branch length described by t

_{3}.

We can calculate the probabilty for any choice of nucleotides (say, Y = A, X = C) in the same way as before. For this choice it is:

It can also be written using the expression for likelihood L(X=C) as:

Stick with probabilities for a moment.

There are 16 possible paths here. Suppose Y = M and X = N, where both M and N are in the set

`{A,C,G,T}`

. Then there are 16 terms like:This is only for the left-hand clade. We usually talk about the tree as if it were rotated with Z at the top and Y on the left, but it's easier to draw as shown. The probability for the right-hand branch from Y to G described by t

_{4}, is calculated for any particular choice of M =

`{A,C,G,T}`

as described in the first part:So each of our 16 terms picks up an additional factor

and the sum of the four terms involving Y=M (for a particular choice of M = A,C,G or T) is the likelihood L(Y=M).

### A node with two internal child nodes

Now consider node W at the top of the tree and the branch t

_{5}connecting it to Y. We let W assume any of the four states

`{A,C,G,T}`

and calculate probabilities as follows:For the t

_{5}branch, we have three equivalent expressions:

There are 16 terms like:

for each of the 16 possible values for the tuple (W,Y). Once again, this is only for the left-hand clade. Each of the 16 terms picks up another factor from the right-hand branch:

So the total likelihood

`L(W=A,Y={A,C,G,T},Z={A,C,G,T})`

is the sum of:An equivalent description is to call this a sum of sums, or double sum:

The expression is symmetrical and you could use either M or N in the outside sum. But the double sum makes my head spin a bit. So I'll stick with the longer (and perhaps less confusing) formula.

We can abbreviate this as L(W=A).

### Top of the tree

At the top of the tree, there is a final factor which comes in. It is π, the equilibrium frequency of each nucleotide according to our evolutionary model. The total likelihood for the tree is the sum over the four nucleotides:

### An alignment of many sites

As Higgs and Attwood say:

The likelihood is calculated for each site in this way, and it is assumed that sites evolve independently. Therefore the likelihood for the complete sequence set, L_{tot}, is the product of the likelihoods of the sites. It therefore follows that the log of the likelihood is the sum of the logs of the site likelihoods.

Like I said, it's just a matter of bookkeeping.