findReversible: Find reversible mutation matrix

View source: R/findReversible.R

findReversibleR Documentation

Find reversible mutation matrix

Description

The Metropolis - Hastings algorithm is used to convert a mutation matrix to a reversible one.

Usage

findReversible(mutmat, method = "BA", afreq = NULL, check = TRUE)

Arguments

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.

Details

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.

Value

Reversible mutation matrix. The expected mutation rate of the balanced matrix is returned as 'rate'.

Author(s)

Thore Egeland

Examples

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)

thoree/mut2 documentation built on June 11, 2025, 4:02 p.m.