spectralGap: Spectral gap of a Markov chain

spectralGapR Documentation

Spectral gap of a Markov chain

Description

Computes the spectral gap of a finite, irreducible discrete-time Markov chain, a lightweight diagnostic of its convergence and mixing behaviour.

Usage

spectralGap(object)

## S4 method for signature 'markovchain'
spectralGap(object)

Arguments

object

A markovchain object representing a finite, irreducible discrete-time Markov chain.

Details

The spectral gap is defined from the second largest eigenvalue modulus (SLEM, see slem) as

\mathrm{gap} = 1 - \mathrm{SLEM}.

As with slem, only irreducibility is required. A periodic chain has SLEM = 1 and therefore spectral gap 0: this is the mathematically correct value, not an error condition, since a periodic chain never contracts towards its stationary distribution. A larger spectral gap indicates faster convergence to stationarity; see impliedTimescales for the timescale associated with each non-trivial eigenvalue individually, of which the SLEM gives the slowest (dominant) one.

Value

A numeric scalar in [0,1] containing the spectral gap. For the trivial one-state chain, 1 is returned.

References

Levin, D. A. and Peres, Y. (2017). Markov Chains and Mixing Times, 2nd edition. American Mathematical Society.

See Also

slem, impliedTimescales, is.irreducible

Examples

statesNames <- c("a", "b")
mc <- new("markovchain",
  states = statesNames,
  transitionMatrix = matrix(c(0.7, 0.3, 0.1, 0.9),
    byrow = TRUE, nrow = 2,
    dimnames = list(statesNames, statesNames)))
spectralGap(mc)


markovchain documentation built on Oct. 10, 2026, 9:07 a.m.