Forward-Backward Algorithm to Calculate the Posterior Probabilities of Hidden States in Normal Model
Source:R/MCMC_normal.R
posterior_prob_normal.Rd
Forward-Backward Algorithm to Calculate the Posterior Probabilities of Hidden States in Normal Model
Value
List with the following elements:
F
: auxiliary forward variablesB
: auxiliary backward variabless
: weights
Details
Please see supplementary information at doi:10.1186/s12859-024-05751-4 for more details on the algorithm.
Examples
prior_mat <- rbind(c(1-0.05, 0.05, 0),
c(0.05, 1-0.1, 0.05),
c(0, 0.05, 1-0.05))
prior_means <- c(-0.1, 0.0, 0.1)
prior_sd <- sqrt(0.1)
L <- 100
# Simulate HMM model based on normal data based on prior information
sim_data_normal <- hmm_simulate_normal_data(L = L,
mat_T = prior_mat,
means = prior_means,
sigma = prior_sd)
pi <- sim_data_normal$pi
# pi <- get_pi(prior_mat)
hmm_norm_data <- sim_data_normal$data
# Calculate posterior probabilities of hidden states
post_prob <- posterior_prob_normal(data = hmm_norm_data,
pi = pi,
mat_T = prior_mat,
means = prior_means,
sdev = prior_sd)
str(post_prob)
#> List of 3
#> $ F: num [1:100, 1:3] 0.363 0.358 0.213 0.372 0.386 ...
#> $ B: num [1:100, 1:3] 1.51 1.49 7.26 6.28 1.59 ...
#> $ s: num [1:100] 1.157 1.221 0.433 0.307 1.207 ...