Package: markovchain 1.2.1

Giorgio Alfredo Spedicato

markovchain: Easy Handling Discrete Time Markov Chains

Functions and S4 classes to create, manage and analyse discrete time Markov chains. Includes probabilistic analysis of chain structure (state classification, hitting times, stationary distributions, spectral and mixing diagnostics), statistical inference (maximum likelihood and Bayesian estimation, tests of the Markov property, homogeneity, stationarity and order, simulation), higher-order and multivariate chains, state aggregation, and import/export to JSON, YAML and CSV. Basic support for continuous time Markov chains is also provided; some of these functions depend on the suggested 'ctmcd' package. See Spedicato (2017) <doi:10.32614/RJ-2017-036>.

Authors:Giorgio Alfredo Spedicato [aut, cre], Tae Seung Kang [aut], Sai Bhargav Yalamanchi [aut], Mildenberger Thoralf [ctb], Deepak Yadav [aut], Ignacio Cordón [aut], Vandit Jain [ctb], Toni Giorgino [ctb], Richèl J.C. Bilderbeek [ctb], Daniel Ebbert [ctb], Shreyash Maheshwari [ctb], Reinhold Koch [ctb]

markovchain_1.2.1.tar.gz
markovchain_1.2.1.zip(r-4.7-x86_64)markovchain_1.2.1.zip(r-4.7-arm64)markovchain_1.2.1.zip(r-4.6-x86_64)markovchain_1.2.1.zip(r-4.6-arm64)markovchain_1.2.1.zip(r-4.5-x86_64)
markovchain_1.2.1.tgz(r-4.6-x86_64)markovchain_1.2.1.tgz(r-4.6-arm64)markovchain_1.2.1.tgz(r-4.5-x86_64)markovchain_1.2.1.tgz(r-4.5-arm64)
markovchain_1.2.1.tar.gz(r-4.7-arm64)markovchain_1.2.1.tar.gz(r-4.7-x86_64)markovchain_1.2.1.tar.gz(r-4.6-arm64)markovchain_1.2.1.tar.gz(r-4.6-x86_64)
markovchain_1.2.1.tgz(r-4.6-emscripten)
manual.pdf |manual.html✨
DESCRIPTION |NEWS
card.svg |card.png
markovchain/json (API)

