Package: markovchain 1.2

Giorgio Alfredo Spedicato

markovchain: Easy Handling Discrete Time Markov Chains

Description: 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.tar.gz
markovchain_1.2.zip(r-4.7-x86_64)markovchain_1.2.zip(r-4.7-arm64)markovchain_1.2.zip(r-4.6-x86_64)markovchain_1.2.zip(r-4.6-arm64)markovchain_1.2.zip(r-4.5-x86_64)
markovchain_1.2.tgz(r-4.6-x86_64)markovchain_1.2.tgz(r-4.6-arm64)markovchain_1.2.tgz(r-4.5-x86_64)markovchain_1.2.tgz(r-4.5-arm64)
markovchain_1.2.tar.gz(r-4.7-arm64)markovchain_1.2.tar.gz(r-4.7-x86_64)markovchain_1.2.tar.gz(r-4.6-arm64)markovchain_1.2.tar.gz(r-4.6-x86_64)
markovchain_1.2.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

13.28 score 116 stars 4 packages 898 scripts 9.0k downloads 9 mentions 114 exports 15 dependencies

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

TargetResultTimeFilesSyslog
linux-devel-arm64OK218
linux-devel-x86_64OK273
source / vignettesOK365
linux-release-arm64OK257
linux-release-x86_64OK256
macos-release-arm64OK255
macos-release-x86_64OK630
macos-oldrel-arm64OK279
macos-oldrel-x86_64OK353
windows-devel-arm64ERROR473
windows-devel-x86_64OK295
windows-release-arm64ERROR451
windows-release-x86_64OK294
windows-oldrel-x86_64OK283
wasm-releaseOK127

Exports:.markovchainFitRcppabsorbingStatesabsorptionProbabilitiesaggregateStatesassessIndependenceassessOrderassessStationarityautoLumpbirthDeathcanonicFormclosestReversiblecoercecommittorABcommunicatingClassesconditionalDistributioncreateSequenceMatrixctmcFitdirichletChainentropyRateexpectedRewardsexpectedRewardsBeforeHittingAExpectedTimefirstPassagefirstPassageMultiplefitHigherOrderfitHighOrderMultivarMCfitMTDfreq2GeneratorfromDictionaryfromFilefundamentalMatrixgamblersRuingeneratorToTransitionMatrixhigherOrderLogLikhigherOrderPredicthigherOrderSimulatehittingProbabilitieshommcidentityChainimpliedTimescalesimpreciseProbabilityatTinferHyperparamis.accessibleis.CTMCirreducibleis.irreducibleis.lumpableis.regularis.reversibleis.stochasticallyMonotoneis.TimeReversiblekemenyConstantlazyChainlumpmarkovchainFitmarkovchainListFitmarkovchainSequencemeanAbsorptionTimemeanFirstPassageTimemeanNumVisitsmeanRecurrenceTimemergeWithmixingTimemultinomialConfidenceIntervalsnamename<-noofVisitsDistnormalizedEntropyRateperiodplotpopulationGeneticsModelpredictpredictHommcpredictiveDistributionprintpriorDistributionprobabilityatTrandomMarkovChainrctmcrecurrentClassesrecurrentStatesredistributerelaxationTimermarkovchainrouwenhorstselectOrdersensitivityseq2freqProbseq2matHighshowslemspectralGapstatessteadyStatessubchainsummaryttauchentimeCorrelationstimeRelaxationstoBoundedChaintoDictionarytoDottoFiletoMermaidtoNthOrdertopologicalEntropytransientClassestransientStatestransition2GeneratortransitionProbabilityurnModelverifyEmpiricalToTheoreticalverifyHomogeneityverifyMarkovProperty

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 | Lumpability and aggregation of states | Spectral Kullback-Leibler aggregation | Serialization and export | Estimation | 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 | 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 | Actuarial science | MTPL Bonus Malus | Health insurance example | Sociology | Genetics and Medicine | Genetics | Medicine | Discussion, issues and future plans | Acknowledgments | References

