Learn R Programming

Semi Markov Model

Description

Performs parametric and non-parametric estimation and simulation for multi-state discrete-time semi-Markov processes.

For the parametric estimation, several discrete distributions are considered for the sojourn times:

  • Uniform,
  • Geometric,
  • Poisson,
  • Discrete Weibull,
  • Negative Binomial.

The non-parametric estimation concerns the sojourn time distributions, where no assumptions are done on the shape of distributions. Moreover, the estimation can be done on the basis of one or several sample paths, with or without censoring at the beginning or/and at the end of the sample paths.

Reliability indicators such as reliability, maintainability, availability, BMP-failure rate, RG-failure rate, mean time to failure and mean time to repair are available as well.

The implemented methods are described in:

  • Barbu, V. S., & Limnios, N. (2009). Semi-Markov chains and hidden semi-Markov models toward applications: their use in reliability and DNA analysis (Vol. 191). Springer Science & Business Media. doi:10.1007/978-0-387-73173-5. (Journal version)

  • Barbu, V., & Limnios, N. (2006). Empirical estimation for discrete-time semi-Markov processes with applications in reliability. Nonparametric Statistics, 18(7-8), 483-498. doi:10.1080/10485250701261913. (Journal version)

  • Trevezas, S., & Limnios, N. (2011). Exact MLE and asymptotic properties for nonparametric semi-Markov models. Journal of Nonparametric Statistics, 23(3), 719-739. doi:10.1080/10485252.2011.555543. (Journal version)

Estimation and simulation of discrete-time k-th order Markov chains are also considered.

Install

  • Install from CRAN:
install.packages('smmR')
  • Install latest development version from git:
if (!require("devtools")) {
  install.packages("devtools")
}
devtools::install_git(
  url = "https://plmlab.math.cnrs.fr/lmrs/statistique/smmR",
  dependencies = TRUE,
  build_vignettes = FALSE)

Quickstart

library(smmR)

To create an object smmparametric, we need several pieces of information:

  • a state space (here states)
  • an initial distribution (here alpha)
  • a transition matrix (here p)
  • a distribution matrix stating the laws (here dist)
  • parameters for each state
states <- c("a", "b", "c") # state space

alpha <- c(1, 0, 0) # initial distribution

We define the transition matrix p and the distribution matrix dist (see here for details):

p <- matrix(data = c(0.0, 0.5, 0.5,
                     1.0, 0.0, 0.0,
                     1.0, 0.0, 0.0),
            nrow = 3, ncol = 3, byrow = TRUE)

distr <- matrix(c(NA, "geom", "geom", 
                  "geom", NA, NA,
                  "geom", NA, NA), 
                nrow = 3, ncol = 3, byrow = TRUE) # Distribution matrix

There is only one parameter for the geometrical law:

parameters <- array(c( NA, 0.8, 0.8,
                       0.3,  NA,  NA,
                       0.5,  NA,  NA,
                       NA,  NA,  NA,
                       NA,  NA,  NA,
                       NA,  NA,  NA), 
                    c(3, 3, 2))

Finally, we create our object smmparametric:

mysmmparam <- smmparametric(states = states, init = alpha, ptrans = p, 
                         type.sojourn = "fij", distr = distr, param = parameters)

From this smmparametric object, we can simulate sequences:

M <- 10000
seq <- simulate(object = mysmmparam, nsim = M)

And we can fit another model, here a smmnonparametric object:

estimate <- fitsmm(sequences = seq, states = states, type.sojourn = "fij")

You can find an application to reliability here.

Contributing

Contributions to this package are warmly welcome. Do not hesitate to open an issue to discuss new features.

The official repository is at PLMLab. But to help with issues and contributions, a mirror has been setup at Github.

If you want to contribute to the code, you can fork the repository, make some changes and create a pull request to have them integrated into the package. You can use the devtools::check() function in order to verify that tests are still passing. See also the contributing guidelines.

If you encounter a problem, open a new issue. Try to be concise and explain what the problem is. If you have an example code that shows the error, it can be helpful.

Acknowledgements

We acknowledge the project AStERiCs Apprentissage Statistique à l'Echelle pour la Représentation et la Classification non-supervisées (RIN project funded by the Normandy Region), DAISI on Biomedical Data Classification (co-financed by the European Union with the European Regional Development Fund (ERDF) and by the Normandy Region).

Copy Link

Version

Install

install.packages('smmR')

Monthly Downloads

276

Version

1.0.5

License

GPL-3

Maintainer

Nicolas Vergne

Last Published

November 7th, 2025

Functions in smmR (1.0.5)

get.stationaryDistribution

Method to get the stationary distribution
get.qy

Method to get the semi-Markov kernel \(q_{Y}\)
get.Py

Method to compute the value of \(P_{Y}\)
meanRecurrenceTimes

Method to get the mean recurrence times \(\mu\)
is.smmnonparametric

Function to check if an object is of class smmnonparametric
get.f

Method to get the conditional sojourn time distribution f
get.limitDistribution

Method to get the limit (stationary) distribution
matrixConvolution

Discrete-time matrix convolution product (See definition 3.5 p. 48)
is.smmparametric

Function to check if an object is of class smmparametric
get.psi

Function to compute the value of the matrix-valued function \(\psi\)
maintainability

Maintainability Function
mttf

Mean Time To Failure (MTTF) Function
mm

Markov model specification
is.smm

Function to check if an object is of class smm
is.smmfit

Function to check if an object is of class smmfit
plot.smmfit

Plot function for an object of class smmfit
reliability

Reliability Function
simulate.smm

Simulates semi-Markov chains
simulate.mmfit

Simulates Markov chains
plot.smm

Plot function for an object of class smm
meanSojournTimes

Mean Sojourn Times Function
mttr

Mean Time To Repair (MTTR) Function
smmR-package

smmR : Semi-Markov Models, Markov Models and Reliability
simulate.smmfit

Simulates semi-Markov chains
simulate.mm

Simulates k-th order Markov chains
smmparametric

Parametric semi-Markov model specification
setSeed

Set the RNG Seed from within Rcpp
smmnonparametric

Non-parametric semi-Markov model specification
get.H

Function to compute the value of the sojourn time cumulative distribution \(H\)
convolution

Discrete-time convolution product of \(f\) and \(g\) (See definition 2.2 p. 20)
fitmm

Maximum Likelihood Estimation (MLE) of a k-th order Markov chain
failureRate

Failure Rate Function
fitsmm

Maximum Likelihood Estimation (MLE) of a semi-Markov chain
get.P

Method to compute the value of \(P\)
get.Kpar

Method to get the number of parameters of a Markov or semi-Markov chain
get.Niuj

Function giving the value of the counting process Niuj used in the estimation of the kernel and the transition matrix of censored and non-parametric semi-markov chains (cf. article Exact MLE and asymptotic properties for nonparametric semi-Markov models)
.failureRateBMP

BMP-Failure Rate Function
availability

Availability Function
getProcesses

Function to compute processes based on a list of sequences
getKernel

Method to get the semi-Markov kernel \(q\)
is.mm

Function to check if an object is of class mm
is.mmfit

Function to check if an object is of class mmfit