spgs (version 1.0-1)

estimateMarkovChain: Fit a first-Order Markov Chain to a Sequence of Finite Symbols

Description

Estimates the transition matrix and stationary distribution of a first-order Markov chain from an observed sequence of symbols.

Usage

estimateMarkovChain(x, circular=TRUE)

Arguments

x

The sequence of observed symbols as a character vector.

circular

Should the sequence be treated as circular for the purpose of estimation? The default is TRUE.

Value

A list with class FiniteStateMarkovChain having the following components:

trans.mat

The stochastic transition matrix estimated from x.

stat.dist

The stationary distribution estimated from x.

states

the state labels

See Also

markov.test, markov.disturbance, simulateMarkovChain

Examples

Run this code
# NOT RUN {
#Obtain a random 3 x 3 stochastic matrix with rows and columns labelled "A", "B", "C"
mat <- rstochmat(3, labels=c("A", "B", "C"))
mat

#Simulate a Markov chain of length 500 using mat as the transition matrix
seq <- simulateMarkovChain(500, mat)

#Estimate mat and the stationary distribution for the Markov chain which generated seq
estimateMarkovChain(seq)
# }

Run the code above in your browser using DataLab