gamblersRuin: Build a gambler's ruin Markov chain

View source: R/generators.R

gamblersRuinR Documentation

Build a gambler's ruin Markov chain

Description

Constructs the classic gambler's ruin chain: a gambler with a fortune between 0 and upperBound wins each round (and gains one unit) with probability prob, otherwise loses one unit; play stops as soon as the fortune reaches 0 (ruin) or upperBound (the gambler's target).

Usage

gamblersRuin(upperBound, prob, states = NULL)

Arguments

upperBound

A single positive integer: the fortune at which the gambler stops (having won). The chain has upperBound + 1 states, 0,1,\ldots,\code{upperBound}.

prob

A single number in [0,1]: the probability of winning an individual round (moving up by one unit) while the fortune is strictly between 0 and upperBound.

states

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

Details

This is the special case of birthDeath with constant birth probability prob and constant death probability 1-prob at every interior state, together forced to be absorbing rather than merely reflecting at the two ends – which is why it is provided as its own constructor rather than expressed purely in terms of birthDeath(), which cannot produce absorbing boundaries by itself (see toBoundedChain for turning any chain's ends absorbing or reflecting after construction).

With prob != 0.5, the classical ruin probability of reaching 0 before upperBound, starting from fortune i, is

P(\text{ruin}\mid X_0=i) = \frac{\left(\frac{1-\code{prob}}{\code{prob}}\right)^{i} - \left(\frac{1-\code{prob}}{\code{prob}}\right)^{\code{upperBound}}} {1-\left(\frac{1-\code{prob}}{\code{prob}}\right)^{\code{upperBound}}},

and i/\code{upperBound} when prob = 0.5; this is a standard textbook result (see Norris (1998), Section 1.3) and is not itself computed by this function, but can be read off from absorptionProbabilities applied to the returned chain.

Value

A new, row-stochastic markovchain object with upperBound + 1 states. States "0" and as.character(upperBound) are absorbing; every interior state i has P_{i,i+1}=\code{prob} and P_{i,i-1}=1-\code{prob}.

References

Norris, J. R. (1998). Markov Chains. Cambridge University Press.

See Also

birthDeath, absorptionProbabilities, toBoundedChain

Examples

ruin <- gamblersRuin(upperBound = 5, prob = 0.4)
ruin
absorbingStates(ruin)


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