View source: R/findReversible.R
findReversible | R Documentation |
The Metropolis - Hastings algorithm is used to convert a mutation matrix to a reversible one.
findReversible(mutmat, method = "BA", afreq = NULL, check = TRUE)
mutmat |
A mutation matrix. |
method |
Character. 'MH','PR' or 'BA' |
afreq |
A vector with allele frequencies of the same length as the size of mutmat. |
check |
Logical. |
Three different approaches are implemented.
The method = "MH"
, based on the traditional proposal of MCMC,
gives a balanced matrix with off diagonal elements
q_{ij} min(1, p_j/p_i * q_{ji}/q_{ij})
where q_{ij}
and p_i
are the elements of the original mutation
matrix and the allele frequencies, respectively.
The method method = "BA"
, gives a balanced matrix with off diagonal elements
p_j q_{ij}q_{ji} / (p_i q_{ij} + (p_j q_{ji})
.
The method method = "PR"
is given by
(p_i q_{ij} + p_j q_{ji} ) / (2p_i)
if q_{ji} < p_i, i neq j
(and may otherwise fail to balance).
The expected mutation rate is preserved.
Reversible mutation matrix. The expected mutation rate of the balanced matrix is returned as 'rate'.
Thore Egeland
library(pedmut)
n = 4
p = 1:n/sum(1:n)
names(p) = 1:n
mutmat = mutationMatrix("onestep", rate = 0.02, afreq = p, alleles = 1:n)
R1 = findReversible(mutmat, method = "MH")
expectedMutationRate(R1)
isReversible(R1)
R2 = findReversible(mutmat, method = "PR")
isReversible(R2)
R3 = findReversible(mutmat, method = "BA")
isReversible(R3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.