simulate.smmfit: Simulates semi-Markov chains

View source: R/smmfit.R

simulate.smmfitR Documentation

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): (Z_k)_{k \in \mathbb{N}} is the semi-Markov chain, (J_n)_{n \in \mathbb{N}} its embedded Markov chain (initial distribution init, transition matrix p = ptrans), (X_n)_{n \in \mathbb{N}^*} the sojourn times, q_{ij}(k) = p_{ij} f_{ij}(k) the semi-Markov kernel and 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)


smmR documentation built on Nov. 28, 2026, 1:06 a.m.