urnModel: Build an Ehrenfest urn model Markov chain

View source: R/generators.R

urnModelR Documentation

Build an Ehrenfest urn model Markov chain

Description

Constructs the Ehrenfest diffusion model: balls balls are split between two urns, A and B; at each step, one of the balls balls is chosen uniformly at random and moved to the other urn. The chain tracks the number of balls in urn A.

Usage

urnModel(balls, states = NULL)

Arguments

balls

A single positive integer, the total number of balls. The chain has balls + 1 states, 0,1,\ldots,\code{balls} (the possible counts of balls in urn A).

states

An optional character vector of balls + 1 state names, in increasing order of ball count. Defaults to as.character(0:balls).

Details

The Ehrenfest model is the classical example of a chain whose equilibrium behaviour matches thermodynamic intuition despite every individual transition being fully reversible: its stationary distribution is \mathrm{Binomial}(\code{balls}, 1/2) (each ball is, at equilibrium, independently in urn A or B with probability 1/2), sharply concentrated around \code{balls}/2 for large balls even though the chain only ever moves one ball at a time and is reflecting, not absorbing, at the boundaries. It is irreducible and reversible for every balls, but periodic with period 2 (the parity of the ball count in urn A alternates every step): pass the result through lazyChain first if an aperiodic chain is needed, e.g. for mixingTime.

Value

A new, row-stochastic markovchain object with balls + 1 states. From state i (0<i<\code{balls}),

P_{i,i-1} = i/\code{balls}, \qquad P_{i,i+1} = 1 - i/\code{balls},

the probability that the ball moved was one of the i currently in urn A (decreasing A's count) versus one of the \code{balls}-i currently in urn B (increasing it). States 0 and balls (all balls in one urn) are reflecting: the next ball moved must come from the only non-empty urn, so P_{0,1}=P_{\code{balls}, \code{balls}-1}=1 exactly.

References

Ehrenfest, P. and Ehrenfest, T. (1907). Uber zwei bekannte Einwande gegen das Boltzmannsche H-Theorem. Physikalische Zeitschrift, 8, 311-314.

See Also

birthDeath, lazyChain

Examples

ehrenfest <- urnModel(balls = 4)
ehrenfest
steadyStates(ehrenfest) # approximately Binomial(4, 0.5): 1/16 6/16 ...
dbinom(0:4, 4, 0.5)


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