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.1.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Giorgio Spedicato

Last Published

September 18th, 2026

Functions in markovchain (1.1.1)

firstPassageMultiple

function to calculate first passage probabilities
name

Method to retrieve name of markovchain object
meanNumVisits

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

Check if a Markov chain is stochastically monotone
hittingProbabilities

Hitting probabilities for markovchain
meanRecurrenceTime

Mean recurrence time
kemenyConstant

Kemeny's constant of a Markov chain
firstPassage

First passage across states
is.accessible

Verify if a state j is reachable from state i.
createSequenceMatrix

Function to fit a discrete Markov chain
is.irreducible

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

Functions to fit a higher order Markov chain
freq2Generator

Returns a generator matrix corresponding to frequency matrix
markovchainList-class

Non homogeneus discrete time Markov Chains class
lump

Aggregate a Markov chain over a partition
ictmc-class

An S4 class for representing Imprecise Continuous Time Markovchains
multinomialConfidenceIntervals

A function to compute multinomial confidence intervals of DTMC
transition2Generator

Return the generator matrix for a corresponding transition matrix
tm_abs

Single Year Corporate Credit Rating Transititions
names,markovchain-method

Returns the states for a Markov chain object
markovchain-package

Easy Handling Discrete Time Markov Chains
show,hommc-method

Function to display the details of hommc object
predictHommc

Simulate a higher order multivariate markovchain
rmarkovchain

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

Example from Kullback and Kupperman Tests for Contingency Tables
markovchainListFit

markovchainListFit
markovchainSequence

Function to generate a sequence of states from homogeneous Markov chains.
preproglucacon

Preprogluccacon DNA protein bases sequences
rctmc

rctmc
markovchain-class

Markov Chain class
predictiveDistribution

predictiveDistribution
steadyStates

Stationary states of a markovchain object
period

Various function to perform structural analysis of DTMC
priorDistribution

priorDistribution
hommc-class

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

Function to fit Higher Order Multivariate Markov chain
holson

Holson data set
probabilityatT

Calculating probability from a ctmc object
states

Defined states of a transition matrix
verifyMarkovProperty

Test the first-order Markov property of an empirical sequence
is.regular

Check if a DTMC is regular
is.lumpable

Check exact lumpability of a Markov chain
rain

Alofi island daily rainfall
is.CTMCirreducible

Check if CTMC is irreducible
meanAbsorptionTime

Mean absorption time
ones

Returns an Identity matrix
noofVisitsDist

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

Mean First Passage Time for irreducible Markov chains
is.TimeReversible

checks if ctmc object is time reversible
name<-

Method to set name of markovchain object
zeros

Matrix to create zeros
transitionProbability

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

Sales Demand Sequences
committorAB

Calculates committor of a markovchain object with respect to set A, B
HigherOrderMarkovChain-class

Higher order Markov Chains class
craigsendi

CD4 cells counts on HIV Infects between zero and six month
absorptionProbabilities

Absorption probabilities
autoLump

Automatically aggregate a Markov chain by spectral clustering
ExpectedTime

Returns expected hitting time from state i to state j
autoplot.markovchain

Plot a Markov chain with ggplot2
conditionalDistribution

conditionalDistribution of a Markov Chain
entropyRate

Entropy rate of a Markov chain
expectedRewardsBeforeHittingA

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

Expected Rewards for a markovchain
impreciseProbabilityatT

Calculating full conditional probability using lower rate transition matrix
ctmcFit

Function to fit a CTMC
inferHyperparam

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

Standardize statistical inference results to R's htest convention.
ctmc-class

Continuous time Markov Chains class
blanden

Mobility between income quartiles
fundamentalMatrix

Fundamental matrix of an absorbing Markov chain
generatorToTransitionMatrix

Function to obtain the transition matrix from the generator