This inference was accomplished by a Gibbs sampling algorithm that alternates between sampling each Z i conditional on X i and a previously sampled h, and sampling each element of h conditional on a previously sampled Z. It is straightforward to derive the required conditional distributions and to sample from them (Text S1). The Gibbs sampler converges rapidly and mixes well. Notice that, because the history without selection on any branch is excluded, all of the histories are described by codon models with the same number of parameters. Therefore, no penalty for parameter number is needed when comparing histories.