| redistribute | R Documentation |
Propagates an initial distribution of the states of a discrete-time Markov chain forward in time and returns the whole trajectory of distributions.
redistribute(object, steps, initial = NULL, lastOnly = FALSE)
## S4 method for signature 'markovchain'
redistribute(object, steps, initial = NULL, lastOnly = FALSE)
object |
A |
steps |
A single non-negative whole number: the number of steps to
propagate. With |
initial |
The initial distribution. Either |
lastOnly |
Logical. If |
If \mu_0 is the initial distribution (a row vector) and P the
row-stochastic transition matrix, the distribution after t steps is
\mu_t = \mu_{t-1} P = \mu_0 P^t.
The implementation propagates the vector step by step, at a cost of
O(n^2) per step for a dense n-state chain, instead of
forming P^t; this is what makes the whole trajectory available at
no extra cost. Both row- and column-stochastic storage are supported.
Each distribution is renormalized after every step to prevent round-off
from accumulating over long horizons.
This mirrors PyDTMC's redistribute(), with the same defaults
(uniform initial distribution, output including the initial one).
For chains that converge, the rows approach the stationary distribution
(see steadyStates); for periodic chains they do not, which is
the expected behaviour and not an error.
If lastOnly = FALSE (default), a numeric matrix with
steps + 1 rows and one column per state: row t (labelled
"t", from "0") holds the distribution after t
steps, so the first row is the initial distribution. Otherwise, a named
numeric vector with the distribution after steps steps.
steadyStates, mixingTime,
autoplot.markovchain
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)))
redistribute(mc, steps = 5, initial = "a")
redistribute(mc, steps = 50, initial = c(a = 0.2, b = 0.8), lastOnly = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.