| subchain | R Documentation |
Restricts a markovchain object to a chosen subset of its states,
either as a raw (generally non-stochastic) principal submatrix, or as a
properly renormalized Markov chain describing behaviour conditional on
staying inside the subset.
subchain(object, states, method = c("submatrix", "renormalize"))
## S4 method for signature 'markovchain'
subchain(object, states, method = c("submatrix", "renormalize"))
object |
A |
states |
A character vector of at least one state name from
|
method |
Either |
The two methods are deliberately named after two different, standard constructions, so that the choice – and its consequences – is explicit rather than implied:
"submatrix"Simply the entries of P with both
indices restricted to states, with no adjustment. Its rows
generally sum to less than one, because probability mass that
originally went to states outside the subset is dropped, not
redistributed. This is the "Q" block used, e.g., when building
the fundamental matrix of an absorbing chain (see
fundamentalMatrix): a useful building block for other
computations, but not itself a transition matrix of any Markov
chain, which is why it is returned as a plain matrix.
"renormalize"Each retained row is divided by its own
sum, so the result is row-stochastic and can be wrapped in a
markovchain object. This is the chain of successive positions
of object, conditioned on the event that it never
leaves states (sometimes called the chain "watched on"
states, or its taboo probabilities; see Norris (1997),
Section 3.3). It requires every state in states to have
strictly positive probability of transitioning within the subset
(otherwise that conditioning event has probability zero from that
state, and the row cannot be renormalized); an error is raised
naming any state that fails this, rather than silently producing a
row of NaN.
Neither method requires object to be irreducible: restricting to
a subset of states is meaningful for any chain, and is often used
precisely to study one communicating class in isolation.
The implementation performs no eigendecomposition; it is
O(k^2) time and memory for a subset of size k, after an
O(n^2) extraction from the full n-state matrix.
If method = "submatrix": a plain numeric matrix (not a
markovchain object, since its rows generally do not sum to one),
the principal submatrix of the transition matrix restricted to
states, always returned in row-stochastic orientation regardless
of object's own storage convention.
If method = "renormalize": a new markovchain object on
exactly the states in states, row-stochastic, describing the
chain conditional on never leaving that subset.
Norris, J. R. (1998). Markov Chains. Cambridge University Press.
lazyChain, fundamentalMatrix,
canonicForm
statesNames <- c("a", "b", "c")
mc <- new("markovchain", states = statesNames,
transitionMatrix = matrix(c(0.5, 0.3, 0.2,
0.2, 0.6, 0.2,
0.1, 0.1, 0.8), byrow = TRUE, nrow = 3,
dimnames = list(statesNames, statesNames)))
# Raw submatrix: rows no longer sum to 1, mass has "leaked" to "c".
subchain(mc, c("a", "b"), method = "submatrix")
rowSums(subchain(mc, c("a", "b"), method = "submatrix"))
# Renormalized: a genuine markovchain, conditional on staying in {a, b}.
watched <- subchain(mc, c("a", "b"), method = "renormalize")
watched
rowSums(watched@transitionMatrix)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.