Skip to main content
. 2022 Jul 19;11:e76004. doi: 10.7554/eLife.76004
Algorithm 4. Importance sampled log-likelihood given a single datapoint
procedure SigmaLikelihood (μ^,μ^,m,s,θts,N)           ⊳ Takes mutant m and susceptible s counts for a particular site at a single timepoint. Returns an approximate log-likelihood function l(σ^)=logP(m,s|θts,σ^)+c, up to an additive constant. SigmaLikelihood is a closure that returns a one-parameter function. We used N =103 samples.
   θμ^θtsθμ^θts
  for i1:N do
     xiBeta(θ,θ)                           ⊳ Sample from the neutral distribution
     wiB(θ+m,θ+s)B(θ,θ)1xim(1xi)w                         ⊳ Importance weight ratio
    yiBeta(θ+m,θ+s)                    ⊳ sample from the neutral distribution, conditioned on the observations
     viB(θ+m,θ+s)B(θ,θ)1yim(1yi)w                          ⊳ Importance weight ratio
  end for
  Z0(σ^):=1Nieσ^θtsxi11+wi+1Nieσ^θtsyi11+vi         ⊳ importance sampling mean
  Z1(σ^):=1Nieσ^θtsxi11+wi1+1Nieσ^θtsyi11+vi1            ⊳ Note the inversion in the weighting factor compared to Z0.
return l(σ^):=logZ1(σ^)logZ0(σ^) ⊳ Return a log-likelihood function. The same random variable realizations x1:N and y1:N are cached in memory and used for each function evaluation, making l(σ^) continuous and differentiable.
end procedure