Learn R Programming

markovchain (version 0.9.5)

markovchain-class: Markov Chain class

Description

The S4 class that describes markovchain objects.

Arguments

states

Name of the states. Must be the same of colnames and rownames of the transition matrix

byrow

TRUE or FALSE indicating whether the supplied matrix is either stochastic by rows or by columns

transitionMatrix

Square transition matrix

name

Optional character name of the Markov chain

Creation of objects

Objects can be created by calls of the form new("markovchain", states, byrow, transitionMatrix, ...).

Methods

*

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

absorbingStates

signature(object = "markovchain"): method to get absorbing states

canonicForm

signature(object = "markovchain"): return a markovchain object into canonic form

coerce

signature(from = "markovchain", to = "data.frame"): coerce method from markovchain to data.frame

conditionalDistribution

signature(object = "markovchain"): returns the conditional probability of subsequent states given a state

coerce

signature(from = "data.frame", to = "markovchain"): coerce method from data.frame to markovchain

coerce

signature(from = "table", to = "markovchain"): coerce method from table to markovchain

coerce

signature(from = "msm", to = "markovchain"): coerce method from msm to markovchain

coerce

signature(from = "msm.est", to = "markovchain"): coerce method from msm.est (but only from a Probability Matrix) to markovchain

coerce

signature(from = "etm", to = "markovchain"): coerce method from etm to markovchain

coerce

signature(from = "sparseMatrix", to = "markovchain"): coerce method from sparseMatrix to markovchain

coerce

signature(from = "markovchain", to = "igraph"): coercing to igraph objects

coerce

signature(from = "markovchain", to = "matrix"): coercing to matrix objects

coerce

signature(from = "markovchain", to = "sparseMatrix"): coercing to sparseMatrix objects

coerce

signature(from = "matrix", to = "markovchain"): coercing to markovchain objects from matrix one

dim

signature(x = "markovchain"): method to get the size

names

signature(x = "markovchain"): method to get the names of states

names<-

signature(x = "markovchain", value = "character"): method to set the names of states

initialize

signature(.Object = "markovchain"): initialize method

plot

signature(x = "markovchain", y = "missing"): plot method for markovchain objects

predict

signature(object = "markovchain"): predict method

print

signature(x = "markovchain"): print method.

show

signature(object = "markovchain"): show method.

sort

signature(x = "markovchain", decreasing=FALSE): sorting the transition matrix.

states

signature(object = "markovchain"): returns the names of states (as names.

steadyStates

signature(object = "markovchain"): method to get the steady vector.

summary

signature(object = "markovchain"): method to summarize structure of the markov chain

transientStates

signature(object = "markovchain"): method to get the transient states.

t

signature(x = "markovchain"): transpose matrix

transitionProbability

signature(object = "markovchain"): transition probability

Author

Giorgio Spedicato

References

A First Course in Probability (8th Edition), Sheldon Ross, Prentice Hall 2010

See Also

markovchainSequence,markovchainFit

Examples

Run this code
#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)
if (FALSE) plot(simpleMc)

Run the code above in your browser using DataLab