markov_seq: Discrete markov sequence

Description Usage Arguments Examples

View source: R/markov_seq.R

Description

Generate a random discrete markov sequence

Usage

1
markov_seq(n = 100, tmat = rbind(1:3, 3:1, 2:0), init = 1)

Arguments

n

length of the sequence

tmat

a transition matrix

init

the initial state

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
m <- matrix(c(0.5, 0.3, 0.2,
              0.2, 0.6, 0.2,
              0.2, 0.3, 0.5), 3, byrow=TRUE)

set.seed(1)
ms <- markov_seq(n=1000, tmat=m)

colMeans(m)
prop.table(table(ms))
round(prop.table(table(head(ms, -1), tail(ms, -1), dnn=c("n", "n+1")), 1), 2)

AkselA/R-ymse documentation built on March 21, 2020, 9:52 a.m.