# NOT RUN {
data("biofam3c")
# Creating sequence objects
child_seq <- seqdef(biofam3c$children, start = 15)
marr_seq <- seqdef(biofam3c$married, start = 15)
left_seq <- seqdef(biofam3c$left, start = 15)
## Choosing colors
attr(child_seq, "cpal") <- c("#66C2A5", "#FC8D62")
attr(marr_seq, "cpal") <- c("#AB82FF", "#E6AB02", "#E7298A")
attr(left_seq, "cpal") <- c("#A6CEE3", "#E31A1C")
# Plotting state distribution plots of observations
ssplot(list("Children" = child_seq, "Marriage" = marr_seq,
"Residence" = left_seq))
# }
# NOT RUN {
# Plotting sequence index plots of observations
ssplot(
list(child_seq, marr_seq, left_seq), type = "I",
# Sorting subjects according to the beginning of the 2nd channel (marr_seq)
sortv = "from.start", sort.channel = 2,
# Controlling the size, positions, and names for channel labels
ylab.pos = c(1, 2, 1), cex.lab = 1, ylab = c("Children", "Married", "Residence"),
# Plotting without legend
with.legend = FALSE)
# Plotting hidden Markov models
# Loading a ready-made HMM for the biofam data
data("hmm_biofam")
# Plotting observations and hidden states paths
ssplot(
hmm_biofam, type = "I", plots = "both",
# Sorting according to multidimensional scaling of hidden states paths
sortv = "mds.hidden",
ylab = c("Children", "Married", "Left home"),
# Controlling title
title = "Biofam", cex.title = 1.5,
# Labels for x axis and tick marks
xtlab = 15:30, xlab = "Age")
# Computing the most probable paths of hidden states
hidden.paths <- hidden_paths(hmm_biofam)
hidden.paths_seq <- seqdef(hidden.paths, labels = paste("Hidden state", 1:5))
# Plotting observations and hidden state paths
ssplot(
hmm_biofam, type = "I", plots = "hidden.paths",
# Sequence object of most probable paths
hidden.paths = hidden.paths_seq,
# Sorting according to the end of hidden state paths
sortv = "from.end", sort.channel = 0,
# Contolling legend position, type, and proportion
with.legend = "bottom", legend.prop = 0.15,
# Plotting without title and y label
title = FALSE, ylab = FALSE)
# }
Run the code above in your browser using DataLab