exact_mc: Exact method for p-value [Markov chains]

View source: R/RcppExports.R

exact_mcR Documentation

Exact method for p-value [Markov chains]

Description

Calculates the exact p-value for short numerical Markov chains. Memory usage and time computation can be too large for a high local score value and high score range (see details).

Usage

exact_mc(local_score, m, sequence_length, score_values = NULL, prob0 = NULL)

Arguments

local_score

Integer local score for which the p-value should be calculated

m

Transition matrix [matrix object]. Optionality, rownames can be corresponding score values. m should be a transition matrix of an ergodic Markov chain.

sequence_length

Length of the sequence

score_values

A integer vector of sequence score values (optional). If not set, the rownames of m are used if they are numeric and set.

prob0

Vector of probability distribution of the first score of the sequence (optional). If not set, the stationnary distribution of m is used.

Details

This method computation needs to allocate a square matrix of size local_score^(range(score_values)). This matrix is then exponentiated to sequence_length.

Value

A double representing the probability of a local score as high as the one given as argument

See Also

monteCarlo

Examples

mTransition <- matrix(c(0.2, 0.3, 0.5, 0.3, 0.4, 0.3, 0.2, 0.4, 0.4), byrow = TRUE, ncol = 3)
scoreValues <- -1:1
initialProb <- stationary_distribution(mTransition)
exact_mc(local_score = 12, m = mTransition, sequence_length = 100, 
        score_values = scoreValues, prob0 = initialProb)
exact_mc(local_score = 150, m = mTransition, sequence_length = 1000, 
         score_values = scoreValues, prob0 = initialProb)
rownames(mTransition) <- scoreValues
exact_mc(local_score = 12, m = mTransition, sequence_length = 100, prob0 = initialProb)
# Minimal specification
exact_mc(local_score = 12, m = mTransition, sequence_length = 100)
# Score valeus with "holes"
scoreValues <- c(-2, -1, 2)
mTransition <- matrix(c(0.2, 0.3, 0.5, 0.3, 0.4, 0.3, 0.2, 0.4, 0.4), byrow = TRUE, ncol = 3)
initialProb <- stationary_distribution(mTransition)
exact_mc(local_score = 50, m = mTransition, sequence_length = 100, 
        score_values = scoreValues, prob0 = initialProb)

localScore documentation built on April 3, 2025, 5:26 p.m.