sampleHMM function

Sample hidden Markov models

Sample hidden Markov models

This function draws independent random samples of an hidden Markov model.

sampleHMM(pInit, Q, pEmit, n = 1)

Arguments

  • pInit: an array of length K, containing the marginal distribution of the states for the first variable.
  • Q: an array of size (p-1,K,K), containing a list of p-1 transition matrices between the K states of the Markov chain.
  • pEmit: an array of size (p,M,K), containing the emission probabilities for each of the M possible emission states, from each of the K hidden states and the p variables.
  • n: the number of independent samples to be drawn (default: 1).

Returns

A matrix of size n-by-p containing the n observed Markov chains of length p.

Details

Each element of the output matrix is an integer value between 0 and K-1. The transition matrices contained in Q are defined with the same convention as in sampleDMC . The emission propability matrices contained in pEmit are defined such that P[Xj=kHj=l]=pEmit[j,k,l]P[X_{j}=k|H_{j}=l]=\mathrm{pEmit}[j,k,l], where HjH_j is the latent variable associated to XjX_j.

Examples

p=10; K=5; M=3; pInit = rep(1/K,K) Q = array(stats::runif((p-1)*K*K),c(p-1,K,K)) for(j in 1:(p-1)) { Q[j,,] = Q[j,,] / rowSums(Q[j,,]) } pEmit = array(stats::runif(p*M*K),c(p,M,K)) for(j in 1:p) { pEmit[j,,] = pEmit[j,,] / rowSums(pEmit[j,,]) } X = sampleHMM(pInit, Q, pEmit, n=20)

References

Rdpack::insert_ref(key="sesia2019",package="SNPknock")

See Also

Other models: sampleDMC

  • Maintainer: Matteo Sesia
  • License: GPL-3
  • Last published: 2019-05-17