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 'P'. By default, the path always begins at the first state of the HMM.
#'
#' @param P 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/mixHMM}
#'
#' @examples
#' rle(simulateHMM(P = matrix(c(0.95,0.05,0.05,0.95),2,2),m = 1e4))
#'
#' @export
#'
simulateHMM = function(P,m){
    return(generateHMM(P,m))
}
plbaldoni/mixHMM documentation built on Nov. 8, 2019, 8:05 p.m.