R/simulateHMM.R

Defines functions simulateHMM

Documented in simulateHMM

#' Simulate a hidden Markov model path (HMM)
#'
#' This function simulates a HMM path of size 'M' given a matrix of transition probabilities 'gamma'. By default, the path always begins at the first state of the HMM.
#'
#' @param gamma a square matrix of transition probabiltiies such that all(rowSums(P)==1) is TRUE
#' @param M length of the HMM path
#'
#' @return A vector of integers of length 'M' representing states of the HMM
#'
#' @author Pedro L. Baldoni, \email{pedrobaldoni@gmail.com}
#' @references \url{https://github.com/plbaldoni/mixNBHMM}
#'
#' @examples
#' rle(simulateHMM(gamma = matrix(c(0.95,0.05,0.05,0.95),2,2),M = 1e4))
#'
#' @export
#'
simulateHMM = function(gamma,M){
    if(!all(rowSums(gamma)==1)){
        stop('The argument gamma must be a matrix such that all(rowSums(gamma)==1)==T')
    } else{
        return(generateHMM(gamma,M))
    }
}
plbaldoni/mixNBHMM documentation built on Dec. 24, 2019, 1:31 p.m.