Last update: 2026-10-08
Started: 2018-12-31

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

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 | 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-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
Automatically 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
Closest reversible approximation of a Markov chainclosestReversible closestReversible,markovchain-method
Calculates committor of a markovchain object with respect to set A, BcommittorAB
'conditionalDistribution' of a Markov ChainconditionalDistribution
CD4 cells counts on HIV Infects between zero and six monthcraigsendi
Continuous time Markov Chains classctmc-class dim,ctmc-method initialize,ctmc_method plot,ctmc,missing-method states,ctmc-method steadyStates,ctmc-method
Function to fit a CTMCctmcFit
Markov chain from a Dirichlet processdirichletChain
Entropy rate of a Markov chainentropyRate entropyRate,markovchain-method
Expected Rewards for a markovchainexpectedRewards
Expected first passage Rewards for a set of states in a markovchainexpectedRewardsBeforeHittingA
Returns expected hitting time from state i to state jExpectedTime
First passage across statesfirstPassage
function to calculate first passage probabilitiesfirstPassageMultiple
Functions to fit a higher order Markov chainfitHigherOrder seq2freqProb seq2matHigh
Function to fit Higher Order Multivariate Markov chainfitHighOrderMultivarMC
Fit a mixture transition distribution (MTD) modelfitMTD
Returns a generator matrix corresponding to frequency matrixfreq2Generator
Fundamental matrix of an absorbing Markov chainfundamentalMatrix
Build a gambler's ruin Markov chaingamblersRuin
Function to obtain the transition matrix from the generatorgeneratorToTransitionMatrix
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 for markovchainhittingProbabilities
Holson data setholson
An S4 class for representing High Order Multivariate Markovchain (HOMMC)hommc 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
Calculating full conditional probability using lower rate transition matriximpreciseProbabilityatT
Function to infer the hyperparameters for Bayesian inference from an a priori matrix or a data setinferHyperparam
Verify if a state j is reachable from state i.is.accessible
Check if CTMC is irreducibleis.CTMCirreducible
Function to check if a Markov chain is irreducible (i.e. ergodic)is.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 if a Markov chain is stochastically monotoneis.stochasticallyMonotone is.stochasticallyMonotone,ANY-method is.stochasticallyMonotone,markovchain-method is.stochasticallyMonotone,matrix-method
checks if ctmc object 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
Function to fit a discrete Markov chain.markovchainFitRcpp createSequenceMatrix markovchainFit
Non homogeneus discrete time Markov Chains classdim,markovchainList-method markovchainList-class predict,markovchainList-method print,markovchainList-method show,markovchainList-method [[,markovchainList-method
markovchainListFitmarkovchainListFit
Function to generate a sequence of states from homogeneous Markov chains.markovchainSequence
Mean absorption timemeanAbsorptionTime
Mean First Passage Time for irreducible Markov chainsmeanFirstPassageTime
Mean num of visits for markovchain, starting at 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
A function to compute multinomial confidence intervals of DTMCmultinomialConfidenceIntervals
Method to retrieve name of markovchain objectname name,markovchain-method
Method to set name of markovchain objectname<- 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
Various function to perform structural analysis of DTMCabsorbingStates canonicForm communicatingClasses period recurrentClasses recurrentStates transientClasses transientStates
Build a population-genetics Markov chain (Moran or Wright-Fisher)populationGeneticsModel
Simulate a higher order multivariate markovchainpredictHommc
predictiveDistributionpredictiveDistribution
Preprogluccacon DNA protein bases sequencespreproglucacon
priorDistributionpriorDistribution
Calculating probability from a ctmc objectprobabilityatT
Alofi island daily rainfallrain
Random Markov chainrandomMarkovChain
rctmcrctmc
Evolution of a distribution over timeredistribute redistribute,markovchain-method
Relaxation time of a Markov chainrelaxationTime relaxationTime,markovchain-method
Function to generate a sequence of states from homogeneous or non-homogeneous Markov chains.rmarkovchain
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
Defined states of a transition matrixstates states,markovchain-method
Stationary states of a 'markovchain' objectsteadyStates
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
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
Return the generator matrix for a corresponding transition matrixtransition2Generator
Function to get the transition probabilities from initial to subsequent states.transitionProbability transitionProbability,markovchain-method
Build an Ehrenfest urn model Markov chainurnModel
Test the first-order Markov property of an empirical sequenceassessOrder assessStationarity verifyEmpiricalToTheoretical verifyHomogeneity verifyMarkovProperty
Matrix to create zeroszeros