Performing a parametric bootstrap

Section author: Gavin Huttley

This file contains an example for estimating the probability of a Likelihood ratio statistic obtained from a relative rate test. The bootstrap classes can take advantage of parallel architectures.

From cogent3 import all the components we need.

Define the null model that takes an alignment object and returns a likelihood function properly assembled for optimising the likelihood under the null hypothesis. The sample distribution is generated using this model.

We will use a HKY model.

Define a function that takes an alignment object and returns an appropriately assembled function for the alternative model. Since the two models are identical bar the constraint on the branch lengths, we’ll use the same code to generate the basic likelihood function as for the alt model, and then apply the constraint here

Get our observed data alignment

Create a EstimateProbability bootstrap instance

Specify how many random samples we want it to generate. Here we use a very small number of replicates only for the purpose of testing.

Run it.

Get the estimated probability.

p is a floating point value, as you’d expect. Grab the estimated likelihoods (null and alternate) for the observed data.