| markovchain-class | R Documentation |
The S4 class that describes markovchain objects.
statesName of the states. Must be the same of colnames and rownames of the transition matrix
byrowTRUE or FALSE indicating whether the supplied matrix is either stochastic by rows or by columns
transitionMatrixSquare transition matrix
nameOptional character name of the Markov chain
Objects can be created by calls of the form new("markovchain", states, byrow, transitionMatrix, ...).
signature(e1 = "markovchain", e2 = "markovchain"): multiply two markovchain objects
signature(e1 = "markovchain", e2 = "matrix"): markovchain by matrix multiplication
signature(e1 = "markovchain", e2 = "numeric"): markovchain by numeric vector multiplication
signature(e1 = "matrix", e2 = "markovchain"): matrix by markov chain
signature(e1 = "numeric", e2 = "markovchain"): numeric vector by markovchain multiplication
signature(x = "markovchain", i = "ANY", j = "ANY", drop = "ANY"): ...
signature(e1 = "markovchain", e2 = "numeric"): power of a markovchain object
signature(e1 = "markovchain", e2 = "markovchain"): equality of two markovchain object
signature(e1 = "markovchain", e2 = "markovchain"): non-equality of two markovchain object
signature(object = "markovchain"): method to get absorbing states
signature(object = "markovchain"): return a markovchain object into canonic form
signature(from = "markovchain", to = "data.frame"): coerce method from markovchain to data.frame
signature(object = "markovchain"): returns the conditional probability of subsequent states given a state
signature(from = "data.frame", to = "markovchain"): coerce method from data.frame to markovchain
signature(from = "table", to = "markovchain"): coerce method from table to markovchain
signature(from = "msm", to = "markovchain"): coerce method from msm to markovchain
signature(from = "msm.est", to = "markovchain"): coerce method from msm.est (but only from a Probability Matrix) to markovchain
signature(from = "etm", to = "markovchain"): coerce method from etm to markovchain
signature(from = "sparseMatrix", to = "markovchain"): coerce method from sparseMatrix to markovchain
signature(from = "markovchain", to = "igraph"): coercing to igraph objects
signature(from = "markovchain", to = "matrix"): coercing to matrix objects
signature(from = "markovchain", to = "sparseMatrix"): coercing to sparseMatrix objects
signature(from = "matrix", to = "markovchain"): coercing to markovchain objects from matrix one
signature(x = "markovchain"): method to get the size
signature(x = "markovchain"): method to get the names of states
signature(x = "markovchain", value = "character"): method to set the names of states
signature(.Object = "markovchain"): initialize method
signature(x = "markovchain", y = "missing"): plot method for markovchain objects
signature(object = "markovchain"): predict method. Starting from the last element of newdata, which must be a state of the chain, it returns the n.ahead following states, each being the most probable transition from the previous one; ties are broken at random.
signature(x = "markovchain"): print method.
signature(object = "markovchain"): show method.
signature(x = "markovchain", decreasing=FALSE): sorting the transition matrix.
signature(object = "markovchain"): returns the names of states (as names.
signature(object = "markovchain"): method to get the steady vector.
signature(object = "markovchain"): method to summarize structure of the markov chain.
summary(object, details = TRUE) also prints, after the usual output, the size and rank of
the transition matrix, the number of communicating classes, irreducibility, period, regularity,
whether the chain is absorbing, reversible, stochastically monotone and symmetric, and, when they
are defined, the entropy rate, the SLEM, the spectral gap and Kemeny's constant; these values are
also returned, invisibly, in the details element of the result.
signature(object = "markovchain"): method to get the transient states.
signature(x = "markovchain"): transpose matrix
signature(object = "markovchain"): transition probability
markovchain object are backed by S4 Classes.
Validation method is used to assess whether either columns or rows totals to one.
Rounding is used up to .Machine$double.eps * 100. If state names are not properly
defined for a probability matrix, coercing to markovchain object leads
to overriding states name with artificial "s1", "s2", ... sequence. In addition, operator
overloading has been applied for +,*,^,==,!= operators.
Giorgio Spedicato
A First Course in Probability (8th Edition), Sheldon Ross, Prentice Hall 2010
markovchainSequence,markovchainFit
#show markovchain definition
showClass("markovchain")
#create a simple Markov chain
transMatr<-matrix(c(0.4,0.6,.3,.7),nrow=2,byrow=TRUE)
simpleMc<-new("markovchain", states=c("a","b"),
transitionMatrix=transMatr,
name="simpleMc")
#power
simpleMc^4
#some methods
steadyStates(simpleMc)
absorbingStates(simpleMc)
simpleMc[2,1]
t(simpleMc)
is.irreducible(simpleMc)
#conditional distributions
conditionalDistribution(simpleMc, "b")
#example for predict method
sequence<-c("a", "b", "a", "a", "a", "a", "b", "a", "b", "a", "b", "a", "a", "b", "b", "b", "a")
mcFit<-markovchainFit(data=sequence)
predict(mcFit$estimate, newdata="b",n.ahead=3)
#direct conversion
myMc<-as(transMatr, "markovchain")
#example of summary
summary(simpleMc)
summary(simpleMc, details = TRUE)
## Not run: plot(simpleMc)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.