Skip to contents

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 \(s\).

init

Vector of initial distribution of length \(s\).

ptrans

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

type.sojourn

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

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

  • Vector of distributions of length \(s\) 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)\) (2 corresponds to the maximal number of distribution parameters) if type.sojourn = "fij";

  • Matrix of distribution parameters of dimension \((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.

Value

Returns an object of class smmparametric.

Details

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/n\) for \(a \le x \le b\), with \(n = b-a+1\);

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

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

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

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

  • Non-parametric.

We define :

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

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

  • the initial distribution \(\mu_i = P(J_1 = i) = P(Z_1 = i)\), \(i \in 1, 2, \dots, s\);

  • the conditional sojourn time distributions \((f_{ij}(k))_{i,j} \in states,\ k \in N ,\ f_{ij}(k) = P(T_{m+1} - T_m = k | J_m = i, J_{m+1} = j )\), \(f\) 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 (\(f_{ij}\));

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

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

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

If type.sojourn = "fij", distr is a matrix of dimension \((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.

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.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
#> $states
#> [1] "a" "c" "g" "t"
#> 
#> $s
#> [1] 4
#> 
#> $init
#>    a    c    g    t 
#> 0.25 0.25 0.25 0.25 
#> 
#> $type.sojourn
#> [1] "fij"
#> 
#> $ptrans
#>     a   c   g   t
#> a 0.0 0.2 0.5 0.3
#> c 0.2 0.0 0.3 0.5
#> g 0.3 0.5 0.0 0.2
#> t 0.4 0.2 0.4 0.0
#> 
#> $distr
#>   a      c      g      t         
#> a NA     "pois" "geom" "nbinom"  
#> c "geom" NA     "pois" "dweibull"
#> g "pois" "pois" NA     "geom"    
#> t "pois" "geom" "geom" NA        
#> 
#> $param
#> , , 1
#> 
#>     a   c   g   t
#> a  NA 2.0 0.4 4.0
#> c 0.7  NA 5.0 0.6
#> g 2.0 3.0  NA 0.6
#> t 4.0 0.3 0.4  NA
#> 
#> , , 2
#> 
#>    a  c  g   t
#> a NA NA NA 0.6
#> c NA NA NA 0.8
#> g NA NA NA  NA
#> t NA NA NA  NA
#> 
#> 
#> $cens.beg
#> [1] FALSE
#> 
#> $cens.end
#> [1] FALSE
#> 
#> attr(,"class")
#> [1] "smm"           "smmparametric"