Learn R Programming

markovchain

R package providing classes, methods and function for easily handling Discrete Time Markov Chains (DTMC), performing probabilistic analysis and fitting.

Install the current release from CRAN:

install.packages('markovchain')

Install the development version from GitHub:

devtools::install_github('spedygiorgio/markovchain')

License and citation

The package is distributed under the MIT License, which permits commercial and non-commercial use, modification, distribution, and private use, provided the copyright notice and permission notice are retained in copies or substantial portions of the software.

If you use markovchain in published work, please cite the package as follows:

citation("markovchain")

or in bibliography form:

Spedicato, G. A. (2017). Discrete Time Markov Chains with R. The R Journal, 9(2), 84-104.

This citation is also provided in inst/CITATION.

Copy Link

Version

Install

install.packages('markovchain')

Monthly Downloads

6,308

Version

1.0.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Giorgio Spedicato

Last Published

August 25th, 2026

Functions in markovchain (1.0.0)

fitHighOrderMultivarMC

Function to fit Higher Order Multivariate Markov chain
fitHigherOrder

Functions to fit a higher order Markov chain
is.TimeReversible

checks if ctmc object is time reversible
is.accessible

Verify if a state j is reachable from state i.
hommc-class

An S4 class for representing High Order Multivariate Markovchain (HOMMC)
markovchainListFit

markovchainListFit
markovchainList-class

Non homogeneus discrete time Markov Chains class
createSequenceMatrix

Function to fit a discrete Markov chain
freq2Generator

Returns a generator matrix corresponding to frequency matrix
markovchainSequence

Function to generate a sequence of states from homogeneous Markov chains.
show,hommc-method

Function to display the details of hommc object
hittingProbabilities

Hitting probabilities for markovchain
multinomialConfidenceIntervals

A function to compute multinomial confidence intervals of DTMC
meanNumVisits

Mean num of visits for markovchain, starting at each state
is.regular

Check if a DTMC is regular
inferHyperparam

Function to infer the hyperparameters for Bayesian inference from an a priori matrix or a data set
holson

Holson data set
is.stochasticallyMonotone

Check if a Markov chain is stochastically monotone
is.CTMCirreducible

Check if CTMC is irreducible
expectedRewards

Expected Rewards for a markovchain
is.irreducible

Function to check if a Markov chain is irreducible (i.e. ergodic)
meanRecurrenceTime

Mean recurrence time
predictHommc

Simulate a higher order multivariate markovchain
preproglucacon

Preprogluccacon DNA protein bases sequences
names,markovchain-method

Returns the states for a Markov chain object
kullback

Example from Kullback and Kupperman Tests for Contingency Tables
firstPassage

First passage across states
sales

Sales Demand Sequences
name<-

Method to set name of markovchain object
predictiveDistribution

predictiveDistribution
rctmc

rctmc
transitionProbability

Function to get the transition probabilities from initial to subsequent states.
rmarkovchain

Function to generate a sequence of states from homogeneous or non-homogeneous Markov chains.
ones

Returns an Identity matrix
tm_abs

Single Year Corporate Credit Rating Transititions
probabilityatT

Calculating probability from a ctmc object
noofVisitsDist

return a joint pdf of the number of visits to the various states of the DTMC
impreciseProbabilityatT

Calculating full conditional probability using lower rate transition matrix
steadyStates

Stationary states of a markovchain object
period

Various function to perform structural analysis of DTMC
ictmc-class

An S4 class for representing Imprecise Continuous Time Markovchains
rain

Alofi island daily rainfall
zeros

Matrix to create zeros
priorDistribution

priorDistribution
markovchain-package

Easy Handling Discrete Time Markov Chains
transition2Generator

Return the generator matrix for a corresponding transition matrix
markovchain-class

Markov Chain class
meanAbsorptionTime

Mean absorption time
states

Defined states of a transition matrix
meanFirstPassageTime

Mean First Passage Time for irreducible Markov chains
verifyMarkovProperty

Test the first-order Markov property of an empirical sequence
absorptionProbabilities

Absorption probabilities
ctmc-class

Continuous time Markov Chains class
committorAB

Calculates committor of a markovchain object with respect to set A, B
conditionalDistribution

conditionalDistribution of a Markov Chain
HigherOrderMarkovChain-class

Higher order Markov Chains class
ctmcFit

Function to fit a CTMC
autoplot.markovchain

Plot a Markov chain with ggplot2
ExpectedTime

Returns expected hitting time from state i to state j
expectedRewardsBeforeHittingA

Expected first passage Rewards for a set of states in a markovchain
firstPassageMultiple

function to calculate first passage probabilities
generatorToTransitionMatrix

Function to obtain the transition matrix from the generator
craigsendi

CD4 cells counts on HIV Infects between zero and six month
.asHtest

Standardize statistical inference results to R's htest convention.
blanden

Mobility between income quartiles
name

Method to retrieve name of markovchain object