# Install 'markovchain' in R:
install.packages('markovchain', repos = c('https://spedygiorgio.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/spedygiorgio/markovchain/issues

Uses libs:
  • openblas– Optimized BLAS
  • c++– GNU Standard C++ Library v3
Datasets:
  • blanden - Mobility between income quartiles
  • craigsendi - CD4 cells counts on HIV Infects between zero and six month
  • holson - Holson data set
  • kullback - Example from Kullback and Kupperman Tests for Contingency Tables
  • preproglucacon - Preprogluccacon DNA protein bases sequences
  • rain - Alofi island daily rainfall
  • sales - Sales Demand Sequences
  • tm_abs - Single Year Corporate Credit Rating Transititions

On CRAN:

Conda:

ctmcdtmcmarkov-chainmarkov-modelr-programmingrcppquartoopenblascpp

11.31 score 117 stars 4 packages 7.2k downloads 9 mentions 120 exports 15 dependencies

Last updated from:42ce47425f. Checks:13 OK, 2 ERROR. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-arm64OK309
linux-devel-x86_64OK326
source / vignettesOK356
linux-release-arm64OK297
linux-release-x86_64OK296
macos-release-arm64OK339
macos-release-x86_64OK585
macos-oldrel-arm64OK359
macos-oldrel-x86_64OK659
windows-devel-arm64ERROR454
windows-devel-x86_64OK407
windows-release-arm64ERROR495
windows-release-x86_64OK627
windows-oldrel-x86_64OK559
wasm-releaseOK199

Exports:.markovchainFitRcppabsorbingStatesabsorptionProbabilitiesaggregateStatesassessIndependenceassessOrderassessStationarityautoLumpbirthDeathbootstrapPropertiescanonicFormclosestReversiblecoercecommittorABcommunicatingClassescompareChainsconditionalDistributioncreateSequenceMatrixctmcFitdirichletChaindivergenceRateentropyRateexpectedRewardsexpectedRewardsBeforeHittingAExpectedTimefirstPassagefirstPassageMultiplefitFunctionfitHigherOrderfitHighOrderMultivarMCfitMTDfreq2GeneratorfromDictionaryfromFilefundamentalMatrixgamblersRuingeneratorToTransitionMatrixhigherOrderLogLikhigherOrderPredicthigherOrderSimulatehittingProbabilitieshommcidentityChainimpliedTimescalesimpreciseProbabilityatTinferHyperparamis.accessibleis.CTMCirreducibleis.irreducibleis.lumpableis.regularis.reversibleis.stochasticallyMonotoneis.TimeReversiblekemenyConstantlazyChainlumpmarkovchainFitmarkovchainListFitmarkovchainSequencemeanAbsorptionTimemeanFirstPassageTimemeanNumVisitsmeanRecurrenceTimemergeWithmixingTimemultinomialConfidenceIntervalsnamename<-noofVisitsDistnormalizedEntropyRateperiodplotplotSequencepopulationGeneticsModelpredictpredictHommcpredictiveDistributionprintpriorDistributionprobabilityatTrandomMarkovChainrctmcrecurrentClassesrecurrentStatesredistributerelaxationTimermarkovchainrouwenhorstselectOrdersensitivityseq2freqProbseq2matHighshowslemspectralGapstatessteadyStatessubchainsummaryttauchentauchenHusseytimeCorrelationstimeRelaxationstoBoundedChaintoDictionarytoDottoFiletoMermaidtoNthOrdertopologicalEntropytransientClassestransientStatestransition2GeneratortransitionProbabilityurnModelverifyEmpiricalToTheoreticalverifyHomogeneityverifyMarkovProperty

Dependencies:clicpp11expmglueigraphlatticelifecyclemagrittrMatrixpkgconfigRcppRcppArmadilloRcppParallelrlangvctrs

The markovchain Package: A Package for Easily Handling Discrete Markov Chains in R
Introduction | Review of core mathematical concepts | General Definitions | Properties and classification of states | A short example | The structure of the package | Creating markovchain objects | Handling markovchain objects | Probability with markovchain objects | Conditional distributions | Stationary states | Entropy rate | Topological entropy and normalized entropy rate | Classification of states | First passage time distributions and means | Kemeny's constant | Sensitivity of the stationary distribution | Spectral diagnostics: SLEM, spectral gap and implied timescales | Reversibility | Closest reversible approximation | Mixing time | Lazy chains | Evolution of a distribution | Mean recurrence time | Absorption probabilities and mean absorption time | Fundamental matrix | Restricting a chain to a subset of states | Committor probability | Hitting probabilities | Stochastic monotonicity | Classical Markov chain constructors | Birth-death chains | The Ehrenfest urn model | Combining two chains | The n-step chain | Population genetics: the Moran and Wright-Fisher models | Random and special chains | Statistical analysis | Simulation | Plotting sequences | Lumpability and aggregation of states | Spectral Kullback-Leibler aggregation | Serialization and export | Estimation | Uncertainty of derived properties | Prediction | Predicting from a markovchain object | Predicting from a markovchainList object | Statistical tests | Assessing the independence of consecutive states | Assessing the Markov property of a Markov chain sequence | Assessing the order of a Markov chain sequence | Assessing the stationarity and time-homogeneity of a Markov chain sequence | Divergence tests for empirically estimated transition matrices | Distances and divergences between two chains | Pseudo-Bayesian estimation | Bayesian estimation | Notation and set-up | Methods | Predictive distribution | Choosing the hyper-parameters | Usage and examples | Continuous time Markov chains | Definition and generator matrix | Stationary distributions | Estimation of the generator matrix | Expected hitting time | Transition probabilities over time | Examples | Applications | Weather forecasting | Land of Oz | Alofi Island Rainfall | Finance and Economics | Finance | Economics | Discretizing autoregressive processes | Quadrature-based discretizations | Actuarial science | MTPL Bonus Malus | Health insurance example | Sociology | Genetics and Medicine | Genetics | Medicine | Discussion, issues and future plans | Acknowledgments | References

Last update: 2026-11-01
Started: 2018-12-31

Higher order Markov chains
Higher order Markov chains as mixtures of lags | Comparing models of different orders | Selecting the order of a full Markov chain | Reproducing a published comparison | The mixture transition distribution model | Standard errors | Negative weights | The MTDg model | Faster convergence | Prediction and simulation | Higher order multivariate Markov chains | Introduction | Representation of parameters in the code | Definition of HOMMC class | How to create an object of class HOMMC | Fit HOMMC | A marketing example | Acknowledgments | References

Last update: 2026-11-01
Started: 2026-08-15

Google Summer of Code 2017 Additions
Expected hitting time of a CTMC | Probability at time t of a CTMC | Plotting the generator matrix of a CTMC | Imprecise continuous time Markov chains | Types of ICTMCs | Lower Transition Rate Operators for ICTMCs | Lower Transition Operators | The impreciseProbabilityatT function | Generator of a CTMC from a frequency matrix | Committor of a Markov chain | First passage probability for a set of states | Mean occupation of the states during the first N steps | Expected rewards of a Markov chain | Expected rewards before hitting a set of states | Irreducibility of a CTMC | Simulation of higher order multivariate Markov chains | Time reversibility of a CTMC | References

Last update: 2026-10-08
Started: 2026-08-15

Readme and manuals

Help Manual

Help pageTopics
Easy Handling Discrete Time Markov Chainsmarkovchain-package markovchain
Absorption probabilitiesabsorptionProbabilities
Aggregate a Markov chain's state space by Kullback-Leibler minimizationaggregateStates aggregateStates,markovchain-method
Test independence of consecutive states of an empirical sequenceassessIndependence
Aggregate a Markov chain by spectral clusteringautoLump autoLump,markovchain-method
Plot a Markov chain with ggplot2autoplot.markovchain
Build a birth-death Markov chainbirthDeath
Mobility between income quartilesblanden
Bootstrap confidence intervals for properties of an estimated chainbootstrapProperties
Closest reversible approximation of a Markov chainclosestReversible closestReversible,markovchain-method
Committor probabilitiescommittorAB
Compare two Markov chainscompareChains
Conditional distribution of the next stateconditionalDistribution
CD4 cells counts on HIV Infects between zero and six monthcraigsendi
Continuous time Markov chain classctmc-class dim,ctmc-method initialize,ctmc_method plot,ctmc,missing-method states,ctmc-method steadyStates,ctmc-method
Fit a continuous time Markov chainctmcFit
Markov chain from a Dirichlet processdirichletChain
Kullback-Leibler divergence rate between two Markov chainsdivergenceRate
Entropy rate of a Markov chainentropyRate entropyRate,markovchain-method
Expected cumulative reward of a Markov chainexpectedRewards
Expected reward collected before hitting a set of statesexpectedRewardsBeforeHittingA
Expected hitting time of a state in a continuous time Markov chainExpectedTime
First passage time distributionfirstPassage
First passage time distribution of a set of statesfirstPassageMultiple
Markov chain approximating a continuous transition kernel by quadraturefitFunction
Fit a higher order Markov chainfitHigherOrder seq2freqProb seq2matHigh
Fit a higher order multivariate Markov chainfitHighOrderMultivarMC
Fit a mixture transition distribution (MTD) modelfitMTD
Generator matrix estimated from a matrix of transition frequenciesfreq2Generator
Fundamental matrix of an absorbing Markov chainfundamentalMatrix
Build a gambler's ruin Markov chaingamblersRuin
Transition matrix of the embedded jump chaingeneratorToTransitionMatrix
Log-likelihood, deviance and information criteria of a higher order Markov chainhigherOrderLogLik
Higher order Markov Chains classHigherOrderMarkovChain-class
Next-state probabilities and simulation for higher order Markov chainshigherOrderPredict higherOrderSimulate
Hitting probabilities of a Markov chainhittingProbabilities
Holson data setholson
Higher order multivariate Markov chain classhommc hommc-class
An S4 class for representing Imprecise Continuous Time Markovchainsictmc ictmc-class
Identity Markov chainidentityChain
Implied timescales of a Markov chainimpliedTimescales impliedTimescales,markovchain-method
Lower transition probability of an imprecise continuous time Markov chainimpreciseProbabilityatT
Hyperparameters for Bayesian estimation of a Markov chaininferHyperparam
Check whether a state can be reached from anotheris.accessible
Check whether a continuous time Markov chain is irreducibleis.CTMCirreducible
Check whether a Markov chain is irreducibleis.irreducible
Check exact lumpability of a Markov chainis.lumpable is.lumpable,markovchain-method
Check if a DTMC is regularis.regular
Check whether a Markov chain is reversibleis.reversible is.reversible,markovchain-method
Check whether a Markov chain is stochastically monotoneis.stochasticallyMonotone is.stochasticallyMonotone,ANY-method is.stochasticallyMonotone,markovchain-method is.stochasticallyMonotone,matrix-method
Check whether a continuous time Markov chain is time reversibleis.TimeReversible
Kemeny's constant of a Markov chainkemenyConstant kemenyConstant,markovchain-method
Example from Kullback and Kupperman Tests for Contingency Tableskullback
Build a lazy version of a Markov chainlazyChain lazyChain,markovchain-method
Aggregate a Markov chain over a partitionlump lump,markovchain-method
Markov Chain class!=,markovchain,markovchain-method *,markovchain,markovchain-method *,markovchain,matrix-method *,markovchain,numeric-method *,matrix,markovchain-method *,numeric,markovchain-method ==,markovchain,markovchain-method absorbingStates,markovchain-method absorptionProbabilities,markovchain-method canonicForm,markovchain-method coerce,data.frame,markovchain-method coerce,etm,markovchain-method coerce,markovchain,data.frame-method coerce,markovchain,igraph-method coerce,markovchain,matrix-method coerce,markovchain,sparseMatrix-method coerce,Matrix,markovchain-method coerce,matrix,markovchain-method coerce,msm,markovchain-method coerce,msm.est,markovchain-method coerce,sparseMatrix,markovchain-method coerce,table,markovchain-method communicatingClasses,markovchain-method conditionalDistribution,markovchain-method dim,markovchain-method hittingProbabilities,markovchain-method initialize,markovchain-method is.accessible,markovchain,character,character-method is.accessible,markovchain,missing,missing-method is.irreducible,markovchain-method is.regular,markovchain-method markovchain-class meanAbsorptionTime,markovchain-method meanFirstPassageTime,markovchain,character-method meanFirstPassageTime,markovchain,missing-method meanNumVisits,markovchain-method meanRecurrenceTime,markovchain-method names<-,markovchain-method plot,markovchain,missing-method predict,markovchain-method print,markovchain-method recurrentClasses,markovchain-method recurrentStates,markovchain-method show,markovchain-method sort,markovchain-method steadyStates,markovchain-method summary,markovchain-method t,markovchain-method transientClasses,markovchain-method transientStates,markovchain-method [,markovchain,ANY,ANY,ANY-method ^,markovchain,numeric-method
Session cache of eigenvaluesmarkovchainCache
Fit a discrete time Markov chain.markovchainFitRcpp createSequenceMatrix markovchainFit
Non-homogeneous discrete time Markov chain classdim,markovchainList-method markovchainList-class predict,markovchainList-method print,markovchainList-method show,markovchainList-method [[,markovchainList-method
Fit a non-homogeneous Markov chainmarkovchainListFit
Simulate a trajectory of a Markov chainmarkovchainSequence
Mean absorption timemeanAbsorptionTime
Mean first passage times of an irreducible Markov chainmeanFirstPassageTime
Mean number of visits to each statemeanNumVisits
Mean recurrence timemeanRecurrenceTime
Merge two Markov chains by convex combination of their transition matricesmergeWith mergeWith,markovchain,markovchain-method
Mixing time of a Markov chainmixingTime mixingTime,markovchain-method
Simultaneous confidence intervals for transition probabilitiesmultinomialConfidenceIntervals
Name of a Markov chainname name,markovchain-method
Set the name of a Markov chainname<- name<-,markovchain-method
Returns the states for a Markov chain objectnames,markovchain-method
Expected fraction of the first N steps spent in each statenoofVisitsDist
Normalized entropy rate of a Markov chainnormalizedEntropyRate normalizedEntropyRate,markovchain-method
Returns an Identity matrixones
Structural analysis of a Markov chainabsorbingStates canonicForm communicatingClasses period recurrentClasses recurrentStates transientClasses transientStates
Plot state sequences of a Markov chainplotSequence
Build a population-genetics Markov chain (Moran or Wright-Fisher)populationGeneticsModel
Simulate from a higher order multivariate Markov chainpredictHommc
Bayesian predictive probability of new datapredictiveDistribution
Preprogluccacon DNA protein bases sequencespreproglucacon
Prior density of a transition matrixpriorDistribution
Transition probabilities of a continuous time Markov chain at time tprobabilityatT
Alofi island daily rainfallrain
Random Markov chainrandomMarkovChain
Simulate a continuous time Markov chainrctmc
Evolution of a distribution over timeredistribute redistribute,markovchain-method
Relaxation time of a Markov chainrelaxationTime relaxationTime,markovchain-method
Simulate from a homogeneous or non-homogeneous Markov chainrmarkovchain
Discretize an AR(1) process into a Markov chain (Rouwenhorst's method)rouwenhorst
Sales Demand Sequencessales
Select the order of a Markov chain by information criteriaselectOrder
Sensitivity of the stationary distribution to a state's transition rowsensitivity sensitivity,markovchain-method
Function to display the details of hommc objectshow,hommc-method
Second largest eigenvalue modulus (SLEM) of a Markov chainslem slem,markovchain-method
Spectral gap of a Markov chainspectralGap spectralGap,markovchain-method
States of a Markov chainstates states,markovchain-method
Statistical tests for Markov chainsassessOrder assessStationarity statisticalTests verifyEmpiricalToTheoretical verifyHomogeneity verifyMarkovProperty
Stationary distributions of a Markov chainsteadyStates
Restrict a Markov chain to a subset of statessubchain subchain,markovchain-method
Discretize an AR(1) process into a Markov chain (Tauchen's method)tauchen
Discretize an AR(1) process into a Markov chain (Tauchen-Hussey method)tauchenHussey
Time correlations and time relaxations of observed sequencestimeCorrelations timeCorrelations,markovchain-method timeRelaxations timeRelaxations,markovchain-method
Single Year Corporate Credit Rating Transititionstm_abs
Apply a boundary condition to a Markov chain's first and last statetoBoundedChain toBoundedChain,markovchain-method
Represent a Markov chain as a plain R listfromDictionary toDictionary toDictionary,markovchain-method
Export the transition graph as Graphviz DOT or Mermaid texttoDot toDot,markovchain-method toMermaid toMermaid,markovchain-method
Write or read a Markov chain to or from a filefromFile toFile toFile,markovchain-method
Return the n-step transition chaintoNthOrder
Topological entropy of a Markov chaintopologicalEntropy topologicalEntropy,markovchain-method
Generator matrix from a transition matrixtransition2Generator
Transition probability between two statestransitionProbability transitionProbability,markovchain-method
Build an Ehrenfest urn model Markov chainurnModel
Matrix to create zeroszeros