Learn R Programming

RcppHMM (version 1.0.1)

generateObservations: Generate observations given a model

Description

Function used to generate observations given a hidden Markov model.

Usage

generateObservations(hmm, length)

Arguments

hmm

a list that contains all the necesary variables to define a hidden Markov model.

length

a value that sets how many observations to be generated.

Value

A "list" that contains the generated observations and the hidden state that generated it.

X

a vector with path of hidden states traversed.

Y

a vector with the generated observations.

Examples

Run this code
# NOT RUN {
# Set the model parameters
n <- c("First","Second")
m <- c("A","T","C","G")
A <- matrix(c(0.8,0.2,
              0.1,0.9),
            nrow = 2,
            byrow = TRUE)

B <- matrix(c(0.2, 0.2, 0.3, 0.3,
              0.4, 0.4, 0.1, 0.1),
            nrow = 2,
            byrow = TRUE)

Pi <- c(0.5, 0.5)

params <- list( "Model" = "HMM",
                "StateNames" = n,
                "ObservationNames" = m,
                "A" = A,
                "B" = B,
                "Pi" = Pi)

HMM <- verifyModel(params)

# Data simulation
set.seed(100)
length <- 100
observationSequence <- generateObservations(HMM, length)
# }

Run the code above in your browser using DataLab