Learn R Programming

markovchain (version 0.0.2)

markovchainSequence: Function to generate a sequence of states from a given discrete markov chain.

Description

Provided a markovchain object, it returns a sequence of states coming from the underlying stationary distribution.

Usage

markovchainSequence(n, markovchain, t0 = sample(markovchain@states, 1), 
include.t0 = FALSE)

Arguments

n
length of the sequence
markovchain
markov chain
t0
initial state
include.t0
logical, tells if t0 shall be added as initial value.

Value

  • a vector of characters

Details

It is assumed the process to arise from a single steady state markov chain.

See Also

markovchainFit

Examples

Run this code
#define the markov chain
statesNames=c("a","b","c")
mcB<-new("markovchain", states=statesNames, transitionMatrix=
          matrix(c(0.2,0.5,0.3,
                   0,0.2,0.8,
                   0.1,0.8,0.1),nrow=3, byrow=TRUE, dimnames=list(statesNames,
				   statesNames)
                 ))

#show the sequence
outs<-markovchainSequence(n=100,markovchain=mcB, t0="a")

Run the code above in your browser using DataLab