Package 'smmR'

Title: Simulation, Estimation and Reliability of Semi-Markov Models
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 and 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. (2008) <doi:10.1007/978-0-387-73173-5>, Barbu, V.S., Limnios, N. (2006) <doi:10.1080/10485250701261913> and Trevezas, S., Limnios, N. (2011) <doi:10.1080/10485252.2011.555543>. Estimation and simulation of discrete-time k-th order Markov chains are also considered.
Authors: Vlad Stefan Barbu [aut] (ORCID: <https://orcid.org/0000-0002-0840-016X>), Florian Lecocq [aut], Corentin Lothode [aut] (ORCID: <https://orcid.org/0000-0002-8209-317X>), Nicolas Vergne [aut, cre] (ORCID: <https://orcid.org/0000-0001-5757-074X>)
Maintainer: Nicolas Vergne <[email protected]>
License: GPL-3
Version: 1.0.7.9000
Built: 2026-12-02 00:55:11 UTC
Source: https://github.com/nicolasv-dev/smmr

Help Index


smmR : Semi-Markov Models, Markov Models and Reliability

Description

This package 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 and 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. Estimation and simulation of discrete-time k-th order Markov chains are also considered.

Semi-Markov models are specified by using the functions smmparametric() and smmnonparametric() for parametric and non-parametric specifications respectively. These functions return objects of S3 class (smm, smmparametric) and (smm, smmnonparametric) respectively (smm class inherits from S3 classes smmparametric or smmnonparametric). Thus, smm is like a wrapper class for semi-Markov model specifications.

Based on a model specification (an object of class smm), it is possible to:

  • simulate one or several sequences with the method simulate.smm();

  • plot conditional sojourn time distributions (method plot.smm());

  • compute log-likelihood, AIC and BIC criteria (methods logLik(), AIC(), BIC());

  • compute reliability, maintainability, availability, failure rates (methods reliability(), maintainability(), availability(), failureRate()).

Estimations of parametric and non-parametric semi-Markov models can be done by using the function fitsmm(). This function returns an object of S3 class smmfit. The class smmfit inherits from classes (smm, smmparametric) or (smm, smmnonparametric).

Based on a fitted/estimated semi-Markov model (an object of class smmfit), it is possible to:

  • simulate one or several sequences with the method simulate.smmfit();

  • plot estimated conditional sojourn time distributions (method plot.smmfit());

  • compute log-likelihood, AIC and BIC criteria (methods logLik(), AIC(), BIC());

  • compute estimated reliability, maintainability, availability, failure rates and their confidence intervals (methods reliability(), maintainability(), availability(), failureRate()).

Notation

The models and the notation follow Barbu and Limnios (2008). The other help pages of the package only recall the notation they use.

State space

The state space is a finite set EE (the vector states) with s=card(E)s = \textrm{card}(E) elements; when needed, the states are identified with 1,…,s1, \dots, s, in the order of states.

Semi-Markov chain

A Markov renewal chain (Jn,Sn)n∈N(J_n, S_n)_{n \in \mathbb{N}} (Barbu and Limnios, 2008, Definition 3.2, p. 45) is made of:

  • the successively visited states (Jn)n∈N(J_n)_{n \in \mathbb{N}}, a Markov chain called the embedded Markov chain, with initial distribution α\alpha (init) and transition matrix p=(pij)i,j∈Ep = (p_{ij})_{i, j \in E} (ptrans), with pii=0p_{ii} = 0 (no transition to the same state);

  • the jump times (Sn)n∈N(S_n)_{n \in \mathbb{N}}, 0=S0<S1<S2<…0 = S_0 < S_1 < S_2 < \dots, and the sojourn times (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*}, Xn=Sn−Sn−1X_n = S_n - S_{n - 1}, with values in {1,2,… }\{1, 2, \dots\} (no instantaneous transition).

The semi-Markov chain (Zk)k∈N(Z_k)_{k \in \mathbb{N}} gives the state at each time: Zk=JN(k)Z_k = J_{N(k)}, where N(k)=max⁡{n∈N:Sn≤k}N(k) = \max\{n \in \mathbb{N} : S_n \le k\} is the number of jumps up to time kk (Definition 3.7, p. 50). Its backward recurrence time (Uk)k∈N(U_k)_{k \in \mathbb{N}}, Uk=k−SN(k)U_k = k - S_{N(k)}, is the time already spent in the current state; the couple (Zk,Uk)k∈N(Z_k, U_k)_{k \in \mathbb{N}} is a Markov chain (Section 6.2.1, p. 137).

Semi-Markov kernel and sojourn time distributions

The semi-Markov kernel (Definition 3.1, p. 44) is

qij(k)=P(Jn+1=j,Xn+1=k∣Jn=i)=pijfij(k),i,j∈E, k∈N,q_{ij}(k) = P(J_{n + 1} = j, X_{n + 1} = k \mid J_n = i) = p_{ij} f_{ij}(k), \quad i, j \in E,\ k \in \mathbb{N},

with qij(0)=0q_{ij}(0) = 0, where fij(k)=P(Xn+1=k∣Jn=i,Jn+1=j)f_{ij}(k) = P(X_{n + 1} = k \mid J_n = i, J_{n + 1} = j) is the conditional sojourn time distribution (Definition 3.3, p. 46). Four types of models are considered (argument type.sojourn): fijf_{ij} depends on the current state ii and on the next state jj ("fij"), only on ii ("fi", fif_i), only on jj ("fj", fjf_j), or on neither ("f", ff). The sojourn time in state ii has the distribution hi(k)=∑j∈Eqij(k)h_i(k) = \sum_{j \in E} q_{ij}(k), the cumulative distribution function Hi(k)=∑l=1khi(l)H_i(k) = \sum_{l = 1}^{k} h_i(l) and the mean mi=∑k≥1k hi(k)m_i = \sum_{k \ge 1} k\, h_i(k) (Definition 3.4, p. 47).

Transition function and limit distribution

The discrete-time convolution product of two matrix-valued functions is (A∗B)(k)=∑l=0kA(k−l)B(l)(A * B)(k) = \sum_{l = 0}^{k} A(k - l) B(l) (Definition 3.5, p. 48) and q(n)q^{(n)} is the nn-fold convolution of qq. With H(k)=diag(Hi(k); i∈E)H(k) = \textrm{diag}(H_i(k);\ i \in E), the Markov renewal function ψ(k)=∑n=0kq(n)(k)\psi(k) = \sum_{n = 0}^{k} q^{(n)}(k) gives the transition function of the semi-Markov chain (Equation (3.33), p. 59)

Pij(k)=P(Zk=j∣Z0=i),P=ψ∗(I−H).P_{ij}(k) = P(Z_k = j \mid Z_0 = i), \quad P = \psi * (I - H).

The limit distribution of an ergodic semi-Markov chain is πj=νjmj/∑l∈Eνlml\pi_j = \nu_j m_j / \sum_{l \in E} \nu_l m_l, where ν\nu is the stationary distribution of the embedded Markov chain (Proposition 3.9, p. 65).

Reliability

The state space is split into up states UU (upstates), with s1=card(U)s_1 = \textrm{card}(U), and down states D=E∖UD = E \setminus U. TDT_D is the first passage time to DD; the reliability is R(k)=P(TD>k)R(k) = P(T_D > k), the availability A(k)=P(Zk∈U)A(k) = P(Z_k \in U) and the maintainability M(k)=P(TU≤k)M(k) = P(T_U \le k) (Definitions 5.1 to 5.3, pp. 104-108). The chain (Yk)k∈N(Y_k)_{k \in \mathbb{N}} is equal to ZkZ_k for k<TDk < T_D and absorbed in a state Δ\Delta after; its kernel is qYq_Y and its transition function PYP_Y (Proposition 5.1, pp. 105-106).

Markov chains

A Markov chain (Zn)n∈N(Z_n)_{n \in \mathbb{N}} of order kk on EE has a transition matrix ptrans of dimension (sk,s)(s^k, s): its rows correspond to the words of length kk.

Storage of the matrix-valued functions

A matrix-valued function AA on {0,1,…,k}\{0, 1, \dots, k\} (kernel, HH, ψ\psi, PP, ...) is stored in an array of dimension (s,s,k+1)(s, s, k + 1) whose slice l+1l + 1 is the matrix A(l)A(l), for l=0,…,kl = 0, \dots, k. The sequences are given as a list of vectors of states.

Author(s)

Maintainer: Nicolas Vergne [email protected] (ORCID)

Authors:

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

R.E. Barlow, A.W. Marshall, and F. Proschan. (1963). Properties of probability distributions with monotone hazard rate. Ann. Math. Statist., 34, 375-389.

T. Nakagawa and S. Osaki. (1975). The discrete Weibull distribution. IEEE Trans. Reliabil., R-24, 300-301.

D. Roy and R. Gupta. (1992). Classification of discrete lives. Microelectron. Reliabil., 32 (10), 1459-1473.

I. Votsi & A. Brouste (2019) Confidence interval for the mean time to failure in semi-Markov models: an application to wind energy production, Journal of Applied Statistics, 46:10, 1756-1773.

See Also

Useful links:


Availability Function

Description

The pointwise (or instantaneous) availability of a system S\mathcal{S} at time k∈Nk \in \mathbb{N} is the probability that the system is operational at time kk (independently of the fact that the system has failed or not in [0,k)[0, k)).

Usage

availability(x, k, upstates = x$states, level = 0.95, klim = 10000)

Arguments

x

An object of S3 class smmfit or smm.

k

A positive integer giving the time at which the availability should be computed.

upstates

Vector giving the subset of operational states UU.

level

Confidence level of the asymptotic confidence interval. Helpful for an object x of class smmfit.

klim

Optional. The time horizon used to approximate the series in the computation of the mean sojourn times vector mm (cf. meanSojournTimes function) for the asymptotic variance.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, E=U∪DE = U \cup D the partition into up and down states, s=card(E)s = \textrm{card}(E), s1=card(U)s_1 = \textrm{card}(U) and TDT_D the first passage time to DD.

Consider a system (or a component) S\mathcal{S} whose possible states during its evolution in time are E={1,…,s}E = \{1,\dots,s\}. Denote by U={1,…,s1}U = \{1,\dots,s_1\} the subset of operational states of the system (the up states) and by D={s1+1,…,s}D = \{s_1 + 1,\dots,s\} the subset of failure states (the down states), with 0<s1<s0 < s_1 < s (obviously, E=U∪DE = U \cup D and U∩D=∅U \cap D = \emptyset, U≠∅, D≠∅U \neq \emptyset,\ D \neq \emptyset). One can think of the states of UU as different operating modes or performance levels of the system, whereas the states of DD can be seen as failures of the systems with different modes.

We are interested in investigating the availability of a discrete-time semi-Markov system S\mathcal{S}. Consequently, we suppose that the evolution in time of the system is governed by an E-state space semi-Markov chain (Zk)k∈N(Z_k)_{k \in \mathbb{N}}. The state of the system is given at each instant k∈Nk \in \mathbb{N} by ZkZ_k: the event {Zk=i}\{Z_k = i\}, for a certain i∈Ui \in U, means that the system S\mathcal{S} is in operating mode ii at time kk, whereas {Zk=j}\{Z_k = j\}, for a certain j∈Dj \in D, means that the system is not operational at time kk due to the mode of failure jj or that the system is under the repairing mode jj.

The pointwise (or instantaneous) availability of a system S\mathcal{S} at time k∈Nk \in \mathbb{N} is the probability that the system is operational at time kk (independently of the fact that the system has failed or not in [0,k)[0, k)).

Thus, the pointwise availability of a semi-Markov system at time k∈Nk \in \mathbb{N} is

A(k)=P(Zk∈U)=∑i∈EαiAi(k),A(k) = P(Z_k \in U) = \sum_{i \in E} \alpha_i A_i(k),

where we have denoted by Ai(k)A_i(k) the conditional availability of the system at time k∈Nk \in \mathbb{N}, given that it starts in state i∈Ei \in E,

Ai(k)=P(Zk∈U∣Z0=i).A_i(k) = P(Z_k \in U | Z_0 = i).

Value

A matrix with k+1k + 1 rows, and with columns giving values of the availability, asymptotic variances (sigma2), lower (lwr) and upper (upr) asymptotic confidence limits (if x is an object of class smmfit).

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

# Up states "a" and "b", down state "c"
availability(x, k = 10, upstates = c("a", "b"))

# Estimation on a simulated sequence
seqs <- simulate(x, nsim = 5000, seed = 1)
est <- fitsmm(sequences = seqs, states = states, type.sojourn = "fi",
              distr = c("geom", "pois", "dweibull"))

# Estimated availability with asymptotic confidence intervals
head(availability(est, k = 10, upstates = c("a", "b")))

Coefficients, variance-covariance matrix and number of observations of a Markov or semi-Markov model

Description

Methods of the generic functions stats::coef, stats::vcov and stats::nobs for the Markov and semi-Markov models.

Usage

## S3 method for class 'smm'
coef(object, ...)
## S3 method for class 'mm'
coef(object, ...)
## S3 method for class 'smmfit'
vcov(object, ...)
## S3 method for class 'mmfit'
vcov(object, ...)
## S3 method for class 'smmfit'
nobs(object, ...)
## S3 method for class 'mmfit'
nobs(object, ...)

Arguments

object

An object of S3 class mm, mmfit, smm (smmparametric or smmnonparametric) or smmfit (coef()), or of class mmfit or smmfit (vcov(), nobs()).

...

Not used.

Details

Notation (see smmR-package for the complete description of the models): p=(pij)p = (p_{ij}) is the transition matrix of the embedded Markov chain (of the Markov chain for a model of class mm), NiN_i the number of visits of the state (or word) ii followed by a transition and s=card(E)s = \textrm{card}(E).

coef() returns the transition probabilities pijp_{ij}, i≠ji \neq j, named p(i,j) (all the pijp_{ij} for a Markov model, where ii is a word of length kk), followed, for a parametric semi-Markov model, by the parameters of the sojourn time distributions, named after the parameter and the state(s) concerned: n (uniform), theta (geometric), lambda (Poisson), q and beta (discrete Weibull), alpha and prob (negative binomial), with the notation of smmparametric; for instance lambda(a,b) for a Poisson distribution of fabf_{ab} (type.sojourn = "fij"), q(a) for a discrete Weibull distribution of fa∙f_{a\bullet} or f∙af_{\bullet a} ("fi" or "fj") and lambda for ff ("f"). The initial distribution is not included. For a non-parametric semi-Markov model, only the transition probabilities are returned; the sojourn time distributions are given by get.f.

vcov() returns the estimated asymptotic variance-covariance matrix of the maximum likelihood estimators returned by coef(), for a fitted model:

  • for a Markov model (class mmfit), the transition probabilities of each row are multinomial: cov^(p^ij,p^il)=p^ij(1{j=l}−p^il)/Ni\widehat{\textrm{cov}}(\hat p_{ij}, \hat p_{il}) = \hat p_{ij} (\mathbf{1}_{\{j = l\}} - \hat p_{il}) / N_i, and the rows are independent;

  • for a parametric semi-Markov model (class smmfit), the matrix is the inverse of the observed Fisher information, that is of the Hessian of minus the log-likelihood (including the censored sojourn times, if any) with respect to the free parameters, computed by numerical differentiation at the estimate. In each row of pp, one probability is computed from the others, so that the matrix of the pijp_{ij} is singular. The variances are NA for the parameters of the uniform distributions (an integer parameter, whose estimator is the largest observed sojourn time) and for the transition probabilities estimated as 0 or 1;

  • for a non-parametric semi-Markov model, no variance-covariance matrix is returned (an error is given): the asymptotic variances of the estimated semi-Markov kernel and of the reliability indicators are given by get.kernel, reliability, availability, etc. with the argument var = TRUE or in their columns sigma2.

nobs() returns the total length of the sequences used for the estimation, used by BIC.

Value

coef(): a named numeric vector. vcov(): a square matrix whose rows and columns are named as the coefficients. nobs(): an integer.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

summary.smmfit, fitsmm, fitmm, logLik.smmfit

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"),
                   param = matrix(c(0.3, 2, 0.6, NA, NA, 0.8), nrow = 3))
