hmm.discnp (version 0.2-4)

sim.hmm: Simulate discrete data from a hidden Markov model.

Description

Simulates one or more replicates of discrete data from a model such as is fitted by the function hmm().

Usage

sim.hmm(nsim,tpm,Rho,ispd=NULL,yval=NULL,verb=FALSE)

Arguments

nsim

Vector of the lengths of the sequences of observations to be generated.

tpm

The transition probability matrix for the underlying hidden Markov chain(s). Note that the rows of tpm must sum to 1. Ignored if ncol(Rho)==1.

Rho

A matrix specifying the probability of an observation taking on one of a set of possible values, given the state of the underlying hidden Markov chain. Note that the columns of Rho must sum to 1. If ncol(Rho)==1 the simulated data are i.i.d. from the distribution specified by the single column of Rho.

ispd

A vector specifying the initial state probability distribution of the chain. If this is not specified it is taken to be the stationary distribution of the chain, calculated from tpm.

yval

Vector of numbers or character strings constituting the possible values of the observations. If not supplied it is taken to equal 1:nrow(Rho).

verb

Logical scalar. If TRUE then the overall index of the simulated value that has been reached is printed out every 1000 iterations. Useful for reassurance when very “large” simulations are undertaken.

Value

If length(nsim)==1 then the value returned is a vector of length nsim. If length(nsim)>1 then the value returned is a list of the same length as nsim, each component of which is an independent vector of simulated observations. The length of component i of this list is equal to nsim[i]. The values of the observations are entries of yval.

See Also

hmm()

Examples

Run this code
# NOT RUN {
P <- matrix(c(0.7,0.3,0.1,0.9),2,2,byrow=TRUE)
R <- matrix(c(0.5,0,0.1,0.1,0.3,
              0.1,0.1,0,0.3,0.5),5,2)
set.seed(42)
lll   <- sample(250:350,20,TRUE)
y.num <- sim.hmm(lll,P,R)
y.let <- sim.hmm(lll,P,R,yval=letters[1:5])
# }

Run the code above in your browser using DataCamp Workspace