# Load a pre-defined HMM
data("hmm_biofam")
# Compute the most probable hidden state paths given the data and the model
mpp <- hidden_paths(hmm_biofam)
head(mpp)
# Plot hidden paths for the first 100 individuals
seqs <- data_to_stslist(mpp, "id", "time", "state")
stacked_sequence_plot(seqs, type = "i", ids = 1:100)
# Because the model structure is so sparse that the posterior probabilities are
# mostly peaked to single state at each time point, the joint probability of
# observations and most probable paths of hidden states is almost identical to
# log-likelihood:
sum(attr(mpp, "log_prob"))
logLik(hmm_biofam)
Run the code above in your browser using DataLab