plot.mHMM_gamma: Plotting the transition probabilities gamma for a fitted...

View source: R/plot.mHMM_gamma.R

plot.mHMM_gammaR Documentation

Plotting the transition probabilities gamma for a fitted multilevel HMM

Description

plot.mHMM_gamma plots the transition probability matrix for a fitted multilevel hidden Markov model, by means of an alluvial plot (also known as Sankey diagram or riverplot) using the R package alluvial. The plotted transition probability matrix either represents the probabilities at the group level, i.e., representing the average transition probability matrix over all subjects, or at the subject level. In case of the latter, the user has to specify for which subject the transition probability matrix should be plotted.

Usage

## S3 method for class 'mHMM_gamma'
plot(x, subj_nr = NULL, cex = 0.8, col, hide, ...)

Arguments

x

An object of class mHMM_gamma, generated by the function obtain_gamma.

subj_nr

An integer specifying for which specific subject the transition probability matrix should be plotted. Only required if the input object represents the subject specific transition probability matrices.

cex

An integer specifying scaling of fonts of category labels. When not specified, defaults to cex = 0.8.

col

An optional vector with length m * m (i.e., where m denotes the number of hidden states) specifying the used colors in the alluvial plot.

hide

An optional logical vector with length m * m (i.e., where m denotes the number of hidden states) specifying whether particular stripes should be plotted. When not specified, omits the lines representing a value of exactly zero.

...

Arguments to be passed to alluvial (see alluvial)

Value

plot.mHMM_gamma returns a plot of the transition probability matrix. Depending on whether the input object represents the transition probabilities at the group level or the subject specific transition probability matrices, the returned plot represents either the group transition probability matrix, or the transition probability matrix for a given subject, specified by subject_nr.

See Also

mHMM for fitting the multilevel hidden Markov model, creating the object mHMM, and obtain_gamma to obtain the transition probabilities gamma for a fitted multilevel HMM, creating the object mHMM_gamma.

Examples


#' ###### Example on package data, see ?nonverbal
# specifying general model properties:
m <- 2
n_dep <- 4
q_emiss <- c(3, 2, 3, 2)

# specifying starting values
start_TM <- diag(.8, m)
start_TM[lower.tri(start_TM) | upper.tri(start_TM)] <- .2
start_EM <- list(matrix(c(0.05, 0.90, 0.05,
                          0.90, 0.05, 0.05), byrow = TRUE,
                        nrow = m, ncol = q_emiss[1]), # vocalizing patient
                 matrix(c(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), byrow = TRUE,
                        nrow = m, ncol = q_emiss[3]), # vocalizing therapist
                 matrix(c(0.1, 0.9,
                          0.1, 0.9), byrow = TRUE, nrow = m,
                        ncol = q_emiss[4])) # looking therapist

# Run a model without covariate(s):
out_2st <- mHMM(s_data = nonverbal,
                gen = list(m = m, n_dep = n_dep, q_emiss = q_emiss),
                start_val = c(list(start_TM), start_EM),
                mcmc = list(J = 11, burn_in = 5))

out_2st
summary(out_2st)

# obtaining the transition probabilities at the group and subject level
est_gamma_group <- obtain_gamma(out_2st, level = "group")

# plot the obtained transition probabilities
plot(est_gamma_group, col = rep(c("green", "blue"), each = m))





mHMMbayes documentation built on Oct. 2, 2023, 5:06 p.m.