A test of the neutral theory

Section author: Gavin Huttley

This file contains an example for performing a likelihood ratio test of neutrality. The test compares a model where the codon model parameter omega is constrained to be the same for all edges against one where each edge has its’ own omega. From cogent3 import all the components we need.

Get your alignment and tree.

We use a Goldman Yang 1994 model.

Make the controller object

Get the likelihood function object this object performs the actual likelihood calculation.

By default, parameters other than branch lengths are treated as global in scope, so we don’t need to do anything special here. We can influence how rigorous the optimisation will be, and switch between the global and local optimisers provided in the toolkit using arguments to the optimise method. The global_tolerance=1.0 argument specifies conditions for an early break from simulated annealing which will be automatically followed by the Powell local optimiser. .. note:: the ‘results’ are of course nonsense.

View the resulting maximum-likelihood parameter values

We’ll get the lnL and number of free parameters for later use.

Specify each edge has it’s own omega by just modifying the existing lf. This means the new function will start with the above values.

Optimise the likelihood function, this time just using the local optimiser.

View the resulting maximum-likelihood parameter values.

Get out an annotated tree, it looks just like a tree, but has the maximum-likelihood parameter estimates attached to each tree edge. This object can be used for plotting, or to provide starting estimates to a related model.

The lnL’s from the two models are now used to calculate the likelihood ratio statistic (LR) it’s degrees-of-freedom (df) and the probability (P) of observing the LR.

Print this and look up a chi-sq with number of edges - 1 degrees of freedom.