Employ this function to fit a Hidden Markov Model (HMM) to the provided data. It iteratively estimates model parameters using the EM algorithm.
HMM_C_raw(
delta,
Y_mat,
A,
B,
X_cube,
family,
eps = 1e-05,
eps_IRLS = 1e-04,
N_iter = 1000L,
max_N_IRLS = 300L,
trace = 0L
)
A list object with the following slots:
the estimate of delta.
the estimate of A.
the estimate of B.
the log-likelihood of the model.
a vector of length S specifying the initial probabilities.
a matrix of observations of size N x T.
a matrix of size S x S specifying the transition probabilities.
a matrix of size S x (p + 1) specifying the GLM parameters of the emission probabilities.
a design array of size T x p x N.
the family of the response.
convergence tolerance in the EM algorithm for fitting HMM.
convergence tolerance in the iteratively reweighted least squares step.
the maximal number of the EM algorithm for fitting HMM.
the maximal number of IRLS iterations.
logical indicating if detailed output should be produced during the fitting process.
# Example usage of the function
seed_num <- 1
p_noise <- 2
N <- 100
N_persub <- 10
parameters_setting <- list(
init_vec = c(0.5, 0.5),
trans_mat = matrix(c(0.7, 0.3, 0.2, 0.8), nrow = 2, byrow = TRUE),
emis_mat = matrix(c(1, 0.5, 0.5, 2), nrow = 2, byrow = TRUE)
)
simulated_data <- simulate_HMM_data(seed_num, p_noise, N, N_persub, parameters_setting)
init_start = c(0.5, 0.5)
trans_start = matrix(c(0.5, 0.5, 0.5, 0.5), nrow = 2)
emis_start = matrix(rep(1, 8), nrow = 2)
HMM_fit_raw <- HMM_C_raw(delta=as.matrix(init_start),
Y_mat=simulated_data$y_mat,
A=trans_start,
B=emis_start,
X_cube=simulated_data$X_array,
family="P",
eps=1e-4,
trace = 0
)
Run the code above in your browser using DataLab