seqs <- simulate(x, nsim = 5000, seed = 1)
est <- fitsmm(sequences = seqs, states = states, type.sojourn = "fi",
              distr = c("geom", "pois", "dweibull"))
coef(est)
sqrt(diag(vcov(est)))   # standard errors
nobs(est)

Discrete-time convolution product of two sequences

Description

Computes the discrete-time convolution product f∗gf * g of two sequences ff and gg defined on N\mathbb{N} (Barbu and Limnios, 2008, Definition 2.2, p. 20):

(f∗g)(k)=∑l=0kf(k−l) g(l),k∈N.(f * g)(k) = \sum_{l = 0}^{k} f(k - l)\, g(l), \quad k \in \mathbb{N}.

Usage

convolution(f, g)

Arguments

f

A numeric vector giving the values f(0),…,f(k)f(0), \dots, f(k).

g

A numeric vector of the same length as f giving the values g(0),…,g(k)g(0), \dots, g(k).

Details

Notation (see smmR-package for the complete description of the models): the sequences are indexed by the time k∈Nk \in \mathbb{N}, and the element l+1l + 1 of a vector is the value at time ll.

The vectors f and g contain the values of the sequences at times 0,1,…,k0, 1, \dots, k. Only the values up to the time horizon kk (the common length of f and g minus one) are needed to compute (f∗g)(0),…,(f∗g)(k)(f * g)(0), \dots, (f * g)(k), so that the result is exact (it is not a truncation of a longer convolution).

The convolution product is commutative and associative, and its neutral element is the sequence δ\delta defined by δ(0)=1\delta(0) = 1 and δ(k)=0\delta(k) = 0 for k>0k > 0. If ff and gg are the distributions of two independent random variables with values in N\mathbb{N}, f∗gf * g is the distribution of their sum. For matrix-valued sequences, see matrixConvolution.

Value

A numeric vector of the same length as f giving the values (f∗g)(0),…,(f∗g)(k)(f * g)(0), \dots, (f * g)(k).

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

matrixConvolution

Examples

# delta is the neutral element
convolution(f = c(0.2, 0.5, 0.3), g = c(1, 0, 0))

# Distribution of the sum of two independent random variables
# with values in {0, 1, 2} (the result is given up to k = 2)
convolution(f = c(0.5, 0.5, 0), g = c(0.5, 0.5, 0))

# Distribution of the sum of two sojourn times (geometric on {1, 2, ...}),
# i.e. of the time of the second jump of a renewal chain
k <- 0:20
f <- c(0, dgeom(k[-1] - 1, prob = 0.4))
f2 <- convolution(f, f)
all.equal(f2, c(0, 0, dnbinom(k[-(1:2)] - 2, size = 2, prob = 0.4)))

Failure Rate Function

Description

Function to compute the BMP-failure rate or the RG-failure rate.

Consider a system S\mathcal{S} starting to work at time k=0k = 0. The BMP-failure rate at time k∈Nk \in \mathbb{N} is the conditional probability that the failure of the system occurs at time kk, given that the system has worked until time k−1k - 1.

The RG-failure rate is a discrete-time adapted failure rate, proposed by D. Roy and R. Gupta. Classification of discrete lives. Microelectronics Reliability, 32(10):1459–1473, 1992. We call it the RG-failure rate and denote it by r(k), k∈Nr(k),\ k \in \mathbb{N}.

Usage

failureRate(
  x,
  k,
  upstates = x$states,
  failure.rate = c("BMP", "RG"),
  level = 0.95,
  epsilon = 0.001,
  klim = 10000
)

Arguments

x

An object of S3 class smmfit or smm.

k

A positive integer giving the period [0,k][0, k] on which the failure rate should be computed.

upstates

Vector giving the subset of operational states UU.

failure.rate

Type of failure rate to compute. If failure.rate = "BMP" (default value), then BMP-failure-rate is computed. If failure.rate = "RG", the RG-failure rate is computed.

level

Confidence level of the asymptotic confidence interval. Helpful for an object x of class smmfit.

epsilon

Threshold below which the reliability is supposed to be 0 because of computation errors (see Details).

klim

Optional. The time horizon used to approximate the series in the computation of the mean sojourn times vector mm (cf. meanSojournTimes function) for the asymptotic variance.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, E=U∪DE = U \cup D the partition into up and down states, s=card(E)s = \textrm{card}(E), s1=card(U)s_1 = \textrm{card}(U) and TDT_D the first passage time to DD.

Consider a system (or a component) S\mathcal{S} whose possible states during its evolution in time are E={1,…,s}E = \{1,\dots,s\}. Denote by U={1,…,s1}U = \{1,\dots,s_1\} the subset of operational states of the system (the up states) and by D={s1+1,…,s}D = \{s_1 + 1,\dots,s\} the subset of failure states (the down states), with 0<s1<s0 < s_1 < s (obviously, E=U∪DE = U \cup D and U∩D=∅U \cap D = \emptyset, U≠∅, D≠∅U \neq \emptyset,\ D \neq \emptyset). One can think of the states of UU as different operating modes or performance levels of the system, whereas the states of DD can be seen as failures of the systems with different modes.

We are interested in investigating the failure rate of a discrete-time semi-Markov system S\mathcal{S}. Consequently, we suppose that the evolution in time of the system is governed by an E-state space semi-Markov chain (Zk)k∈N(Z_k)_{k \in \mathbb{N}}. The system starts to work at instant 00 and the state of the system is given at each instant k∈Nk \in \mathbb{N} by ZkZ_k: the event {Zk=i}\{Z_k = i\}, for a certain i∈Ui \in U, means that the system S\mathcal{S} is in operating mode ii at time kk, whereas {Zk=j}\{Z_k = j\}, for a certain j∈Dj \in D, means that the system is not operational at time kk due to the mode of failure jj or that the system is under the repairing mode jj.

The BMP-failure rate at time k∈Nk \in \mathbb{N} is the conditional probability that the failure of the system occurs at time kk, given that the system has worked until time k−1k - 1.

Let TDT_D denote the first passage time in subset DD, called the lifetime of the system, i.e.,

TD:=inf{n∈N; Zn∈D} and inf ∅:=∞.T_D := \textrm{inf}\{ n \in \mathbb{N};\ Z_n \in D\}\ \textrm{and}\ \textrm{inf}\ \emptyset := \infty.

For a discrete-time semi-Markov system, the failure rate at time k≥1k \geq 1 has the expression:

λ(k):=P(TD=k∣TD≥k)\lambda(k) := P(T_{D} = k | T_{D} \geq k)

We can rewrite it as follows :

λ(k)=1−R(k)R(k−1), if R(k−1)≠0; λ(k)=0,otherwise\lambda(k) = 1 - \frac{R(k)}{R(k - 1)},\ \textrm{if } R(k - 1) \neq 0;\ \lambda(k) = 0, \textrm{otherwise}

The failure rate at time k=0k = 0 is defined by λ(0):=1−R(0)\lambda(0) := 1 - R(0), with RR being the reliability function (see reliability function).

The calculation of the reliability RR involves the computation of many convolutions. It implies that the computation error may be higher (in value) than the "true" reliability itself for reliability close to 0. In order to avoid inconsistent values of the BMP-failure rate, we use the following formula:

λ(k)=1−R(k)R(k−1), if R(k−1)≥ϵ; λ(k)=0,otherwise\lambda(k) = 1 - \frac{R(k)}{R(k - 1)},\ \textrm{if } R(k - 1) \geq \epsilon;\ \lambda(k) = 0, \textrm{otherwise}

with ϵ\epsilon, the threshold, the parameter epsilon in the function failureRate.

Expressing the RG-failure rate r(k)r(k) in terms of the reliability RR we obtain that the RG-failure rate function for a discrete-time system is given by:

r(k)=−ln⁡R(k)R(k−1), if k≥1; r(k)=−ln⁡R(0), if k=0r(k) = - \ln \frac{R(k)}{R(k - 1)},\ \textrm{if } k \geq 1;\ r(k) = - \ln R(0),\ \textrm{if } k = 0

for R(k)≠0R(k) \neq 0. If R(k)=0R(k) = 0, we set r(k):=0r(k) := 0.

Note that the RG-failure rate is related to the BMP-failure rate by:

r(k)=−ln⁡(1−λ(k)), k∈Nr(k) = - \ln (1 - \lambda(k)),\ k \in \mathbb{N}

For an estimated model (class smmfit), the asymptotic variance σλ2(k)\sigma_{\lambda}^2(k) of the estimator of the BMP-failure rate is given by Barbu and Limnios (2008, Theorem 5.4 and Equation (5.35), p. 119), and the asymptotic variance of the estimator of the RG-failure rate is obtained by the delta method (Corollary 5.1, p. 121):

σr2(k)=σλ2(k)(1−λ(k))2.\sigma_r^2(k) = \frac{\sigma_{\lambda}^2(k)}{(1 - \lambda(k))^2}.

The confidence limits are λ^(k)±zσλ2(k)/M\hat{\lambda}(k) \pm z \sqrt{\sigma_{\lambda}^2(k) / M} (or the same with rr and σr2\sigma_r^2), where MM is the total length of the sequences used for the estimation and zz the quantile of order (1+level)/2(1 + level) / 2 of the standard normal distribution.

Value

A matrix with k+1k + 1 rows, and with columns giving values of the BMP-failure rate or RG-failure rate, asymptotic variances (sigma2), lower (lwr) and upper (upr) asymptotic confidence limits (if x is an object of class smmfit).

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

R.E. Barlow, A.W. Marshall, and F. Proschan. (1963). Properties of probability distributions with monotone hazard rate. Ann. Math. Statist., 34, 375-389.

D. Roy and R. Gupta. (1992). Classification of discrete lives. Microelectron. Reliabil., 32 (10), 1459-1473.

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

# Up states "a" and "b", down state "c"
failureRate(x, k = 10, upstates = c("a", "b"), failure.rate = "BMP")
failureRate(x, k = 10, upstates = c("a", "b"), failure.rate = "RG")

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

Description

Maximum Likelihood Estimation of the transition matrix and initial distribution of a k-th order Markov chain starting from one or several sequences.

Usage

fitmm(sequences, states, k = 1, init.estim = "mle")

Arguments

sequences

A list of vectors representing the sequences.

states

Vector of state space (of length s).

k

Order of the Markov chain.

init.estim

Optional. init.estim gives the method used to estimate the initial distribution. The following methods are proposed:

  • init.estim = "mle": the classical Maximum Likelihood Estimator is used to estimate the initial distribution init;

  • init.estim = "stationary": the initial distribution is replaced by the stationary distribution of the Markov chain (if the order of the Markov chain is more than one, the transition matrix is converted into a square block matrix in order to estimate the stationary distribution);

  • init.estim = "freq": the initial distribution is estimated by taking the frequencies of the words of length k for all sequences;

  • init.estim = "prod": init is estimated by using the product of the frequencies of each letter (for all the sequences) in the word of length k;

  • init.estim = "unif": the initial probability of each state is equal to 1/s1 / s, with ss the number of states.

Details

Notation (see smmR-package for the complete description of the models): (Zn)n∈N(Z_n)_{n \in \mathbb{N}} is a Markov chain of order kk on EE, with s=card(E)s = \textrm{card}(E), initial distribution init and transition matrix ptrans of dimension (sk,s)(s^k, s).

Let X1,X2,...,XnX_1, X_2, ..., X_n be a trajectory of length nn of the Markov chain X=(Xm)m∈NX = (X_m)_{m \in \mathbb{N}} of order k=1k = 1 with transition matrix ptrans(i,j)=P(Xm+1=j∣Xm=i)p_{trans}(i,j) = P(X_{m+1} = j | X_m = i). The maximum likelihood estimation of the transition matrix is ptrans^(i,j)=NijNi.\widehat{p_{trans}}(i,j) = \frac{N_{ij}}{N_{i.}}, where NijN_{ij} is the number of transitions from state ii to state jj and Ni.N_{i.} is the number of transition from state ii to any state. For k>1k > 1 we have similar expressions.

The initial distribution of a k-th order Markov chain is defined as μi=P(X1=i)\mu_i = P(X_1 = i). Five methods are proposed for the estimation of the latter :

Maximum Likelihood Estimator:

The Maximum Likelihood Estimator for the initial distribution. The formula is: μi^=NstartiL\widehat{\mu_i} = \frac{Nstart_i}{L}, where NstartiNstart_i is the number of occurrences of the word ii (of length kk) at the beginning of each sequence and LL is the number of sequences. This estimator is reliable when the number of sequences LL is high.

Stationary distribution:

The stationary distribution is used as a surrogate of the initial distribution. If the order of the Markov chain is more than one, the transition matrix is converted into a square block matrix in order to estimate the stationary distribution. This method may take time if the order of the Markov chain is high (more than three (3)).

Frequencies of each word:

The initial distribution is estimated by taking the frequencies of the words of length k for all sequences. The formula is μi^=NiN\widehat{\mu_i} = \frac{N_i}{N}, where NiN_i is the number of occurrences of the word ii (of length kk) in the sequences and NN is the sum of the lengths of the sequences.

Product of the frequencies of each state:

The initial distribution is estimated by using the product of the frequencies of each state (for all the sequences) in the word of length kk.

Uniform distribution:

The initial probability of each state is equal to 1/s1 / s, with ss, the number of states.

Value

An object of class S3 mmfit (inheriting from the S3 class mm). The S3 class mmfit contains:

  • All the attributes of the S3 class mm;

  • An attribute M which is an integer giving the total length of the set of sequences sequences (sum of all the lengths of the list sequences);

  • An attribute logLik which is a numeric value giving the value of the log-likelihood of the specified Markov model based on the sequences;

  • An attribute sequences which is equal to the parameter sequences of the function fitmm (i.e. a list of sequences used to estimate the Markov model).

See Also

mm, simulate.mm

Examples

states <- c("a", "c", "g", "t")
s <- length(states)
k <- 2
init <- rep.int(1 / s ^ k, s ^ k)
p <- matrix(0.25, nrow = s ^ k, ncol = s)

# Specify a Markov model of order 2
markov <- mm(states = states, init = init, ptrans = p, k = k)

seqs <- simulate(object = markov, nsim = c(1000, 10000, 2000), seed = 150)

est <- fitmm(sequences = seqs, states = states, k = 2)

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

Description

Maximum Likelihood Estimation of a semi-Markov chain starting from one or several sequences. This estimation can be parametric or non-parametric, non-censored, censored at the beginning and/or at the end of the sequence, with one or several trajectories. Several parametric distributions are considered (Uniform, Geometric, Poisson, Discrete Weibull and Negative Binomial).

Usage

fitsmm(
  sequences,
  states,
  type.sojourn = c("fij", "fi", "fj", "f"),
  distr = "nonparametric",
  init.estim = "mle",
  cens.beg = FALSE,
  cens.end = FALSE
)

Arguments

sequences

A list of vectors representing the sequences.

states

Vector of state space (of length s).

type.sojourn

Type of sojourn time (for more explanations, see Details).

distr

By default "nonparametric" for the non-parametric estimation case.

If the parametric estimation case is desired, distr should be:

  • A matrix of distributions of dimension (s,s)(s, s) if type.sojourn = "fij";

  • A vector of distributions of length ss if type.sojourn = "fi" or "fj";

  • A distribution if type.sojourn = "f".

The distributions to be used in distr must be one of "unif", "geom", "pois", "dweibull", "nbinom".

init.estim

