###### Example using package example data, see ?nonverbal
# specifying general model properties:
m <- 3
# specifying manual values for RW metropolis sampler on gamma
gamma_int_mle0 <- matrix(c( -2, -2,
2, 0,
0, 3), byrow = TRUE, nrow = m, ncol = m - 1)
gamma_scalar <- c(2)
gamma_w <- c(0.2)
manual_gamma_sampler <- pd_RW_gamma(m = m, gamma_int_mle0 = gamma_int_mle0,
gamma_scalar = gamma_scalar,
gamma_w = gamma_w)
# specifying starting values
n_dep <- 4
q_emiss <- c(3, 2, 3, 2)
start_TM <- diag(.7, m)
start_TM[lower.tri(start_TM) | upper.tri(start_TM)] <- .1
start_EM <- list(matrix(c(0.05, 0.90, 0.05,
0.90, 0.05, 0.05,
0.55, 0.45, 0.05), byrow = TRUE,
nrow = m, ncol = q_emiss[1]), # vocalizing patient
matrix(c(0.1, 0.9,
0.1, 0.9,
0.1, 0.9), byrow = TRUE, nrow = m,
ncol = q_emiss[2]), # looking patient
matrix(c(0.90, 0.05, 0.05,
0.05, 0.90, 0.05,
0.55, 0.45, 0.05), byrow = TRUE,
nrow = m, ncol = q_emiss[3]), # vocalizing therapist
matrix(c(0.1, 0.9,
0.1, 0.9,
0.1, 0.9), byrow = TRUE, nrow = m,
ncol = q_emiss[4])) # looking therapist
# Note that for reasons of running time, J is set at a ridiculous low value.
# One would typically use a number of iterations J of at least 1000,
# and a burn_in of 200.
# \donttest{
out_3st_RWgamma <- mHMM(s_data = nonverbal,
gen = list(m = m, n_dep = n_dep, q_emiss = q_emiss),
start_val = c(list(start_TM), start_EM),
gamma_sampler = manual_gamma_sampler,
mcmc = list(J = 11, burn_in = 5))
out_3st_RWgamma
summary(out_3st_RWgamma)
# checking acceptance rate (for illustrative purposes, in the example,
# J is too low for getting a fair indication)
J_it <- 11 - 1 # accept/reject starts at iteration 2 of MCMC algorithm
out_3st_RWgamma$gamma_naccept / J_it
# average acceptance rate over all subjects per parameter
apply(out_3st_RWgamma$gamma_naccept / J_it, 2, mean)
# }
# \dontshow{
out_3st_RWgamma <- mHMM(s_data = nonverbal,
gen = list(m = m, n_dep = n_dep, q_emiss = q_emiss),
start_val = c(list(start_TM), start_EM),
gamma_sampler = manual_gamma_sampler,
mcmc = list(J = 5, burn_in = 3))
# }
Run the code above in your browser using DataLab