rmarkov: Generate a sample of a discrete-state Markov chain

Description Usage Arguments Examples

View source: R/rmarkov.R

Description

Generates a sequence of discrete states from a discrete-time Markov chain with transition matrix P.

Usage

1
rmarkov(n, P, start = rep(1, ncol(P)))

Arguments

n

length of the generated sequence.

P

transition matrix (rows are normalized to sum to 1).

start

vector with nonnegative values that defines the discrete starting distribution at t=0 (start is normalized to sum to 1). The default is a discrete uniform distribution.

Examples

1
2
3
4
P <- matrix(c(.30, .50, .20,
              .05, .25, .70,
              .00, .10, .90), 3, 3, byrow=TRUE)
rmarkov(50, P)

Example output

 [1] 1 2 3 3 3 3 2 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3
[39] 3 3 3 3 3 2 2 3 3 3 3 3

MCMCprecision documentation built on Dec. 5, 2019, 9:08 a.m.