Learn R Programming

markovchain (version 0.0.9.5)

markovchainFit: Function to fit a discrete Markov chain

Description

Given a sequence of states arising from a stationary state, it fits the underlying Markov chain distribution using either MLE (also using a Laplacian smoother) or bootstrap.

Usage

markovchainFit(data, method = "mle", byrow = TRUE, nboot = 10,laplacian=0,name, 
parallel=FALSE)
createSequenceMatrix(stringchar, toRowProbs = FALSE, sanitize = TRUE)

Arguments

data
A character list.
method
Method used to estimate the Markov chain. Either "mle" or "bootstrap" or "laplace"
byrow
it tells whether the output Markov chain should show the transition probabilities by row.
nboot
Number of bootstrap replicates in case "bootstrap" is used.
laplacian
Laplacian smoothing parameter, default zero. It is only used when "laplace" method is chosen.
name
Optional character for name slot.
parallel
Use parallel processing when performing Boostrap estimates.
stringchar
Equivalent to data
toRowProbs
converts a sequence matrix into a probability matrix
sanitize
put 1 in all rows having rowSum equal to zero

Value

  • A list containing an estimate and, when "bootstrap" method is used, a matrix of standards deviations and the bootstrap samples.

Warning

"mle" method calls createSequenceMatrix function using sanitize parameter set to TRUE.

References

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

See Also

markovchainSequence

Examples

Run this code
sequence<-c("a", "b", "a", "a", "a", "a", "b", "a", "b", "a", "b", "a", "a", 
"b", "b", "b", "a")
sequenceMatr<-createSequenceMatrix(sequence,sanitize=FALSE)
mcFitMLE<-markovchainFit(data=sequence)
mcFitBSP<-markovchainFit(data=sequence,method="bootstrap",nboot=5, name="Bootstrap Mc")

Run the code above in your browser using DataLab