Package DBHC is an implementation of a sequence clustering algorithm that uses a mixture of discrete-output hidden Markov models (HMMs), the Discrete Bayesian HMM Clustering (DBHC) algorithm. The algorithm uses heuristics based on the Bayesian Information Criterion (BIC) to search for the optimal number of hidden states in each HMM and the optimal number of clusters. The packages provides functions for finding clusters in discrete sequence data with the DBHC algorithm and for plotting heatmaps of the probability matrices that are estimated in the cluster models.
Below a basic example of how to use package DBHC for obtaining sequence clusters for the Swiss Household data in package TraMineR:
library(DBHC)
library(TraMineR)
## Swiss Household Data
data("biofam", package = "TraMineR")
# Clustering algorithm
<- c("P", "L", "M", "LM", "C", "LC", "LMC", "D")
new.alphabet <- seqdef(biofam[,10:25], alphabet = 0:7, states = new.alphabet)
sequences
# Code below takes long time to run
<- hmm.clust(sequences)
res
# Heatmaps
<- 1 # display heatmaps for cluster 1
cluster transition.heatmap(res$partition[[cluster]]$transition_probs,
$partition[[cluster]]$initial_probs)
resemission.heatmap(res$partition[[cluster]]$emission_probs)
## A smaller example, which takes less time to run
<- sequences[sample(1:nrow(sequences), 20, replace = FALSE),]
subset
# Clustering algorithm
<- hmm.clust(subset, K.max = 3)
res
# Number of clusters
print(res$n.clusters)
# Table of cluster memberships
table(res$memberships[,"cluster"])
# BIC for each number of clusters
print(res$bic)
# Heatmaps
<- 1 # display heatmaps for cluster 1
cluster transition.heatmap(res$partition[[cluster]]$transition_probs,
$partition[[cluster]]$initial_probs)
resemission.heatmap(res$partition[[cluster]]$emission_probs)