backward {regmhmm} | R Documentation |
Probability Calculation using the Backward Algorithm for Hidden Markov Models
Description
Calculate the probability given parameters of a hidden Markov model utilizing the backward algorithm.
Usage
backward(delta, Y, A, B, X, family)
Arguments
delta |
a vector of length S specifying the initial probabilities. |
Y |
a vector of observations of size T. |
A |
a matrix of size S x S specifying the transition probabilities. |
B |
a matrix of size S x (p + 1) specifying the GLM parameters of the emission probabilities. |
X |
a design matrix of size T x p. |
family |
the family of the response. |
Value
A matrix of size S x T that is the backward probabilities in log scale.
Examples
# Example usage of the function
parameters_setting <- list()
parameters_setting$emis_mat <- matrix(NA, nrow = 2, ncol = 4)
parameters_setting$emis_mat[1, 1] <- 0.1
parameters_setting$emis_mat[1, 2] <- 0.5
parameters_setting$emis_mat[1, 3] <- -0.75
parameters_setting$emis_mat[1, 4] <- 0.75
parameters_setting$emis_mat[2, 1] <- -0.1
parameters_setting$emis_mat[2, 2] <- -0.5
parameters_setting$emis_mat[2, 3] <- 0.75
parameters_setting$emis_mat[2, 4] <- 1
parameters_setting$trans_mat <- matrix(NA, nrow = 2, ncol = 2)
parameters_setting$trans_mat[1, 1] <- 0.65
parameters_setting$trans_mat[1, 2] <- 0.35
parameters_setting$trans_mat[2, 1] <- 0.2
parameters_setting$trans_mat[2, 2] <- 0.8
parameters_setting$init_vec <- c(0.65, 0.35)
simulated_data <- simulate_HMM_data(
seed_num = 1,
p_noise = 7,
N = 100,
N_persub = 10,
parameters_setting = parameters_setting
)
backward_C <- backward(
delta = parameters_setting$init_vec,
Y = simulated_data$y_mat[1, ],
A = parameters_setting$trans_mat,
B = parameters_setting$emis_mat,
X = simulated_data$X_array[, 1:4, 1],
family = "P"
)
[Package regmhmm version 1.0.0 Index]