| populationGeneticsModel | R Documentation |
Constructs the Markov chain tracking the number of copies of a mutant
allele in a population of n individuals under mutation and
viability selection, for either the Moran or the Wright-Fisher model of
population genetics.
populationGeneticsModel(
model = c("moran", "wright-fisher"),
n,
s = 0,
u = 1e-09,
v = 1e-09,
states = NULL
)
model |
Either |
n |
A single integer of at least |
s |
A single finite number greater than |
u |
A single number in |
v |
A single number in |
states |
An optional character vector of |
Moran model. At each step one individual is chosen to reproduce
(with probability proportional to its type's relative fitness, mutant
fitness r=1+s against wild-type fitness 1) and one
individual, chosen uniformly at random, dies and is replaced by the
offspring, which mutates with probability u or v
depending on the parent's type. From interior state i
(0<i<n), writing r_i=(1+s)i and m_i=n-i,
P_{i,i-1}=\frac{i}{n}\cdot\frac{r_i v + m_i(1-u)}{r_i+m_i},\qquad
P_{i,i+1}=\frac{m_i}{n}\cdot\frac{r_i(1-u) + m_i v}{r_i+m_i},
with P_{ii} the remainder.
Wright-Fisher model. Generations are discrete and
non-overlapping: from interior state i, the mutant-allele
frequency k=i/n is first updated for mutation,
p=k(1-u)+(1-k)v, then for viability selection,
p'=\min\bigl(p(1+s)/(1+ps),\,1\bigr), and the next generation's
mutant count is \mathrm{Binomial}(n,p')-distributed:
P_{ij}=\binom{n}{j}p'^{\,j}(1-p')^{n-j}.
Both constructions follow PyDTMC's
population_genetics_model, with one deliberate difference: this
function uses mutant relative fitness 1+s in both models
(PyDTMC's Moran implementation instead uses 1-s, so that a
positive s there favours the wild-type rather than the mutant,
the opposite of its own Wright-Fisher convention and of the usual
textbook one). s = 0 (neutral drift) and the mutation-rate terms
are unaffected by this choice and match PyDTMC exactly; away from
s = 0 the two packages' Moran chains differ by construction, by
design, to keep s's meaning consistent between "moran" and
"wright-fisher" within this package. As u, v shrink to
0, both reduce to the classical drift-only chains with absorbing
loss/fixation states, going back to Wright (1931) and Moran (1958); see
Ewens (2004) for a modern textbook treatment of both.
A new, row-stochastic markovchain object on n + 1
states. States "0" and as.character(n) (loss and
fixation of the mutant allele) are absorbing, following the standard
textbook treatment of both models; every interior state has a
transition row determined by model, s, u and
v as detailed below.
Wright, S. (1931). Evolution in Mendelian populations. Genetics, 16(2), 97-159.
Moran, P. A. P. (1958). Random processes in genetics. Mathematical Proceedings of the Cambridge Philosophical Society, 54(1), 60-71.
Ewens, W. J. (2004). Mathematical Population Genetics I: Theoretical Introduction (2nd ed.). Springer.
birthDeath, gamblersRuin
# Neutral drift (s = 0): absorption ("fixation") probability of the
# mutant allele from state i equals i/n, the classical result.
neutral <- populationGeneticsModel(model = "moran", n = 8, s = 0)
ap <- absorptionProbabilities(neutral)
ap["4", "8"] # close to 4/8 = 0.5
# Positive selection increases the fixation probability from any
# interior starting count.
favoured <- populationGeneticsModel(model = "wright-fisher", n = 8, s = 0.5)
absorptionProbabilities(favoured)["4", "8"]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.