simulate.mmfit: Simulates Markov chains

View source: R/mmfit.R

simulate.mmfitR Documentation

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): (Z_n)_{n \in \mathbb{N}} is a Markov chain of order k on E, with s = \textrm{card}(E), initial distribution init and transition matrix ptrans of dimension (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)


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