View source: R/makeReversible.R
makeReversible | R Documentation |
The Metropolis - Hastings algorithm is used to convert a mutation matrix to a reversible one, i.e., find the balanced matrix matrix.
makeReversible(mutmat, method = "MH", afreq = NULL, check = TRUE)
mutmat |
A mutation matrix. |
method |
Character. MH, PM or BA conversions. |
afreq |
A vector with allele frequencies of the same length as the size of mutmat. |
check |
Logical. |
Three different approaches are implemented.
The default, method = "MH"
, 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 average method method = "PM"
, gives a balanced matrix with off diagonal elements
(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 method Barker method = "BA"
, gives a balanced matrix with off diagonal elements
p_j q_{ji}/(p_i q_{ij} + p_j q_{ji})
If q_{ij} = 0
or q_{ji} = 0
, the elements (i,j) and (j,i) of the transformed
matrix becomes 0.
Balanced 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)
makeReversible(mutmat)
makeReversible(mutmat, method = "PM")
makeReversible(mutmat, method = "BA")
Q = matrix(ncol = 2, c(0.9,0.9, 0.1, 0.1))
p = c(0.01, 0.99)
mutmat = mutationMatrix("custom", matrix = Q, alleles = 1:2)
makeReversible(mutmat, afreq = p)
# PM balancing not possible:
# makeReversible(mutmat, method = "PM", afreq = p)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.