# Example with 3 states, normal observations
J <- 3
# HMM transition matrix
Pi <- matrix(c(0.8, 0.15, 0.05,
0.1, 0.7, 0.2,
0.2, 0.3, 0.5), nrow = 3, byrow = TRUE)
# Observation parameters (normal distribution)
obspar <- list(
mean = c(-2, 0, 3),
sd = c(0.5, 1, 1.5)
)
# Generate 200 observations
sim_data <- generateHMM(n = 200, J = J, obsdist = "norm",
obspar = obspar, Pi = Pi)
# View the results
head(sim_data$x) # observations
head(sim_data$state) # hidden states
length(sim_data$x) # number of observations
Run the code above in your browser using DataLab