Optional. init.estim gives the method used to estimate the initial distribution. The following methods are proposed:

  • init.estim = "mle": the classical Maximum Likelihood Estimator is used to estimate the initial distribution init;

  • init.estim = "limit": the initial distribution is replaced by the limit (stationary) distribution of the semi-Markov chain;

  • init.estim = "freq": the initial distribution is replaced by the frequencies of each state in the sequences;

  • init.estim = "unif": the initial probability of each state is equal to 1/s1 / s, with ss the number of states.

cens.beg

Optional. A logical value indicating whether or not sequences are censored at the beginning. The censoring at the beginning is only available for the parametric estimation (distr different from "nonparametric").

cens.end

Optional. A logical value indicating whether or not sequences are censored at the end.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, (Jn)n∈N(J_n)_{n \in \mathbb{N}} its embedded Markov chain (initial distribution init, transition matrix pp = ptrans), (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times, qij(k)=pijfij(k)q_{ij}(k) = p_{ij} f_{ij}(k) the semi-Markov kernel and s=card(E)s = \textrm{card}(E).

This function estimates a semi-Markov model in parametric or non-parametric case, taking into account the type of sojourn time and the censoring described in references. The non-parametric estimation concerns sojourn time distributions defined by the user. For the parametric estimation, several discrete distributions are considered (see below).

The difference between the Markov model and the semi-Markov model concerns the modeling of the sojourn time. With a Markov chain, the sojourn time distribution is modeled by a Geometric distribution (in discrete time). With a semi-Markov chain, the sojourn time can be any arbitrary distribution. In this package, the available distribution for a semi-Markov model are :

  • Uniform: f(x)=1nf(x) = \frac{1}{n} for 1≤x≤n1 \le x \le n. nn is the parameter;

  • Geometric: f(x)=θ(1−θ)x−1f(x) = \theta (1-\theta)^{x - 1} for x=1,2,…,nx = 1, 2,\ldots,n, 0<θ<10 < \theta < 1, θ\theta is the probability of success. θ\theta is the parameter;

  • Poisson: f(x)=λxexp(−λ)x!f(x) = \frac{\lambda^x exp(-\lambda)}{x!} for x=0,1,2,…,nx = 0, 1, 2,\ldots,n, with λ>0\lambda > 0. λ\lambda is the parameter;

  • Discrete Weibull of type 1: f(x)=q(x−1)β−qxβf(x)=q^{(x-1)^{\beta}}-q^{x^{\beta}}, x=1,2,…,nx = 1, 2,\ldots,n, with 0<q<10 < q < 1, the first parameter and β>0\beta > 0 the second parameter. (q,β)(q, \beta) are the parameters;

  • Negative binomial: f(x)=Γ(x+α)Γ(α)x!pα(1−p)xf(x)=\frac{\Gamma(x+\alpha)}{\Gamma(\alpha) x!} p^{\alpha} (1 - p)^x, for x=0,1,2,…,nx = 0, 1, 2,\ldots,n, Γ\Gamma is the Gamma function, α\alpha is the parameter of overdispersion and pp is the probability of success, 0<p<10 < p < 1. (α,p)(\alpha, p) are the parameters;

  • Non-parametric.

We define :

  • the semi-Markov kernel qij(k)=P(Jm+1=j,Tm+1−Tm=k∣Jm=i)q_{ij}(k) = P( J_{m+1} = j, T_{m+1} - T_{m} = k | J_{m} = i );

  • the transition matrix (ptrans(i,j))i,j∈states(p_{trans}(i,j))_{i,j} \in states of the embedded Markov chain J=(Jm)mJ = (J_m)_m, ptrans(i,j)=P(Jm+1=j∣Jm=i)p_{trans}(i,j) = P( J_{m+1} = j | J_m = i );

  • the initial distribution μi=P(J1=i)=P(Z1=i)\mu_i = P(J_1 = i) = P(Z_1 = i), i∈1,2,…,si \in 1, 2, \dots, s;

  • the conditional sojourn time distributions (fij(k))i,j∈states, k∈N, fij(k)=P(Tm+1−Tm=k∣Jm=i,Jm+1=j)(f_{ij}(k))_{i,j} \in states,\ k \in \mathbb{N} ,\ f_{ij}(k) = P(T_{m+1} - T_m = k | J_m = i, J_{m+1} = j ), ff is specified by the argument param in the parametric case and by distr in the non-parametric case.

The maximum likelihood estimation of the transition matrix of the embedded Markov chain is ptrans^(i,j)=NijNi.\widehat{p_{trans}}(i,j) = \frac{N_{ij}}{N_{i.}}.

Five methods are proposed for the estimation of the initial distribution :

Maximum Likelihood Estimator:

The Maximum Likelihood Estimator for the initial distribution. The formula is: μi^=NstartiL\widehat{\mu_i} = \frac{Nstart_i}{L}, where NstartiNstart_i is the number of occurrences of the word ii (of length kk) at the beginning of each sequence and LL is the number of sequences. This estimator is reliable when the number of sequences LL is high.

Limit (stationary) distribution:

The limit (stationary) distribution of the semi-Markov chain is used as a surrogate of the initial distribution.

Frequencies of each state:

The initial distribution is replaced by taking the frequencies of each state in the sequences.

Uniform distribution:

The initial probability of each state is equal to 1/s1 / s, with ss, the number of states.

Note that qij(k)=ptrans(i,j) fij(k)q_{ij}(k) = p_{trans}(i,j) \ f_{ij}(k) in the general case (depending on the present state and on the next state). For particular cases, we replace fij(k)f_{ij}(k) by fi.(k)f_{i.}(k) (depending on the present state ii), f.j(k)f_{.j}(k) (depending on the next state jj) and f..(k)f_{..}(k) (depending neither on the present state nor on the next state).

In this package we can choose different types of sojourn time. Four options are available for the sojourn times:

  • depending on the present state and on the next state (fij);

  • depending only on the present state (fi);

  • depending only on the next state (fj);

  • depending neither on the current, nor on the next state (f).

If type.sojourn = "fij", distr is a matrix of dimension (s,s)(s, s) (e.g., if the 1st element of the 2nd column is "pois", that is to say we go from the first state to the second state following a Poisson distribution). If type.sojourn = "fi" or "fj", distr must be a vector (e.g., if the first element of vector is "geom", that is to say we go from (or to) the first state to (or from) any state according to a Geometric distribution). If type.sojourn = "f", distr must be one of "unif", "geom", "pois", "dweibull", "nbinom" (e.g., if distr is equal to "nbinom", that is to say that the sojourn time when going from one state to another state follows a Negative Binomial distribution). For the non-parametric case, distr is equal to "nonparametric" whatever type of sojourn time given.

If the sequence is censored at the beginning and/or at the end, cens.beg must be equal to TRUE and/or cens.end must be equal to TRUE. All the sequences must be censored in the same way.

Value

Returns an object of S3 class smmfit (inheriting from the S3 class smm and smmnonparametric class if distr = "nonparametric" or smmparametric otherwise). The S3 class smmfit contains:

  • All the attributes of the S3 class smmnonparametric or smmparametric depending on the type of estimation;

  • An attribute M which is an integer giving the total length of the set of sequences sequences (sum of all the lengths of the list sequences);

  • An attribute logLik which is a numeric value giving the value of the log-likelihood of the specified semi-Markov model based on the sequences;

  • An attribute sequences which is equal to the parameter sequences of the function fitsmm (i.e. a list of sequences used to estimate the Markov model).

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

smmnonparametric, smmparametric, simulate.smm, simulate.smmfit, plot.smm, plot.smmfit

Examples

states <- c("a", "c", "g", "t")
s <- length(states)

# Creation of the initial distribution
vect.init <- c(1 / 4, 1 / 4, 1 / 4, 1 / 4)

# Creation of the transition matrix
pij <- matrix(c(0, 0.2, 0.5, 0.3, 
                0.2, 0, 0.3, 0.5, 
                0.3, 0.5, 0, 0.2, 
                0.4, 0.2, 0.4, 0), 
              ncol = s, byrow = TRUE)

# Creation of the distribution matrix

distr.matrix <- matrix(c(NA, "pois", "geom", "nbinom", 
                         "geom", NA, "pois", "dweibull",
                         "pois", "pois", NA, "geom", 
                         "pois", "geom", "geom", NA), 
                       nrow = s, ncol = s, byrow = TRUE)

# Creation of an array containing the parameters
param1.matrix <- matrix(c(NA, 2, 0.4, 4, 
                          0.7, NA, 5, 0.6, 
                          2, 3, NA, 0.6, 
                          4, 0.3, 0.4, NA), 
                        nrow = s, ncol = s, byrow = TRUE)

param2.matrix <- matrix(c(NA, NA, NA, 0.6, 
                          NA, NA, NA, 0.8, 
                          NA, NA, NA, NA, 
                          NA, NA, NA, NA), 
                        nrow = s, ncol = s, byrow = TRUE)

param.array <- array(c(param1.matrix, param2.matrix), c(s, s, 2))

# Specify the semi-Markov model
semimarkov <- smmparametric(states = states, init = vect.init, ptrans = pij, 
                            type.sojourn = "fij", distr = distr.matrix, 
                            param = param.array)

seqs <- simulate(object = semimarkov, nsim = c(1000, 10000, 2000), seed = 100)

# Estimation of simulated sequences
est <- fitsmm(sequences = seqs, states = states, type.sojourn = "fij", 
              distr = distr.matrix)

Conditional sojourn time distributions

Description

Returns the values at times 1,…,k1, \dots, k of the conditional sojourn time distributions of a semi-Markov chain:

fij(l)=P(Xn+1=l∣Jn=i,Jn+1=j),l≥1,f_{ij}(l) = P(X_{n + 1} = l \mid J_n = i, J_{n + 1} = j), \quad l \ge 1,

(Barbu and Limnios, 2008, Definition 3.3, p. 46) or, depending on the type of the model (type.sojourn), fi(l)f_i(l) (depending on the current state), fj(l)f_j(l) (depending on the next state) or f(l)f(l) (depending on neither) (Remark 3.3, p. 47). The semi-Markov kernel is qij(l)=pijfij(l)q_{ij}(l) = p_{ij} f_{ij}(l).

Usage

get.f(x, k)

Arguments

x

An object of S3 class smm (smmparametric or smmnonparametric) or smmfit (see fitsmm).

k

A strictly positive integer giving the time horizon.

Details

Notation (see smmR-package for the complete description of the models): (Jn)n∈N(J_n)_{n \in \mathbb{N}} is the embedded Markov chain with transition matrix pp (ptrans), (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times and s=card(E)s = \textrm{card}(E).

There are no instantaneous transitions, so that f(0)=0f(0) = 0: the values start at time 1. For a nonparametric model (smmnonparametric), the values beyond the maximal sojourn time kmaxk_{max} of the model are 0. For a parametric model (smmparametric), the distributions are those of distr shifted to {1,2,… }\{1, 2, \dots\} (see smmparametric); the entries corresponding to NA in distr (e.g. the diagonal for "fij") are 0.

Value

The values f(1),…,f(k)f(1), \dots, f(k), with s=card(E)s = \textrm{card}(E), according to type.sojourn:

"fij"

An array of dimension (s,s,k)(s, s, k) whose element ⁠[i, j, l]⁠ is fij(l)f_{ij}(l);

"fi", "fj"

A matrix of dimension (s,k)(s, k) whose element ⁠[i, l]⁠ is fi(l)f_i(l) (or fj(l)f_j(l));

"f"

A vector of length kk whose element ll is f(l)f(l).

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

smmparametric, smmnonparametric, fitsmm, get.kernel

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

f <- get.f(x, k = 10)   # matrix (3, 10): f_i(l), l = 1, ..., 10
round(f, 3)
rowSums(get.f(x, k = 200))   # close to 1

Cumulative distribution functions of the sojourn times in each state

Description

Computes, from a semi-Markov kernel qq, the diagonal matrix-valued function H(k)=diag(Hi(k); i∈E)H(k) = \textrm{diag}(H_i(k);\ i \in E) (Barbu and Limnios, 2008, Definition 3.4, p. 47, and p. 51), where HiH_i is the cumulative distribution function of the sojourn time in state ii:

Hi(k)=P(Xn+1≤k∣Jn=i)=∑l=1k∑j∈Eqij(l).H_i(k) = P(X_{n + 1} \le k \mid J_n = i) = \sum_{l = 1}^{k} \sum_{j \in E} q_{ij}(l).

Usage

get.H(q)

Arguments

q

A numeric array of dimension (s,s,k+1)(s, s, k + 1), where s=card(E)s = \textrm{card}(E), giving the values of a semi-Markov kernel at times 0,…,k0, \dots, k, typically the output of get.kernel (or of get.qy).

Details

Notation (see smmR-package for the complete description of the models): (Jn)n∈N(J_n)_{n \in \mathbb{N}} is the embedded Markov chain, (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times, qq the semi-Markov kernel and s=card(E)s = \textrm{card}(E).

The function I−H(k)I - H(k), where II is the identity matrix, gives the survival functions H‾i(k)=P(Xn+1>k∣Jn=i)\overline{H}_i(k) = P(X_{n + 1} > k \mid J_n = i) of the sojourn times; it is used to compute the transition function P=ψ∗(I−H)P = \psi * (I - H) (see get.P).

Hi(k)H_i(k) tends to 1 as kk tends to infinity. When the sojourn times have a finite support, Hi(k)=1H_i(k) = 1 for kk larger than the maximal sojourn time.

Value

A numeric array of dimension (s,s,k+1)(s, s, k + 1) whose slice l+1l + 1 is the diagonal matrix H(l)H(l), for l=0,…,kl = 0, \dots, k.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

get.kernel, get.psi, get.P, meanSojournTimes

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

q <- get.kernel(x, k = 20)
H <- get.H(q)
H[, , 6]                                     # H(5)
t(apply(H, 3, diag))[1:6, ]                  # H_i(l), l = 0, ..., 5

Method to get the semi-Markov kernel qq

Description

Computes the semi-Markov kernel qij(k)q_{ij}(k).

Usage

get.kernel(x, k, var = FALSE, klim = 10000)

Arguments

x

An object of S3 class smmfit or smm.

k

A positive integer giving the time horizon.

var

Logical. If TRUE the asymptotic variance is computed.

klim

Optional. The time horizon used to approximate the series in the computation of the mean sojourn times vector mm (cf. meanSojournTimes function) for the asymptotic variance.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, (Jn)n∈N(J_n)_{n \in \mathbb{N}} its embedded Markov chain (initial distribution init, transition matrix pp = ptrans), (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times, qij(k)=pijfij(k)q_{ij}(k) = p_{ij} f_{ij}(k) the semi-Markov kernel and s=card(E)s = \textrm{card}(E).

Value

An array giving the value of qij(k)q_{ij}(k) at each time between 0 and k if var = FALSE. If var = TRUE, a list containing the following components:

x:

an array giving the value of qij(k)q_{ij}(k) at each time between 0 and k;

sigma2:

an array giving the asymptotic variance of the estimator σq2(i,j,k)\sigma_{q}^{2}(i, j, k).

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

q <- get.kernel(x, k = 5)
q[, , 3]   # q(2)

# The kernel sums to 1 over the next states and the times (k large)
rowSums(apply(get.kernel(x, k = 200), c(1, 2), sum))

Number of parameters of a Markov or semi-Markov model

Description

Returns the number of parameters of a Markov or semi-Markov model, used in the computation of the information criteria AIC and BIC (see logLik.smm).

Usage

get.Kpar(x)

Arguments

x

An object of S3 class mm, mmfit, smm (smmparametric or smmnonparametric) or smmfit.

Details

Notation (see smmR-package for the complete description of the models): s=card(E)s = \textrm{card}(E) is the number of states, kk the order of a Markov chain and kmaxk_{max} the maximal sojourn time of a nonparametric semi-Markov model.

The number of parameters is:

  • Markov chain of order kk (mm, mmfit): the number of free transition probabilities, (s−1)sk(s - 1) s^k;

  • parametric semi-Markov model (smmparametric): the number of parameters of the sojourn time distributions, i.e. the sum over the distributions of distr of 1 ("geom", "pois", "unif") or 2 ("nbinom", "dweibull");

  • nonparametric semi-Markov model (smmnonparametric) with maximal sojourn time kmaxk_{max}: s(s−2)(kmax−1)s (s - 2) (k_{max} - 1) for "fij", s(kmax−1)s (k_{max} - 1) for "fi" and "fj", and kmax−1k_{max} - 1 for "f".

Value

A positive integer giving the number of parameters.

See Also

logLik.smm, mm, smmparametric, smmnonparametric

Examples

# Markov chain of order 2 on 2 states: (2 - 1) * 2^2 = 4 parameters
x <- mm(states = c("a", "b"), init = rep(1/4, 4), k = 2,
        ptrans = matrix(c(0.9, 0.1, 0.5, 0.5, 0.2, 0.8, 0.3, 0.7),
                        nrow = 4, byrow = TRUE))
get.Kpar(x)

# Parametric semi-Markov model: geom (1) + pois (1) + dweibull (2) = 4
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
y <- smmparametric(states = c("a", "b", "c"), init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)
get.Kpar(y)

Limit distribution of a semi-Markov chain

Description

Computes the limit distribution π\pi of an ergodic semi-Markov chain (Zk)k∈N(Z_k)_{k \in \mathbb{N}}, πj=lim⁡k→∞P(Zk=j)\pi_j = \lim_{k \to \infty} P(Z_k = j) (Barbu and Limnios, 2008, Definition 3.14 and Proposition 3.9, Equation (3.42), p. 65):

πj=νj mj∑l∈Eνl ml,j∈E,\pi_j = \frac{\nu_j\, m_j}{\sum_{l \in E} \nu_l\, m_l}, \quad j \in E,

where ν\nu is the stationary distribution of the embedded Markov chain (Jn)n∈N(J_n)_{n \in \mathbb{N}} (transition matrix ptrans) and mjm_j the mean sojourn time in state jj (see meanSojournTimes).

Usage

get.limitDistribution(x, klim = 10000)

Arguments

x

An object of S3 class smm (smmparametric or smmnonparametric) or smmfit (see fitsmm).

klim

Optional. The time horizon used to approximate the series in the computation of the mean sojourn times mm (cf. meanSojournTimes).

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, (Jn)n∈N(J_n)_{n \in \mathbb{N}} its embedded Markov chain, mjm_j the mean sojourn time in jj and s=card(E)s = \textrm{card}(E).

The mean sojourn times are computed from the semi-Markov kernel up to time klim (the series are truncated). The limit distribution of a semi-Markov chain is in general different from the stationary distribution ν\nu of its embedded Markov chain: the states with long sojourns have a larger weight. The Markov renewal chain is assumed aperiodic, irreducible and with finite mean sojourn times (assumptions of Proposition 3.9).

Value

A vector of length s=card(E)s = \textrm{card}(E) giving the values of the limit distribution.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

meanSojournTimes, get.P, get.stationaryDistribution

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

get.limitDistribution(x)

# Each row of the transition function P(k) tends to the limit distribution
get.P(x, k = 300)[, , 301]

Counting process Niuj of the couple (state, backward recurrence time)

Description

Counts, in a list of sequences, the transitions of the Markov chain (Zk,Uk)k∈N(Z_k, U_k)_{k \in \mathbb{N}}, where (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain and (Uk)k∈N(U_k)_{k \in \mathbb{N}} its backward recurrence time (time already spent in the current state):

Niuj=∑k≥11{Zk−1=i, Uk−1=u, Zk=j}.N_{iuj} = \sum_{k \ge 1} \mathbf{1}_{\{Z_{k - 1} = i,\ U_{k - 1} = u,\ Z_k = j\}}.

The couple (Zk,Uk)k∈N(Z_k, U_k)_{k \in \mathbb{N}} is a Markov chain (Barbu and Limnios, 2008, Section 6.2.1, Equation (6.5) and Proposition 6.1, p. 137). These counts are the sufficient statistics of the exact maximum likelihood estimator of a nonparametric semi-Markov chain censored at the end of the sequences (Trevezas and Limnios, 2011).

Usage

get.Niuj(sequences)

Arguments

sequences

A list of vectors (of characters or numbers) representing the observed sequences of states.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the observed semi-Markov chain and (Uk)k∈N(U_k)_{k \in \mathbb{N}} its backward recurrence time, Uk=k−SN(k)U_k = k - S_{N(k)}.

Uk=0U_k = 0 when the chain has just entered a new state at time kk; if Zk−1=iZ_{k - 1} = i and Uk−1=uU_{k - 1} = u, then either Zk=iZ_k = i and Uk=u+1U_k = u + 1 (the sojourn in ii goes on) or Zk=j≠iZ_k = j \neq i and Uk=0U_k = 0 (jump to jj). The diagonal counts NiuiN_{iui} are therefore the numbers of times the sojourn in ii goes on after u+1u + 1 time units.

The states are taken in their order of first appearance in sequences (unique(unlist(sequences))), as in get.processes.

Value

A numeric array of dimension (s,kmax,s)(s, k_{max}, s), where ss is the number of distinct observed states and kmaxk_{max} the length of the longest observed sojourn: the element ⁠[i, u + 1, j]⁠ is NiujN_{iuj}, for u=0,…,kmax−1u = 0, \dots, k_{max} - 1. The dimensions are named with the states and the values of uu.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

S. Trevezas, N. Limnios. (2011). Exact MLE and asymptotic properties for nonparametric semi-Markov models. Journal of Nonparametric Statistics, 23(3), 719-739.

See Also

get.processes, fitsmm

Examples

seqs <- list(c("c", "c", "a", "a", "a", "g"), c("a", "g", "g"))
N <- get.Niuj(seqs)
dim(N)      # states "c", "a", "g" (order of appearance), kmax = 3

# Transitions from state "a" after u = 0, 1, 2 time units
N["a", , ]  # rows: u = 0, 1, 2; columns: next state "c", "a", "g"

Transition function of a semi-Markov chain

Description

Computes the transition function PP of the semi-Markov chain (Zk)k∈N(Z_k)_{k \in \mathbb{N}}, Pij(k)=P(Zk=j∣Z0=i)P_{ij}(k) = P(Z_k = j \mid Z_0 = i) (Barbu and Limnios, 2008, Definition 3.8, p. 51, and Equation (3.33), p. 59):

P=ψ∗(I−H),P = \psi * (I - H),

where ψ\psi is the Markov renewal function (get.psi), HH the diagonal matrix of the sojourn time cumulative distribution functions (get.H) and ∗* the matrix convolution product (matrixConvolution).

Usage

get.P(x, k, states = x$states, var = FALSE, klim = 10000)

Arguments

x

An object of S3 class smm (smmparametric or smmnonparametric) or smmfit (see fitsmm).

k

A positive integer giving the time horizon.

states

Vector giving the subset AA of states for which the transition function is computed (by default, all the states; see Details).

var

Logical. If TRUE the asymptotic variance is computed.

klim

Optional. The time horizon used to approximate the series in the computation of the mean recurrence times (cf. meanRecurrenceTimes) for the asymptotic variance.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, qq its kernel, HH and ψ\psi are defined in get.H and get.psi, and s=card(E)s = \textrm{card}(E).

When states is a strict subset AA of EE, the function computes ψAA∗(I−H)AA\psi_{AA} * (I - H)_{AA}, where ψAA\psi_{AA} is the Markov renewal function of the restriction qAAq_{AA} of the kernel to AA: its element (i,j)(i, j) at time kk is the probability that the chain stays in AA up to time kk and is in state jj at time kk, given Z0=iZ_0 = i:

P(Zk=j, Zl∈A, l=0,…,k∣Z0=i),i,j∈A.P(Z_k = j,\ Z_l \in A,\ l = 0, \dots, k \mid Z_0 = i), \quad i, j \in A.

With A=UA = U, the set of up states, this is the function P11P_{11} of Barbu and Limnios (2008, Proposition 5.1 and its second proof, pp. 105-106), and the sum over jj of these probabilities is the reliability of the system starting from ii (see reliability).

With var = TRUE, the asymptotic variance of the estimator of Pij(k)P_{ij}(k) is computed (Barbu and Limnios, 2008, Equation (4.29), p. 91); this is relevant for a fitted model (class smmfit).

Value

If var = FALSE, a numeric array of dimension (a,a,k+1)(a, a, k + 1), where a=card(A)a = \textrm{card}(A) (a=sa = s by default), whose slice l+1l + 1 is the matrix P(l)P(l), for l=0,…,kl = 0, \dots, k; the rows and columns follow the order of x$states. If var = TRUE, a list with the following components:

x

The array described above;

sigma2

An array of the same dimension giving the asymptotic variances σP2(i,j,k)\sigma_{P}^{2}(i, j, k).

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

get.psi, get.H, matrixConvolution, availability, reliability, get.limitDistribution

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

P <- get.P(x, k = 20)
P[, , 6]                 # P(5)
rowSums(P[, , 21])       # each P(k) is a stochastic matrix

# Probability to stay in {"a", "b"} up to time 5
Pab <- get.P(x, k = 5, states = c("a", "b"))
rowSums(Pab[, , 6])

Processes associated with a list of sequences

Description

Computes, for a list of sequences, the processes of the Markov renewal representation of a semi-Markov chain (successively visited states, jump times, sojourn times, backward recurrence times) and the counting processes used by the estimators of fitsmm.

Usage

get.processes(sequences)

Arguments

sequences

A list of vectors (of characters or numbers) representing the observed sequences of states.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the observed semi-Markov chain, (Jn)n∈N(J_n)_{n \in \mathbb{N}} the visited states, (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times and (Uk)k∈N(U_k)_{k \in \mathbb{N}} the backward recurrence times.

For each sequence Z1,…,ZnZ_1, \dots, Z_n (time is counted from 1 to nn, as the indices of the R vector):

  • Jm gives the successively visited states J0,J1,…J_0, J_1, \dots (embedded Markov chain (Jn)n∈N(J_n)_{n \in \mathbb{N}});

  • Xm gives the corresponding sojourn times X1,X2,…X_1, X_2, \dots ((Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*}); the last one is censored by the end of the sequence;

  • Tm gives the times when a new state is entered, from the second visited state on, followed by n+1n + 1;

  • Um gives the backward recurrence times (Uk)k∈N(U_k)_{k \in \mathbb{N}}, i.e. the number of time units already spent in the current state (0 at each jump; Barbu and Limnios, 2008, Equation (6.5), p. 137).

The states are taken in their order of first appearance in sequences (unique(unlist(sequences))), not in alphabetical order.

Value

A list with the following components:

s

Number of distinct observed states;

states

Vector of the observed states, in their order of first appearance (length ss);

M

Total length (sum of the length of each sequence);

L

Number of sequences;

kmax

Length of the longest sojourn (censored sojourns included);

Ym

The list sequences itself;

Jm

List of the successively visited states of each sequence;

Tm

List of the jump times of each sequence (see Details);

Xm

List of the sojourn times of each sequence;

Um

List of the backward recurrence times of each sequence;

counting

List of counting processes, with the states coded by their index in states and the sojourn times k=1,…,kmaxk = 1, \dots, k_{max}: Nijk (array of dimension (s,s,kmax)(s, s, k_{max}), number of transitions i→ji \to j after a complete sojourn of length kk in ii), its margins Nij, Nik, Njk, Ni, Nj, Nk and its total N; Nbijk and its margins Nbik, Nbjk, Nbk (first sojourn of each sequence, used for the censoring at the beginning); Neik, Nek (last sojourn of each sequence, censored at the end); Nebik, Nebk (sums of the previous two); Nstarti (number of sequences starting in each state).

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

get.Niuj, fitsmm

Examples

seqs <- list(c("c", "c", "a", "a", "a", "g"), c("a", "g", "g"))
p <- get.processes(seqs)
p$states    # "c" "a" "g"
p$Jm[[1]]   # "c" "a" "g"
p$Xm[[1]]   # 2 3 1
p$Tm[[1]]   # 3 6 7
p$Um[[1]]   # 0 1 0 1 2 0
p$counting$Nij

Markov renewal function ψ of a semi-Markov kernel

Description

Computes, from a semi-Markov kernel qq, the matrix-valued function ψ\psi (Barbu and Limnios, 2008, Proposition 3.4, Equations (3.14)-(3.16), p. 53):

ψ(k)=∑n=0kq(n)(k),k∈N,\psi(k) = \sum_{n = 0}^{k} q^{(n)}(k), \quad k \in \mathbb{N},

where q(n)q^{(n)} is the nn-fold matrix convolution of qq (see matrixConvolution) and q(0)=δIq^{(0)} = \delta I.

Usage

get.psi(q)

Arguments

q

A numeric array of dimension (s,s,k+1)(s, s, k + 1), where s=card(E)s = \textrm{card}(E), giving the values of a semi-Markov kernel at times 0,…,k0, \dots, k, typically the output of get.kernel (or of get.qy).

Details

Notation (see smmR-package for the complete description of the models): (Jn)n∈N(J_n)_{n \in \mathbb{N}} is the embedded Markov chain, (Sn)n∈N(S_n)_{n \in \mathbb{N}} the jump times, qq the semi-Markov kernel and s=card(E)s = \textrm{card}(E).

ψij(k)\psi_{ij}(k) is the probability that the semi-Markov chain enters state jj at time kk (i.e. that a jump to jj occurs at time kk), given that it entered state ii at time 0 (Equation (3.19), p. 54):

ψij(k)=P(⋃n=0k{Jn=j,Sn=k} | J0=i).\psi_{ij}(k) = P\left(\bigcup_{n = 0}^{k} \{J_n = j, S_n = k\} \,\middle|\, J_0 = i\right).

Since there are no instantaneous transitions (q(0)=0q(0) = 0), the sum is finite and ψ\psi is computed exactly by the recursion

ψ(0)=I,ψ(k)=∑l=0k−1ψ(l) q(k−l),k≥1,\psi(0) = I, \quad \psi(k) = \sum_{l = 0}^{k - 1} \psi(l)\, q(k - l), \quad k \ge 1,

which is the solution of the Markov renewal equation ψ=δI+ψ∗q\psi = \delta I + \psi * q. ψ\psi is the inverse of δI−q\delta I - q for the matrix convolution product, and the transition function of the semi-Markov chain is P=ψ∗(I−H)P = \psi * (I - H) (see get.P).

Value

A numeric array of dimension (s,s,k+1)(s, s, k + 1) whose slice l+1l + 1 is the matrix ψ(l)\psi(l), for l=0,…,kl = 0, \dots, k.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

get.kernel, matrixConvolution, get.H, get.P

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

q <- get.kernel(x, k = 20)
psi <- get.psi(q)
psi[, , 4]                                   # psi(3)

# psi is the sum of the n-fold convolutions of q
qn <- q
s <- array(0, dim(q)); s[, , 1] <- diag(3)    # q^(0)
for (n in 1:20) {
  s <- s + qn
  qn <- matrixConvolution(qn, q)
}
all.equal(s, psi)

Transition function PY of the chain absorbed in the down states

Description

Computes the transition function of the semi-Markov chain (Yk)k∈N(Y_k)_{k \in \mathbb{N}} absorbed in Δ\Delta at the first passage to the down states (see get.qy) (Barbu and Limnios, 2008, Proposition 5.1 and its second proof, pp. 105-106):

PY=ψY∗(I−HY),P_Y = \psi_Y * (I - H_Y),

where ψY\psi_Y and HYH_Y are computed from the kernel qYq_Y as in get.psi and get.H.

Usage

get.Py(x, k, upstates = x$states)

Arguments

x

An object of S3 class smm (smmparametric or smmnonparametric) or smmfit (see fitsmm).

k

A positive integer giving the time horizon.

upstates

Vector giving the subset of operational states UU.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, E=U∪DE = U \cup D the partition into up and down states, s1=card(U)s_1 = \textrm{card}(U), TDT_D the first passage time to DD and qYq_Y the kernel of get.qy.

For an up state i∈Ui \in U, PY(k)iΔ=P(TD≤k∣Z0=i)P_Y(k)_{i \Delta} = P(T_D \le k \mid Z_0 = i), where TDT_D is the first passage time to DD, so that the reliability of the system is

R(k)=∑i∈Uαi(1−PY(k)iΔ),R(k) = \sum_{i \in U} \alpha_i \left(1 - P_Y(k)_{i \Delta}\right),

with α\alpha the initial distribution (see reliability). The rows and columns are the up states, in the order of x$states, followed by Δ\Delta.

Value

A numeric array of dimension (s1+1,s1+1,k+1)(s_1 + 1, s_1 + 1, k + 1), where s1=card(U)s_1 = \textrm{card}(U) is the number of up states, whose slice l+1l + 1 is the matrix PY(l)P_Y(l), for l=0,…,kl = 0, \dots, k.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

get.qy, get.P, reliability

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

up <- c("a", "b")
Py <- get.Py(x, k = 10, upstates = up)
Py[, , 11]   # P_Y(10): rows/columns "a", "b", Delta

# Reliability at time 10
sum(x$init[1:2] * (1 - Py[1:2, 3, 11]))
reliability(x, k = 10, upstates = up)[11, ]

Semi-Markov kernel qY of the chain absorbed in the down states

Description

For a partition E=U∪DE = U \cup D of the state space into up states UU (upstates) and down states DD, computes the semi-Markov kernel qYq_Y of the chain (Yk)k∈N(Y_k)_{k \in \mathbb{N}} which coincides with the semi-Markov chain (Zk)k∈N(Z_k)_{k \in \mathbb{N}} up to the first passage time TDT_D to DD, and which is then absorbed in a state Δ\Delta gathering the states of DD (Barbu and Limnios, 2008, Proposition 5.1 and its second proof, pp. 105-106):

qY(k)=(q11(k)q12(k) 1s−s100),q_Y(k) = \left(\begin{array}{cc} q_{11}(k) & q_{12}(k)\, \mathbf{1}_{s - s_1} \\ \mathbf{0} & 0 \end{array}\right),

where q11q_{11} and q12q_{12} are the blocks U×UU \times U and U×DU \times D of the kernel qq, s=card(E)s = \textrm{card}(E), s1=card(U)s_1 = \textrm{card}(U) and 1s−s1\mathbf{1}_{s - s_1} is a column vector of ones.

Usage

get.qy(x, k, upstates = x$states)

Arguments

x

An object of S3 class smm (smmparametric or smmnonparametric) or smmfit (see fitsmm).

k

A positive integer giving the time horizon.

upstates

Vector giving the subset of operational states UU.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, qq its kernel, E=U∪DE = U \cup D the partition into up and down states, s1=card(U)s_1 = \textrm{card}(U) and TDT_D the first passage time to DD.

The chain (Yk)k∈N(Y_k)_{k \in \mathbb{N}} is used to compute the reliability of the system: TD>kT_D > k if and only if Yk≠ΔY_k \neq \Delta (see get.Py and reliability). The rows and columns of qYq_Y are the up states, in the order of x$states (not of upstates), followed by Δ\Delta.

Value

A numeric array of dimension (s1+1,s1+1,k+1)(s_1 + 1, s_1 + 1, k + 1), where s1=card(U)s_1 = \textrm{card}(U) is the number of up states, whose slice l+1l + 1 is the matrix qY(l)q_Y(l), for l=0,…,kl = 0, \dots, k.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

get.kernel, get.Py, reliability, failureRate

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

# Up states "a" and "b", down state "c" (gathered in Delta)
qy <- get.qy(x, k = 10, upstates = c("a", "b"))
qy[, , 3]   # q_Y(2): rows/columns "a", "b", Delta

Stationary distribution of a Markov chain

Description

Computes the stationary distribution μ\mu of a Markov chain (Zn)n∈N(Z_n)_{n \in \mathbb{N}} with transition matrix PP, i.e. the probability vector solution of μP=μ\mu P = \mu.

Usage

get.stationaryDistribution(x)

Arguments

x

An object of S3 class mm (see mm) or mmfit (see fitmm).

Details

Notation (see smmR-package for the complete description of the models): (Zn)n∈N(Z_n)_{n \in \mathbb{N}} is a Markov chain of order kk on EE, with s=card(E)s = \textrm{card}(E) and transition matrix ptrans of dimension (sk,s)(s^k, s).

For a Markov chain of order k>1k > 1, ptrans (of dimension (sk,s)(s^k, s)) is first written as the transition matrix of the Markov chain of order 1 of the words of length kk, of dimension (sk,sk)(s^k, s^k); the stationary distribution is then a distribution on these words.

The chain is assumed irreducible, so that the stationary distribution is unique. For semi-Markov chains, see get.limitDistribution.

Value

A vector of length sks^k (named with the words of length kk for k>1k > 1) giving the values of the stationary distribution; for k=1k = 1, a vector of length s=card(E)s = \textrm{card}(E).

See Also

mm, fitmm, get.limitDistribution

Examples

x <- mm(states = c("a", "b"), init = c(0.5, 0.5), k = 1,
        ptrans = matrix(c(0.9, 0.1, 0.3, 0.7), nrow = 2, byrow = TRUE))
get.stationaryDistribution(x)   # 0.75 0.25

# Order 2: distribution on the words "aa", "ab", "ba", "bb"
y <- mm(states = c("a", "b"), init = rep(1/4, 4), k = 2,
        ptrans = matrix(c(0.9, 0.1, 0.5, 0.5, 0.2, 0.8, 0.3, 0.7),
                        nrow = 4, byrow = TRUE))
get.stationaryDistribution(y)

Function to check if an object is of class mm

Description

is.mm returns TRUE if x is an object of class mm.

Usage

is.mm(x)

Arguments

x

An arbitrary R object.

Value

is.mm returns TRUE or FALSE depending on whether x is an object of class mm or not.

Examples

x <- mm(states = c("a", "b"), init = c(0.5, 0.5), k = 1,
        ptrans = matrix(c(0.9, 0.1, 0.3, 0.7), nrow = 2, byrow = TRUE))

is.mm(x)
is.mm("a")

Function to check if an object is of class mmfit

Description

is.mmfit returns TRUE if x is an object of class mmfit.

Usage

is.mmfit(x)

Arguments

x

An arbitrary R object.

Value

is.mmfit returns TRUE or FALSE depending on whether x is an object of class mmfit or not.

Examples

x <- mm(states = c("a", "b"), init = c(0.5, 0.5), k = 1,
        ptrans = matrix(c(0.9, 0.1, 0.3, 0.7), nrow = 2, byrow = TRUE))

seqs <- simulate(x, nsim = 2000, seed = 1)
est <- fitmm(sequences = seqs, states = c("a", "b"), k = 1)
is.mmfit(est)
is.mmfit(x)

Function to check if an object is of class smm

Description

is.smm returns TRUE if x is an object of class smm.

Usage

is.smm(x)

Arguments

x

An arbitrary R object.

Value

is.smm returns TRUE or FALSE depending on whether x is an object of class smm or not.

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

is.smm(x)
is.smm("a")

Function to check if an object is of class smmfit

Description

is.smmfit returns TRUE if x is an object of class smmfit.

Usage

is.smmfit(x)

Arguments

x

An arbitrary R object.

Value

is.smmfit returns TRUE or FALSE depending on whether x is an object of class smmfit or not.

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

# Estimation on a simulated sequence
seqs <- simulate(x, nsim = 5000, seed = 1)
est <- fitsmm(sequences = seqs, states = states, type.sojourn = "fi",
              distr = c("geom", "pois", "dweibull"))

is.smmfit(est)
is.smmfit(x)

Function to check if an object is of class smmnonparametric

Description

is.smmnonparametric returns TRUE if x is an object of class smmnonparametric.

Usage

is.smmnonparametric(x)

Arguments

x

An arbitrary R object.

Value

is.smmnonparametric returns TRUE or FALSE depending on whether x is an object of class smmnonparametric or not.

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

is.smmnonparametric(x)
is.smmparametric(x)

Function to check if an object is of class smmparametric

Description

is.smmparametric returns TRUE if x is an object of class smmparametric.

Usage

is.smmparametric(x)

Arguments

x

An arbitrary R object.

Value

is.smmparametric returns TRUE or FALSE depending on whether x is an object of class smmparametric or not.

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

is.smmparametric(x)
is.smmnonparametric(x)

Log-likelihood, AIC and BIC of a Markov or semi-Markov model

Description

Methods of the generic functions stats::logLik, stats::AIC and stats::BIC for the Markov and semi-Markov models of the package: models specified by the user (mm, smmparametric, smmnonparametric) and fitted models (fitmm, fitsmm).

Usage

## S3 method for class 'smmparametric'
logLik(object, ...)
## S3 method for class 'smmnonparametric'
logLik(object, ...)
## S3 method for class 'smmfit'
logLik(object, ...)
## S3 method for class 'mm'
logLik(object, ...)
## S3 method for class 'mmfit'
logLik(object, ...)

## S3 method for class 'smmparametric'
AIC(object, ...)
## S3 method for class 'smmnonparametric'
AIC(object, ...)
## S3 method for class 'smmfit'
AIC(object, ...)
## S3 method for class 'mm'
AIC(object, ...)
## S3 method for class 'mmfit'
AIC(object, ...)

## S3 method for class 'smmparametric'
BIC(object, ...)
## S3 method for class 'smmnonparametric'
BIC(object, ...)
## S3 method for class 'smmfit'
BIC(object, ...)
## S3 method for class 'mm'
BIC(object, ...)
## S3 method for class 'mmfit'
BIC(object, ...)

Arguments

object

An object of S3 class mm, mmfit, smm (smmparametric or smmnonparametric) or smmfit.

...

The argument sequences: a list of vectors representing the sequences for which the log-likelihood is computed (named ⁠sequences = ⁠ or given as the first unnamed argument). Required for the models specified by the user, optional for the fitted models.

Details

Notation (see smmR-package for the complete description of the models): L\mathcal{L} is the likelihood, KK the number of parameters of the model (see get.Kpar), nn the total length of the sequences and s=card(E)s = \textrm{card}(E).

The log-likelihood log⁡L\log \mathcal{L} is computed on the sequences given in the argument sequences. For a fitted model (class mmfit or smmfit), this argument is optional: by default, the value computed at the estimation, on the sequences used for the estimation, is returned. The information criteria are

AIC=−2log⁡L+2K,BIC=−2log⁡L+log⁡(n) K,AIC = -2 \log \mathcal{L} + 2 K, \qquad BIC = -2 \log \mathcal{L} + \log(n)\, K,

where KK is the number of parameters of the model (see get.Kpar) and nn the total length of the sequences.

For a non-parametric model censored at the end (cens.end = TRUE), the log-likelihood is the one of the Markov chain (state, backward recurrence time) (Barbu and Limnios, 2008, Proposition 6.1, p. 137). It is -Inf if the model gives a probability 0 to an observed sojourn time, for instance when the last, censored, sojourn time of a sequence is longer than all the complete sojourn times used to estimate the model.

Value

A numeric value: the log-likelihood, the AIC or the BIC.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

get.Kpar, fitsmm, fitmm

Examples

states <- c("a", "c", "g", "t")
pij <- matrix(c(0, 0.2, 0.5, 0.3,
                0.2, 0, 0.3, 0.5,
                0.3, 0.5, 0, 0.2,
                0.4, 0.2, 0.4, 0), ncol = 4, byrow = TRUE)
x <- smmparametric(states = states, init = rep(1/4, 4), ptrans = pij,
                   type.sojourn = "f", distr = "pois", param = c(2, NA))
seqs <- simulate(x, nsim = 5000, seed = 150)
est <- fitsmm(sequences = seqs, states = states, type.sojourn = "f",
              distr = "pois")

# Fitted model: value at the estimation
logLik(est)
AIC(est)
BIC(est)

# Model specified by the user: the sequences must be given
logLik(x, sequences = seqs)
AIC(x, sequences = seqs)

Maintainability Function

Description

For a reparable system S\mathcal{S} for which the failure occurs at time k=0k = 0, its maintainability at time k∈Nk \in \mathbb{N} is the probability that the system is repaired up to time kk, given that it has failed at time k=0k = 0.

Usage

maintainability(x, k, upstates = x$states, level = 0.95, klim = 10000)

Arguments

x

An object of S3 class smmfit or smm.

k

A positive integer giving the period [0,k][0, k] on which the maintainability should be computed.

upstates

Vector giving the subset of operational states UU.

level

Confidence level of the asymptotic confidence interval. Helpful for an object x of class smmfit.

klim

Optional. The time horizon used to approximate the series in the computation of the mean sojourn times vector mm (cf. meanSojournTimes function) for the asymptotic variance.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, E=U∪DE = U \cup D the partition into up and down states, s=card(E)s = \textrm{card}(E), s1=card(U)s_1 = \textrm{card}(U) and TDT_D the first passage time to DD.

Consider a system (or a component) S\mathcal{S} whose possible states during its evolution in time are E={1,…,s}E = \{1,\dots,s\}. Denote by U={1,…,s1}U = \{1,\dots,s_1\} the subset of operational states of the system (the up states) and by D={s1+1,…,s}D = \{s_1 + 1,\dots, s\} the subset of failure states (the down states), with 0<s1<s0 < s_1 < s (obviously, E=U∪DE = U \cup D and U∩D=∅U \cap D = \emptyset, U≠∅, D≠∅U \neq \emptyset,\ D \neq \emptyset). One can think of the states of UU as different operating modes or performance levels of the system, whereas the states of DD can be seen as failures of the systems with different modes.

We are interested in investigating the maintainability of a discrete-time semi-Markov system S\mathcal{S}. Consequently, we suppose that the evolution in time of the system is governed by an E-state space semi-Markov chain (Zk)k∈N(Z_k)_{k \in \mathbb{N}}. The system starts to fail at instant 00 and the state of the system is given at each instant k∈Nk \in \mathbb{N} by ZkZ_k: the event {Zk=i}\{Z_k = i\}, for a certain i∈Ui \in U, means that the system S\mathcal{S} is in operating mode ii at time kk, whereas {Zk=j}\{Z_k = j\}, for a certain j∈Dj \in D, means that the system is not operational at time kk due to the mode of failure jj or that the system is under the repairing mode jj.

Thus, we take (αi:=P(Z0=i))i∈U=0(\alpha_{i} := P(Z_{0} = i))_{i \in U} = 0 and we denote by TUT_U the first hitting time of subset UU, called the duration of repair or repair time, that is,

TU:=inf{n∈N; Zn∈U} and inf ∅:=∞.T_U := \textrm{inf}\{ n \in \mathbb{N};\ Z_n \in U\}\ \textrm{and}\ \textrm{inf}\ \emptyset := \infty.

The maintainability at time k∈Nk \in \mathbb{N} of a discrete-time semi-Markov system is

M(k)=P(TU≤k)=1−P(TU>k)=1−P(Zn∈D, n=0,…,k).M(k) = P(T_U \leq k) = 1 - P(T_{U} > k) = 1 - P(Z_{n} \in D,\ n = 0,\dots,k).

Value

A matrix with k+1k + 1 rows, and with columns giving values of the maintainability, asymptotic variances (sigma2), lower (lwr) and upper (upr) asymptotic confidence limits (if x is an object of class smmfit).

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

# Up states "a" and "b", down state "c"
maintainability(x, k = 10, upstates = c("a", "b"))

Discrete-time matrix convolution product

Description

Computes the discrete-time convolution product A∗BA * B of two matrix-valued functions AA and BB defined on N\mathbb{N} (Barbu and Limnios, 2008, Definition 3.5, p. 48):

(A∗B)(k)=∑l=0kA(k−l) B(l),k∈N,(A * B)(k) = \sum_{l = 0}^{k} A(k - l)\, B(l), \quad k \in \mathbb{N},

where A(k−l)B(l)A(k - l) B(l) is the usual matrix product.

Usage

matrixConvolution(a, b)

Arguments

a

A numeric array of dimension (s,s,k+1)(s, s, k + 1).

b

A numeric array of dimension (s,s,k+1)(s, s, k + 1).

Details

Notation (see smmR-package for the complete description of the models): s=card(E)s = \textrm{card}(E) is the number of states, and a matrix-valued function on {0,…,k}\{0, \dots, k\} is an array of dimension (s,s,k+1)(s, s, k + 1) whose slice l+1l + 1 is its value at time ll.

The slice l+1l + 1 of a (or b) is the matrix A(l)A(l) (or B(l)B(l)), for l=0,…,kl = 0, \dots, k. This is the format of the kernel returned by get.kernel and of the outputs of get.H, get.psi and get.P.

The matrix convolution product is associative but not commutative. Its neutral element is δI\delta I, i.e. the identity matrix at time 0 and the null matrix at times k>0k > 0 (Lemma 3.1, p. 48). The nn-fold convolution of the semi-Markov kernel, q(n)q^{(n)} (Definition 3.6, p. 48), is obtained by applying this function n−1n - 1 times (see get.psi).

Value

A numeric array of dimension (s,s,k+1)(s, s, k + 1) whose slice l+1l + 1 is the matrix (A∗B)(l)(A * B)(l), for l=0,…,kl = 0, \dots, k.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

convolution, get.kernel, get.psi, get.P

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

q <- get.kernel(x, k = 10)
q2 <- matrixConvolution(q, q)   # q^(2): two jumps
q2[, , 4]                       # probabilities of two jumps at time 3

Method to get the mean recurrence times μ\mu

Description

Method to get the mean recurrence times μ\mu.

Usage

meanRecurrenceTimes(x, klim = 10000)

Arguments

x

An object of S3 class smmfit or smm.

klim

Optional. The time horizon used to approximate the series in the computation of the mean sojourn times vector mm (cf. meanSojournTimes function).

Details

Notation (see smmR-package for the complete description of the models): (Jn)n∈N(J_n)_{n \in \mathbb{N}} is the embedded Markov chain, (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times, HiH_i the cumulative distribution function of the sojourn time in state ii and s=card(E)s = \textrm{card}(E).

Consider a system (or a component) S\mathcal{S} whose possible states during its evolution in time are E={1,…,s}E = \{1,\dots,s\}.

We are interested in investigating the mean recurrence times of a discrete-time semi-Markov system S\mathcal{S}. Consequently, we suppose that the evolution in time of the system is governed by an E-state space semi-Markov chain (Zk)k∈N(Z_k)_{k \in \mathbb{N}}. The state of the system is given at each instant k∈Nk \in \mathbb{N} by ZkZ_k: the event {Zk=i}\{Z_k = i\}.

Let T=(Tn)n∈NT = (T_{n})_{n \in \mathbb{N}} denote the successive time points when state changes in (Zn)n∈N(Z_{n})_{n \in \mathbb{N}} occur and let also J=(Jn)n∈NJ = (J_{n})_{n \in \mathbb{N}} denote the successively visited states at these time points.

The mean recurrence of an arbitrary state j∈Ej \in E is given by:

μjj=∑i∈Eν(i)miν(j)\mu_{jj} = \frac{\sum_{i \in E} \nu(i) m_{i}}{\nu(j)}

where (ν(1),…,ν(s))(\nu(1),\dots,\nu(s)) is the stationary distribution of the embedded Markov chain (Jn)n∈N(J_{n})_{n \in \mathbb{N}} and mim_{i} is the mean sojourn time in state i∈Ei \in E (see meanSojournTimes function for the computation).

Value

A vector giving the mean recurrence time (μi)i∈[1,…,s](\mu_{i})_{i \in [1,\dots,s]}.

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

meanRecurrenceTimes(x)

Mean Sojourn Times Function

Description

The mean sojourn time is the mean time spent in each state.

Usage

meanSojournTimes(x, states = x$states, klim = 10000)

Arguments

x

An object of S3 class smmfit or smm.

states

Vector giving the states for which the mean sojourn time should be computed. states is a subset of EE.

klim

Optional. The time horizon used to approximate the series in the computation of the mean sojourn times vector mm (cf. meanSojournTimes function).

Details

Notation (see smmR-package for the complete description of the models): (Jn)n∈N(J_n)_{n \in \mathbb{N}} is the embedded Markov chain, (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times, HiH_i the cumulative distribution function of the sojourn time in state ii and s=card(E)s = \textrm{card}(E).

Consider a system (or a component) S\mathcal{S} whose possible states during its evolution in time are E={1,…,s}E = \{1,\dots,s\}.

We are interested in investigating the mean sojourn times of a discrete-time semi-Markov system S\mathcal{S}. Consequently, we suppose that the evolution in time of the system is governed by an E-state space semi-Markov chain (Zk)k∈N(Z_k)_{k \in \mathbb{N}}. The state of the system is given at each instant k∈Nk \in \mathbb{N} by ZkZ_k: the event {Zk=i}\{Z_k = i\}.

Let T=(Tn)n∈NT = (T_{n})_{n \in \mathbb{N}} denote the successive time points when state changes in (Zn)n∈N(Z_{n})_{n \in \mathbb{N}} occur and let also J=(Jn)n∈NJ = (J_{n})_{n \in \mathbb{N}} denote the successively visited states at these time points.

The mean sojourn times vector is defined as follows:

mi=E[T1∣Z0=j]=∑k≥0(1−P(Tn+1−Tn≤k∣Jn=j))=∑k≥0(1−Hj(k)), i∈Em_{i} = E[T_{1} | Z_{0} = j] = \sum_{k \geq 0} (1 - P(T_{n + 1} - T_{n} \leq k | J_{n} = j)) = \sum_{k \geq 0} (1 - H_{j}(k)),\ i \in E

Value

A vector of length s=card(E)s = \textrm{card}(E) giving the values of the mean sojourn times for each state i∈Ei \in E.

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

meanSojournTimes(x)
meanSojournTimes(x, states = c("a", "b"))

Markov model specification

Description

Creates a model specification of a Markov model.

Usage

mm(states, init, ptrans, k = 1)

Arguments

states

Vector of state space of length s.

init

Vector of initial distribution of length s ^ k.

ptrans

Matrix of transition probabilities of dimension (s,s)(s, s).

k

Order of the Markov chain.

Details

Notation (see smmR-package for the complete description of the models): (Zn)n∈N(Z_n)_{n \in \mathbb{N}} is a Markov chain of order kk on EE, with s=card(E)s = \textrm{card}(E), initial distribution init and transition matrix ptrans of dimension (sk,s)(s^k, s).

Value

An object of class mm.

See Also

simulate.mm, fitmm

Examples

states <- c("a", "c", "g", "t")
s <- length(states)
k <- 1
init <- rep.int(1 / s, s)
p <- matrix(c(0, 0, 0.3, 0.4, 0, 0, 0.5, 0.2, 0.7, 0.5, 
              0, 0.4, 0.3, 0.5, 0.2, 0), ncol = s)

# Specify a Markov model of order 1
markov <- mm(states = states, init = init, ptrans = p, k = k)

Mean Time To Failure (MTTF) Function

Description

Consider a system S\mathcal{S} starting to work at time k=0k = 0. The mean time to failure (MTTF) is defined as the mean lifetime.

Usage

mttf(x, upstates = x$states, level = 0.95, klim = 10000)

Arguments

x

An object of S3 class smmfit or smm.

upstates

Vector giving the subset of operational states UU.

level

Confidence level of the asymptotic confidence interval. Helpful for an object x of class smmfit.

klim

Optional. The time horizon used to approximate the series in the computation of the mean sojourn times vector mm (cf. meanSojournTimes function) for the asymptotic variance.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, E=U∪DE = U \cup D the partition into up and down states, s=card(E)s = \textrm{card}(E), s1=card(U)s_1 = \textrm{card}(U) and TDT_D the first passage time to DD.

Consider a system (or a component) S\mathcal{S} whose possible states during its evolution in time are E={1,…,s}E = \{1,\dots,s\}. Denote by U={1,…,s1}U = \{1,\dots,s_1\} the subset of operational states of the system (the up states) and by D={s1+1,…,s}D = \{s_1 + 1,\dots,s\} the subset of failure states (the down states), with 0<s1<s0 < s_1 < s (obviously, E=U∪DE = U \cup D and U∩D=∅U \cap D = \emptyset, U≠∅, D≠∅U \neq \emptyset,\ D \neq \emptyset). One can think of the states of UU as different operating modes or performance levels of the system, whereas the states of DD can be seen as failures of the systems with different modes.

We are interested in investigating the mean time to failure of a discrete-time semi-Markov system S\mathcal{S}. Consequently, we suppose that the evolution in time of the system is governed by an E-state space semi-Markov chain (Zk)k∈N(Z_k)_{k \in \mathbb{N}}. The system starts to work at instant 00 and the state of the system is given at each instant k∈Nk \in \mathbb{N} by ZkZ_k: the event {Zk=i}\{Z_k = i\}, for a certain i∈Ui \in U, means that the system S\mathcal{S} is in operating mode ii at time kk, whereas {Zk=j}\{Z_k = j\}, for a certain j∈Dj \in D, means that the system is not operational at time kk due to the mode of failure jj or that the system is under the repairing mode jj.

Let TDT_D denote the first passage time in subset DD, called the lifetime of the system, i.e.,

TD:=inf{n∈N; Zn∈D} and inf ∅:=∞.T_D := \textrm{inf}\{ n \in \mathbb{N};\ Z_n \in D\}\ \textrm{and}\ \textrm{inf}\ \emptyset := \infty.

The mean time to failure (MTTF) is defined as the mean lifetime, i.e., the expectation of the hitting time to down set DD,

MTTF=E[TD]MTTF = E[T_{D}]

Value

A matrix with s1=card(U)s_1 = \textrm{card}(U) rows, and with columns giving values of the mean time to failure for each state i∈Ui \in U, asymptotic variances (sigma2), lower (lwr) and upper (upr) asymptotic confidence limits (if x is an object of class smmfit).

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

I. Votsi & A. Brouste (2019) Confidence interval for the mean time to failure in semi-Markov models: an application to wind energy production, Journal of Applied Statistics, 46:10, 1756-1773

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

# Up states "a" and "b", down state "c"
mttf(x, upstates = c("a", "b"))

# Estimation on a simulated sequence
seqs <- simulate(x, nsim = 5000, seed = 1)
est <- fitsmm(sequences = seqs, states = states, type.sojourn = "fi",
              distr = c("geom", "pois", "dweibull"))

mttf(est, upstates = c("a", "b"))

Mean Time To Repair (MTTR) Function

Description

Consider a system S\mathcal{S} that has just failed at time k=0k = 0. The mean time to repair (MTTR) is defined as the mean of the repair duration.

Usage

mttr(x, upstates = x$states, level = 0.95, klim = 10000)

Arguments

x

An object of S3 class smmfit or smm.

upstates

Vector giving the subset of operational states UU.

level

Confidence level of the asymptotic confidence interval. Helpful for an object x of class smmfit.

klim

Optional. The time horizon used to approximate the series in the computation of the mean sojourn times vector mm (cf. meanSojournTimes function) for the asymptotic variance.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, E=U∪DE = U \cup D the partition into up and down states, s=card(E)s = \textrm{card}(E), s1=card(U)s_1 = \textrm{card}(U) and TDT_D the first passage time to DD.

Consider a system (or a component) S\mathcal{S} whose possible states during its evolution in time are E={1,…,s}E = \{1,\dots,s\}. Denote by U={1,…,s1}U = \{1,\dots,s_1\} the subset of operational states of the system (the up states) and by D={s1+1,…,s}D = \{s_1 + 1,\dots,s\} the subset of failure states (the down states), with 0<s1<s0 < s_1 < s (obviously, E=U∪DE = U \cup D and U∩D=∅U \cap D = \emptyset, U≠∅, D≠∅U \neq \emptyset,\ D \neq \emptyset). One can think of the states of UU as different operating modes or performance levels of the system, whereas the states of DD can be seen as failures of the systems with different modes.

We are interested in investigating the mean time to repair of a discrete-time semi-Markov system S\mathcal{S}. Consequently, we suppose that the evolution in time of the system is governed by an E-state space semi-Markov chain (Zk)k∈N(Z_k)_{k \in \mathbb{N}}. The system has just failed at instant 0 and the state of the system is given at each instant k∈Nk \in \mathbb{N} by ZkZ_k: the event {Zk=i}\{Z_k = i\}, for a certain i∈Ui \in U, means that the system S\mathcal{S} is in operating mode ii at time kk, whereas {Zk=j}\{Z_k = j\}, for a certain j∈Dj \in D, means that the system is not operational at time kk due to the mode of failure jj or that the system is under the repairing mode jj.

Let TUT_U denote the first passage time in subset UU, called the duration of repair or repair time, i.e.,

TU:=inf{n∈N; Zn∈U} and inf ∅:=∞.T_U := \textrm{inf}\{ n \in \mathbb{N};\ Z_n \in U\}\ \textrm{and}\ \textrm{inf}\ \emptyset := \infty.

The mean time to repair (MTTR) is defined as the mean of the repair duration, i.e., the expectation of the hitting time to up set UU,

MTTR=E[TU]MTTR = E[T_{U}]

Value

A matrix with s1=card(U)s_1 = \textrm{card}(U) rows, and with columns giving values of the mean time to repair for each state i∈Ui \in U, asymptotic variances (sigma2), lower (lwr) and upper (upr) asymptotic confidence limits (if x is an object of class smmfit).

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

I. Votsi & A. Brouste (2019) Confidence interval for the mean time to failure in semi-Markov models: an application to wind energy production, Journal of Applied Statistics, 46:10, 1756-1773

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

# Up states "a" and "b", down state "c"
mttr(x, upstates = c("a", "b"))

Plot function for an object of class smm

Description

Displays the densities for the conditional sojourn time distributions depending on the current state i and on the next state j.

Usage

## S3 method for class 'smm'
plot(x, i, j, klim = NULL, ...)

Arguments

x

An object of S3 class smm (inheriting from the S3 class smmnonparametric or smmparametric).

i

An element of the state space vector x$states giving the current state in the following cases: type.sojourn = "fij" or type.sojourn = "fi", otherwise, i is ignored.

j

An element of the state space vector x$states giving the next state in the following cases: type.sojourn = "fij" or type.sojourn = "fj", otherwise, j is ignored.

klim

An integer giving the limit value for which the density will be plotted. If klim is NULL, then quantile or order 0.95 is used.

...

Arguments passed to plot.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, (Jn)n∈N(J_n)_{n \in \mathbb{N}} its embedded Markov chain (initial distribution init, transition matrix pp = ptrans), (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times, qij(k)=pijfij(k)q_{ij}(k) = p_{ij} f_{ij}(k) the semi-Markov kernel and s=card(E)s = \textrm{card}(E).

Value

None.

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

# Sojourn time distribution in state "a" before a transition to "b"
plot(x, i = "a", j = "b", klim = 15)

Plot function for an object of class smmfit

Description

Displays the densities for the conditional sojourn time distributions depending on the current state i and on the next state j.

Usage

## S3 method for class 'smmfit'
plot(x, i, j, klim = NULL, ...)

Arguments

x

An object of class smmfit (inheriting from the S3 classes smm, smmnonparametric or smmparametric).

i

An element of the state space vector x$states giving the current state in the following cases: type.sojourn = "fij" or type.sojourn = "fi", otherwise, i is ignored.

j

An element of the state space vector x$states giving the next state in the following cases: type.sojourn = "fij" or type.sojourn = "fj", otherwise, j is ignored.

klim

An integer giving the limit value for which the density will be plotted. If klim is NULL, then quantile or order 0.95 is used.

...

Arguments passed to plot.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, (Jn)n∈N(J_n)_{n \in \mathbb{N}} its embedded Markov chain (initial distribution init, transition matrix pp = ptrans), (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times, qij(k)=pijfij(k)q_{ij}(k) = p_{ij} f_{ij}(k) the semi-Markov kernel and s=card(E)s = \textrm{card}(E).

Value

None.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

Examples

states <- c("a", "c", "g", "t")
s <- length(states)

# Creation of the initial distribution
vect.init <- c(1 / 4, 1 / 4, 1 / 4, 1 / 4)

# Creation of the transition matrix
pij <- matrix(c(0, 0.2, 0.3, 0.4, 0.2, 0, 0.5, 0.2, 0.5, 
                0.3, 0, 0.4, 0.3, 0.5, 0.2, 0), ncol = s)

# Creation of the distribution matrix
distr.vec <- c("pois", "geom", "geom", "geom")
parameters <- matrix(c(2, 0.6, 0.8, 0.8, NA, NA, NA, NA), 
                     ncol = 2, byrow = FALSE)

# Specify the semi-Markov model
smm <- smmparametric(states = states, init = vect.init, ptrans = pij, 
                     type.sojourn = "fi", distr = distr.vec, param = parameters)

seqs <- simulate(object = smm, nsim = rep(5000, 100), seed = 10)

est <- fitsmm(sequences = seqs, states = states, type.sojourn = "fi", distr = distr.vec)

class(est)

plot(x = est, i = "a", col = "blue", pch = "+")

Print a Markov or semi-Markov model

Description

Methods of the generic function print for the Markov and semi-Markov models, specified (mm, smmparametric, smmnonparametric) or fitted (fitmm, fitsmm): the state space, the initial distribution, the transition matrix, the sojourn time distributions and, for a fitted model, the log-likelihood and the number of sequences and of observations.

Usage

## S3 method for class 'smm'
print(x, digits = 4, ...)
## S3 method for class 'smmfit'
print(x, digits = 4, ...)
## S3 method for class 'mm'
print(x, digits = 4, ...)
## S3 method for class 'mmfit'
print(x, digits = 4, ...)

Arguments

x

An object of S3 class mm, mmfit, smm or smmfit.

digits

Number of significant digits.

...

Not used.

Value

x, invisibly. The components of x are obtained by x$..., or listed by str(unclass(x)).

Examples

x <- smmparametric(states = c("a", "b"), init = c(0.5, 0.5),
                   ptrans = matrix(c(0, 1, 1, 0), 2),
                   type.sojourn = "fi", distr = c("geom", "pois"),
                   param = matrix(c(0.3, 2, NA, NA), 2))
x
fitsmm(simulate(x, nsim = 1000, seed = 1), c("a", "b"), "fi",
       distr = c("geom", "pois"))

Reliability Function

Description

Consider a system S\mathcal{S} starting to function at time k=0k = 0. The reliability or the survival function of S\mathcal{S} at time k∈Nk \in \mathbb{N} is the probability that the system has functioned without failure in the period [0,k][0, k].

Usage

reliability(x, k, upstates = x$states, level = 0.95, klim = 10000)

Arguments

x

An object of S3 class smmfit or smm.

k

A positive integer giving the period [0,k][0, k] on which the reliability should be computed.

upstates

Vector giving the subset of operational states UU.

level

Confidence level of the asymptotic confidence interval. Helpful for an object x of class smmfit.

klim

Optional. The time horizon used to approximate the series in the computation of the mean sojourn times vector mm (cf. meanSojournTimes function) for the asymptotic variance.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, E=U∪DE = U \cup D the partition into up and down states, s=card(E)s = \textrm{card}(E), s1=card(U)s_1 = \textrm{card}(U) and TDT_D the first passage time to DD.

Consider a system (or a component) S\mathcal{S} whose possible states during its evolution in time are E={1,…,s}E = \{1,\dots,s\}. Denote by U={1,…,s1}U = \{1,\dots,s_1\} the subset of operational states of the system (the up states) and by D={s1+1,…,s}D = \{s_1 + 1,\dots, s\} the subset of failure states (the down states), with 0<s1<s0 < s_1 < s (obviously, E=U∪DE = U \cup D and U∩D=∅U \cap D = \emptyset, U≠∅, D≠∅U \neq \emptyset,\ D \neq \emptyset). One can think of the states of UU as different operating modes or performance levels of the system, whereas the states of DD can be seen as failures of the systems with different modes.

We are interested in investigating the reliability of a discrete-time semi-Markov system S\mathcal{S}. Consequently, we suppose that the evolution in time of the system is governed by an E-state space semi-Markov chain (Zk)k∈N(Z_k)_{k \in \mathbb{N}}. The system starts to work at instant 00 and the state of the system is given at each instant k∈Nk \in \mathbb{N} by ZkZ_k: the event {Zk=i}\{Z_k = i\}, for a certain i∈Ui \in U, means that the system S\mathcal{S} is in operating mode ii at time kk, whereas {Zk=j}\{Z_k = j\}, for a certain j∈Dj \in D, means that the system is not operational at time kk due to the mode of failure jj or that the system is under the repairing mode jj.

Let TDT_D denote the first passage time in subset DD, called the lifetime of the system, i.e.,

TD:=inf{n∈N; Zn∈D} and inf ∅:=∞.T_D := \textrm{inf}\{ n \in \mathbb{N};\ Z_n \in D\}\ \textrm{and}\ \textrm{inf}\ \emptyset := \infty.

The reliability or the survival function at time k∈Nk \in \mathbb{N} of a discrete-time semi-Markov system is:

R(k):=P(TD>k)=P(Zn∈U,n=0,…,k)R(k) := P(T_D > k) = P(Zn \in U,n = 0,\dots,k)

which can be rewritten as follows:

R(k)=∑i∈UP(Z0=i)P(TD>k∣Z0=i)=∑i∈UαiP(TD>k∣Z0=i)R(k) = \sum_{i \in U} P(Z_0 = i) P(T_D > k | Z_0 = i) = \sum_{i \in U} \alpha_i P(T_D > k | Z_0 = i)

Value

A matrix with k+1k + 1 rows, and with columns giving values of the reliability, asymptotic variances (sigma2), lower (lwr) and upper (upr) asymptotic confidence limits (if x is an object of class smmfit).

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

# Up states "a" and "b", down state "c"
reliability(x, k = 10, upstates = c("a", "b"))

# Estimation on a simulated sequence
seqs <- simulate(x, nsim = 5000, seed = 1)
est <- fitsmm(sequences = seqs, states = states, type.sojourn = "fi",
              distr = c("geom", "pois", "dweibull"))

# Estimated reliability with asymptotic confidence intervals
head(reliability(est, k = 10, upstates = c("a", "b")))

Daily precipitation at Rouen-Boos (France), 1995-2024

Description

Daily precipitation measured at the Météo-France station Rouen-Boos (station number 76116001, Seine-Maritime, Normandy, France, altitude 156 m) from 1 January 1995 to 31 December 2024, without missing values.

Usage

rouenRain

Format

A data frame with 10,958 rows and 2 variables:

date

Date (class Date);

rr

Quantity of precipitation (in mm).

Details

The precipitation of day JJ is the quantity of water fallen from 06h UTC on day JJ to 06h UTC on day J+1J + 1.

Classified into dry and rainy days, the sequence of the days is a classical example of semi-Markov chain: the lengths of the dry spells are often not geometric, as a Markov chain would imply (see the example below, where the lengths of the summer dry spells are better described by a discrete Weibull distribution).

Source

Météo-France, Données climatologiques de base - quotidiennes, https://www.data.gouv.fr/datasets/donnees-climatologiques-de-base-quotidiennes/ (file ⁠Q_76_previous-1950-2024_RR-T-Vent.csv.gz⁠, field RR), Licence Ouverte / Open Licence 2.0 (Etalab), accessed on 28 November 2026.

Examples

# Summers (June to August) coded as dry ("D", less than 1 mm),
# wet ("W", from 1 to 10 mm) or heavy rain ("H", 10 mm or more) days:
# 30 sequences of 92 days
state <- cut(rouenRain$rr, breaks = c(-Inf, 1, 10, Inf), right = FALSE,
             labels = c("D", "W", "H"))
summer <- format(rouenRain$date, "%m") %in% c("06", "07", "08")
seqrain <- split(as.character(state[summer]),
                 format(rouenRain$date[summer], "%Y"))

# Semi-Markov models with sojourn times depending on the current state,
# censored at the beginning and at the end of each summer
states <- c("D", "W", "H")
geometric <- fitsmm(seqrain, states, type.sojourn = "fi",
                    distr = c("geom", "geom", "geom"),
                    cens.beg = TRUE, cens.end = TRUE)
weibull <- fitsmm(seqrain, states, type.sojourn = "fi",
                  distr = c("dweibull", "geom", "geom"),
                  cens.beg = TRUE, cens.end = TRUE)
c(geometric = AIC(geometric), weibull = AIC(weibull))

# Mean length of a summer dry spell, with a confidence interval
mttf(weibull, upstates = "D")

Set the RNG Seed from within Rcpp

Description

Set the RNG Seed from within Rcpp

Usage

setSeed(seed)

Arguments

seed

An unsigned int that is the seed one wishes to use.

Value

A set RNG scope.

Examples

set.seed(10)
x <- rnorm(5, 0, 1)
setSeed(10)
y <- rnorm(5, 0, 1)
all.equal(x, y, check.attributes = FALSE)

Simulates k-th order Markov chains

Description

Simulates k-th order Markov chains.

Usage

## S3 method for class 'mm'
simulate(object, nsim = 1, seed = NULL, ...)

Arguments

object

An object of class mm.

nsim

An integer or vector of integers (for multiple sequences) specifying the length of the sequence(s).

seed

Optional. seed for the random number generator. If no seed is given, then seed is set by using the command ⁠set.seed(round(as.numeric(Sys.time()))⁠.

...

further arguments passed to or from other methods.

Details

Notation (see smmR-package for the complete description of the models): (Zn)n∈N(Z_n)_{n \in \mathbb{N}} is a Markov chain of order kk on EE, with s=card(E)s = \textrm{card}(E), initial distribution init and transition matrix ptrans of dimension (sk,s)(s^k, s).

If nsim is a single integer then a chain of that length is produced. If nsim is a vector of integers, then length(nsim) sequences are generated with respective lengths.

Value

A list of vectors representing the sequences.

See Also

mm, fitmm

Examples

states <- c("a", "c", "g", "t")
s <- length(states)
k <- 2
init <- rep.int(1 / s ^ k, s ^ k)
p <- matrix(0.25, nrow = s ^ k, ncol = s)

# Specify a Markov model of order 1
markov <- mm(states = states, init = init, ptrans = p, k = k)

seqs <- simulate(object = markov, nsim = c(1000, 10000, 2000), seed = 150)

Simulates Markov chains

Description

Simulates sequences from a fitted Markov model.

Usage

## S3 method for class 'mmfit'
simulate(object, nsim = 1, seed = NULL, ...)

Arguments

object

An object of class mmfit.

nsim

An integer or vector of integers (for multiple sequences) specifying the length of the sequence(s).

seed

Optional. seed for the random number generator. If no seed is given, then seed is set by using the command ⁠set.seed(round(as.numeric(Sys.time()))⁠.

...

further arguments passed to or from other methods.

Details

Notation (see smmR-package for the complete description of the models): (Zn)n∈N(Z_n)_{n \in \mathbb{N}} is a Markov chain of order kk on EE, with s=card(E)s = \textrm{card}(E), initial distribution init and transition matrix ptrans of dimension (sk,s)(s^k, s).

If nsim is a single integer then a chain of that length is produced. If nsim is a vector of integers, then length(nsim) sequences are generated with respective lengths.

Value

A list of vectors representing the sequences.

See Also

mm, fitmm

Examples

x <- mm(states = c("a", "b"), init = c(0.5, 0.5), k = 1,
        ptrans = matrix(c(0.9, 0.1, 0.3, 0.7), nrow = 2, byrow = TRUE))

seqs <- simulate(x, nsim = 2000, seed = 1)
est <- fitmm(sequences = seqs, states = c("a", "b"), k = 1)

# Sequence simulated from the estimated model
head(simulate(est, nsim = 50, seed = 2)[[1]], 20)

Simulates semi-Markov chains

Description

Simulates sequences from a semi-Markov model.

Usage

## S3 method for class 'smm'
simulate(object, nsim = 1, seed = NULL, ...)

Arguments

object

An object of S3 class smm (inheriting from the S3 class smmnonparametric or smmparametric).

nsim

An integer or vector of integers (for multiple sequences) specifying the length of the sequence(s) (see Details: without censoring, the sequences can be longer).

seed

Optional. seed for the random number generator. If no seed is given, then seed is set by using the command ⁠set.seed(round(as.numeric(Sys.time()))⁠.

...

further arguments passed to or from other methods.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, (Jn)n∈N(J_n)_{n \in \mathbb{N}} its embedded Markov chain (initial distribution init, transition matrix pp = ptrans), (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times, qij(k)=pijfij(k)q_{ij}(k) = p_{ij} f_{ij}(k) the semi-Markov kernel and s=card(E)s = \textrm{card}(E).

If nsim is a single integer then one sequence is simulated; if nsim is a vector of integers, then length(nsim) sequences are simulated, nsim giving their respective lengths.

The length of the simulated sequences depends on the censoring of the model (arguments cens.beg and cens.end of smmparametric and smmnonparametric, or of fitsmm):

  • without censoring (cens.beg = FALSE and cens.end = FALSE, the default), all the sojourn times are entirely simulated, the last one included, so that a sequence can be longer than requested: it stops at the end of the sojourn in progress at the requested length;

  • with censoring at the beginning and/or at the end, the sequences have exactly the requested lengths (the first and/or the last sojourn times are cut).

Value

A list of vectors representing the sequences.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

smmparametric, smmnonparametric, fitsmm

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

# Three sequences of lengths 100, 200 and 50
seqs <- simulate(x, nsim = c(100, 200, 50), seed = 1)
lengths(seqs)
head(seqs[[1]], 20)

Simulates semi-Markov chains

Description

Simulates sequences from a fitted semi-Markov model.

Usage

## S3 method for class 'smmfit'
simulate(object, nsim = 1, seed = NULL, ...)

Arguments

object

An object of class smmfit (inheriting from the S3 classes smm, smmnonparametric or smmparametric).

nsim

An integer or vector of integers (for multiple sequences) specifying the length of the sequence(s) (see Details: without censoring, the sequences can be longer).

seed

seed for the random number generator.

...

further arguments passed to or from other methods.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, (Jn)n∈N(J_n)_{n \in \mathbb{N}} its embedded Markov chain (initial distribution init, transition matrix pp = ptrans), (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times, qij(k)=pijfij(k)q_{ij}(k) = p_{ij} f_{ij}(k) the semi-Markov kernel and s=card(E)s = \textrm{card}(E).

If nsim is a single integer then one sequence is simulated; if nsim is a vector of integers, then length(nsim) sequences are simulated, nsim giving their respective lengths.

The length of the simulated sequences depends on the censoring of the model (arguments cens.beg and cens.end of smmparametric and smmnonparametric, or of fitsmm):

  • without censoring (cens.beg = FALSE and cens.end = FALSE, the default), all the sojourn times are entirely simulated, the last one included, so that a sequence can be longer than requested: it stops at the end of the sojourn in progress at the requested length;

  • with censoring at the beginning and/or at the end, the sequences have exactly the requested lengths (the first and/or the last sojourn times are cut).

Value

A list of vectors representing the sequences.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

smmnonparametric, smmparametric, fitsmm

Examples

states <- c("a", "b", "c")
ptrans <- matrix(c(0, 0.6, 0.4,
                   0.5, 0, 0.5,
                   0.7, 0.3, 0), nrow = 3, byrow = TRUE)
param <- matrix(c(0.3, 2, 0.6,
                  NA, NA, 0.8), nrow = 3)
x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
                   ptrans = ptrans, type.sojourn = "fi",
                   distr = c("geom", "pois", "dweibull"), param = param)

# Estimation on a simulated sequence
seqs <- simulate(x, nsim = 5000, seed = 1)
est <- fitsmm(sequences = seqs, states = states, type.sojourn = "fi",
              distr = c("geom", "pois", "dweibull"))

# Sequence simulated from the estimated model
head(simulate(est, nsim = 100, seed = 2)[[1]], 20)

Non-parametric semi-Markov model specification

Description

Creates a non-parametric model specification for a semi-Markov model.

Usage

smmnonparametric(
  states,
  init,
  ptrans,
  type.sojourn = c("fij", "fi", "fj", "f"),
  distr,
  cens.beg = FALSE,
  cens.end = FALSE
)

Arguments

states

Vector of state space of length ss.

init

Vector of initial distribution of length ss.

ptrans

Matrix of transition probabilities of the embedded Markov chain J=(Jm)mJ=(J_m)_{m} of dimension (s,s)(s, s).

type.sojourn

Type of sojourn time (for more explanations, see Details).

distr
  • Array of dimension (s,s,kmax)(s, s, kmax) if type.sojourn = "fij";

  • Matrix of dimension (s,kmax)(s, kmax) if type.sojourn = "fi" or "fj";

  • Vector of length kmaxkmax if the type.sojourn = "f".

kmaxkmax is the maximum length of the sojourn times.

cens.beg

Optional. A logical value indicating whether or not sequences are censored at the beginning.

cens.end

Optional. A logical value indicating whether or not sequences are censored at the end.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, (Jn)n∈N(J_n)_{n \in \mathbb{N}} its embedded Markov chain (initial distribution init, transition matrix pp = ptrans), (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times, qij(k)=pijfij(k)q_{ij}(k) = p_{ij} f_{ij}(k) the semi-Markov kernel and s=card(E)s = \textrm{card}(E).

This function creates a semi-Markov model object in the non-parametric case, taking into account the type of sojourn time and the censoring described in references. The non-parametric specification concerns sojourn time distributions defined by the user.

The difference between the Markov model and the semi-Markov model concerns the modeling of the sojourn time. With a Markov chain, the sojourn time distribution is modeled by a Geometric distribution (in discrete time). With a semi-Markov chain, the sojourn time can be any arbitrary distribution.

We define :

  • the semi-Markov kernel qij(k)=P(Jm+1=j,Tm+1−Tm=k∣Jm=i)q_{ij}(k) = P( J_{m+1} = j, T_{m+1} - T_{m} = k | J_{m} = i );

  • the transition matrix (ptrans(i,j))i,j∈states(p_{trans}(i,j))_{i,j} \in states of the embedded Markov chain J=(Jm)mJ = (J_m)_m, ptrans(i,j)=P(Jm+1=j∣Jm=i)p_{trans}(i,j) = P( J_{m+1} = j | J_m = i );

  • the initial distribution μi=P(J1=i)=P(Z1=i)\mu_i = P(J_1 = i) = P(Z_1 = i), i∈1,2,…,si \in 1, 2, \dots, s;

  • the conditional sojourn time distributions (fij(k))i,j∈states, k∈N, fij(k)=P(Tm+1−Tm=k∣Jm=i,Jm+1=j)(f_{ij}(k))_{i,j} \in states,\ k \in \mathbb{N} ,\ f_{ij}(k) = P(T_{m+1} - T_m = k | J_m = i, J_{m+1} = j ), f is specified by the argument distr in the non-parametric case.

In this package we can choose different types of sojourn time. Four options are available for the sojourn times:

  • depending on the present state and on the next state (fijf_{ij});

  • depending only on the present state (fif_{i});

  • depending only on the next state (fjf_{j});

  • depending neither on the current, nor on the next state (ff).

Let define kmaxkmax the maximum length of the sojourn times. If type.sojourn = "fij", distr is an array of dimension (s,s,kmax)(s, s, kmax). If type.sojourn = "fi" or "fj", distr must be a matrix of dimension (s,kmax)(s, kmax). If type.sojourn = "f", distr must be a vector of length kmaxkmax.

If the sequence is censored at the beginning and/or at the end, cens.beg must be equal to TRUE and/or cens.end must be equal to TRUE. All the sequences must be censored in the same way.

Value

Returns an object of class smm, smmnonparametric.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

simulate, fitsmm, smmparametric

Examples

states <- c("a", "c", "g", "t")
s <- length(states)

# Creation of the initial distribution
vect.init <- c(1 / 4, 1 / 4, 1 / 4, 1 / 4)

# Creation of the transition matrix
pij <- matrix(c(0, 0.2, 0.5, 0.3, 
                0.2, 0, 0.3, 0.5, 
                0.3, 0.5, 0, 0.2, 
                0.4, 0.2, 0.4, 0), 
              ncol = s, byrow = TRUE)

# Creation of a matrix corresponding to the 
# conditional sojourn time distributions
kmax <- 6
nparam.matrix <- matrix(c(0.2, 0.1, 0.3, 0.2, 
                          0.2, 0, 0.4, 0.2, 
                          0.1, 0, 0.2, 0.1, 
                          0.5, 0.3, 0.15, 0.05, 
                          0, 0, 0.3, 0.2, 
                          0.1, 0.2, 0.2, 0), 
                        nrow = s, ncol = kmax, byrow = TRUE)

semimarkov <- smmnonparametric(states = states, init = vect.init, ptrans = pij, 
                               type.sojourn = "fj", distr = nparam.matrix)

semimarkov

Parametric semi-Markov model specification

Description

Creates a parametric model specification for a semi-Markov model.

Usage

smmparametric(
  states,
  init,
  ptrans,
  type.sojourn = c("fij", "fi", "fj", "f"),
  distr,
  param,
  cens.beg = FALSE,
  cens.end = FALSE
)

Arguments

states

Vector of state space of length ss.

init

Vector of initial distribution of length ss.

ptrans

Matrix of transition probabilities of the embedded Markov chain J=(Jm)mJ=(J_m)_{m} of dimension (s,s)(s, s).

type.sojourn

Type of sojourn time (for more explanations, see Details).

distr
  • Matrix of distributions of dimension (s,s)(s, s) if type.sojourn = "fij";

  • Vector of distributions of length ss if type.sojourn = "fi" or ⁠"fj⁠;

  • A distribution if type.sojourn = "f".

where the distributions to be used can be one of unif, geom, pois, dweibull or nbinom.

param

Parameters of sojourn time distributions:

  • Array of distribution parameters of dimension (s,s,2)(s, s, 2) (2 corresponds to the maximal number of distribution parameters) if type.sojourn = "fij";

  • Matrix of distribution parameters of dimension (s,2)(s, 2) if type.sojourn = "fi" or "fj";

  • Vector of distribution parameters of length 2 if type.sojourn = "f".

When parameters/values are not necessary (e.g. the Poisson distribution has only one parameter that is λ\lambda, leave the value NA for the second parameter in the argument param).

cens.beg

Optional. A logical value indicating whether or not sequences are censored at the beginning.

cens.end

Optional. A logical value indicating whether or not sequences are censored at the end.

Details

Notation (see smmR-package for the complete description of the models): (Zk)k∈N(Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, (Jn)n∈N(J_n)_{n \in \mathbb{N}} its embedded Markov chain (initial distribution init, transition matrix pp = ptrans), (Xn)n∈N∗(X_n)_{n \in \mathbb{N}^*} the sojourn times, qij(k)=pijfij(k)q_{ij}(k) = p_{ij} f_{ij}(k) the semi-Markov kernel and s=card(E)s = \textrm{card}(E).

This function creates a semi-Markov model object in the parametric case, taking into account the type of sojourn time and the censoring described in references. For the parametric specification, several discrete distributions are considered (see below).

The difference between the Markov model and the semi-Markov model concerns the modeling of the sojourn time. With a Markov chain, the sojourn time distribution is modeled by a Geometric distribution (in discrete time). With a semi-Markov chain, the sojourn time can be any arbitrary distribution. In this package, the available distribution for a semi-Markov model are :

  • Uniform: f(x)=1/nf(x) = 1/n for a≤x≤ba \le x \le b, with n=b−a+1n = b-a+1;

  • Geometric: f(x)=θ(1−θ)xf(x) = \theta (1-\theta)^x for x=0,1,2,…,nx = 0, 1, 2,\ldots,n, 0<θ<10 < \theta < 1, with n>0n > 0 and θ\theta is the probability of success;

  • Poisson: f(x)=(λxexp(−λ))/x!f(x) = (\lambda^x exp(-\lambda))/x! for x=0,1,2,…,nx = 0, 1, 2,\ldots,n, with n>0n > 0 and λ>0\lambda > 0;

  • Discrete Weibull of type 1: f(x)=q(x−1)β−qxβ,x=1,2,3,…,nf(x)=q^{(x-1)^{\beta}}-q^{x^{\beta}}, x=1,2,3,\ldots,n, with n>0n > 0, qq is the first parameter and β\beta is the second parameter;

  • Negative binomial: f(x)=Γ(x+α)Γ(α)x!pα(1−p)xf(x)=\frac{\Gamma(x+\alpha)}{\Gamma(\alpha) x!} p^{\alpha} (1 - p)^x, for x=0,1,2,…,nx = 0, 1, 2,\ldots,n, Γ\Gamma is the Gamma function, α\alpha is the parameter of overdispersion and pp is the probability of success, 0<p<10 < p < 1;

  • Non-parametric.

We define :

  • the semi-Markov kernel qij(k)=P(Jm+1=j,Tm+1−Tm=k∣Jm=i)q_{ij}(k) = P( J_{m+1} = j, T_{m+1} - T_{m} = k | J_{m} = i );

  • the transition matrix (ptrans(i,j))i,j∈states(p_{trans}(i,j))_{i,j} \in states of the embedded Markov chain J=(Jm)mJ = (J_m)_m, ptrans(i,j)=P(Jm+1=j∣Jm=i)p_{trans}(i,j) = P( J_{m+1} = j | J_m = i );

  • the initial distribution μi=P(J1=i)=P(Z1=i)\mu_i = P(J_1 = i) = P(Z_1 = i), i∈1,2,…,si \in 1, 2, \dots, s;

  • the conditional sojourn time distributions (fij(k))i,j∈states, k∈N, fij(k)=P(Tm+1−Tm=k∣Jm=i,Jm+1=j)(f_{ij}(k))_{i,j} \in states,\ k \in \mathbb{N} ,\ f_{ij}(k) = P(T_{m+1} - T_m = k | J_m = i, J_{m+1} = j ), ff is specified by the argument param in the parametric case.

In this package we can choose different types of sojourn time. Four options are available for the sojourn times:

  • depending on the present state and on the next state (fijf_{ij});

  • depending only on the present state (fif_{i});

  • depending only on the next state (fjf_{j});

  • depending neither on the current, nor on the next state (ff).

If type.sojourn = "fij", distr is a matrix of dimension (s,s)(s, s) (e.g., if the row 1 of the 2nd column is "pois", that is to say we go from the first state to the second state following a Poisson distribution). If type.sojourn = "fi" or "fj", distr must be a vector (e.g., if the first element of vector is "geom", that is to say we go from the first state to any state according to a Geometric distribution). If type.sojourn = "f", distr must be one of "unif", "geom", "pois", "dweibull", "nbinom" (e.g., if distr is equal to "nbinom", that is to say that the sojourn times when going from any state to any state follows a Negative Binomial distribution). For the non-parametric case, distr is equal to "nonparametric" whatever type of sojourn time given.

If the sequence is censored at the beginning and/or at the end, cens.beg must be equal to TRUE and/or cens.end must be equal to TRUE. All the sequences must be censored in the same way.

Value

Returns an object of class smmparametric.

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

simulate, fitsmm, smmnonparametric

Examples

states <- c("a", "c", "g", "t")
s <- length(states)

# Creation of the initial distribution
vect.init <- c(1 / 4, 1 / 4, 1 / 4, 1 / 4)

# Creation of the transition matrix
pij <- matrix(c(0, 0.2, 0.5, 0.3,
                0.2, 0, 0.3, 0.5,
                0.3, 0.5, 0, 0.2,
                0.4, 0.2, 0.4, 0),
              ncol = s, byrow = TRUE)

# Creation of the distribution matrix

distr.matrix <- matrix(c(NA, "pois", "geom", "nbinom",
                         "geom", NA, "pois", "dweibull",
                         "pois", "pois", NA, "geom",
                         "pois", "geom", "geom", NA),
                       nrow = s, ncol = s, byrow = TRUE)

# Creation of an array containing the parameters
param1.matrix <- matrix(c(NA, 2, 0.4, 4,
                          0.7, NA, 5, 0.6,
                          2, 3, NA, 0.6,
                          4, 0.3, 0.4, NA),
                        nrow = s, ncol = s, byrow = TRUE)

param2.matrix <- matrix(c(NA, NA, NA, 0.6,
                          NA, NA, NA, 0.8,
                          NA, NA, NA, NA,
                          NA, NA, NA, NA),
                        nrow = s, ncol = s, byrow = TRUE)

param.array <- array(c(param1.matrix, param2.matrix), c(s, s, 2))

# Specify the semi-Markov model
semimarkov <- smmparametric(states = states, init = vect.init, ptrans = pij, 
                            type.sojourn = "fij", distr = distr.matrix, 
                            param = param.array)
semimarkov

Summary of a fitted Markov or semi-Markov model

Description

Methods of the generic function summary for the fitted Markov and semi-Markov models (fitmm, fitsmm): the table of the estimated coefficients with their standard errors (see coef.smm and vcov.smmfit), the log-likelihood, the AIC and the BIC.

Usage

## S3 method for class 'smmfit'
summary(object, ...)
## S3 method for class 'mmfit'
summary(object, ...)
## S3 method for class 'summary.smmfit'
print(x, digits = 4, ...)
## S3 method for class 'summary.mmfit'
print(x, digits = 4, ...)

Arguments

object

An object of S3 class mmfit or smmfit.

...

Not used.

x

An object of class summary.smmfit or summary.mmfit.

digits

Number of significant digits.

Value

An object of class summary.smmfit or summary.mmfit, a list with the components model (description of the model), coefficients (matrix with the columns Estimate and ⁠Std. Error⁠; NULL for a non-parametric semi-Markov model), nseq (number of sequences), nobs, logLik, AIC and BIC.

See Also

coef.smm, vcov.smmfit, logLik.smmfit

Examples

x <- smmparametric(states = c("a", "b", "c"), init = rep(1/3, 3),
                   ptrans = matrix(c(0, 0.6, 0.4, 0.5, 0, 0.5, 0.7, 0.3, 0),
                                   3, byrow = TRUE),
                   type.sojourn = "fi", distr = c("geom", "pois", "dweibull"),
                   param = matrix(c(0.3, 2, 0.6, NA, NA, 0.8), nrow = 3))
seqs <- simulate(x, nsim = 5000, seed = 1)
est <- fitsmm(seqs, c("a", "b", "c"), "fi", distr = c("geom", "pois", "dweibull"))
summary(est)