Learn R Programming

seqHMM (version 1.1.0)

build_mmm: Build a Mixture Markov Model

Description

Function build_mmm is a shortcut for constructing a mixture Markov model as a restricted case of an mhmm object.

Usage

build_mmm(
  observations,
  n_clusters,
  transition_probs,
  initial_probs,
  formula,
  data,
  coefficients,
  cluster_names = NULL,
  ...
)

Arguments

observations

An stslist object (see seqdef) containing the sequences.

n_clusters

A scalar giving the number of clusters/submodels (not used if starting values for model parameters are given with initial_probs and transition_probs).

transition_probs

A list of matrices of transition probabilities for submodels of each cluster.

initial_probs

A list which contains vectors of initial state probabilities for submodels of each cluster.

formula

Covariates as an object of class formula, left side omitted.

data

An optional data frame, list or environment containing the variables in the model. If not found in data, the variables are taken from environment(formula).

coefficients

An optional \(k x l\) matrix of regression coefficients for time-constant covariates for mixture probabilities, where \(l\) is the number of clusters and \(k\) is the number of covariates. A logit-link is used for mixture probabilities. The first column is set to zero.

cluster_names

A vector of optional names for the clusters.

...

Additional arguments to simulate_transition_probs.

Value

Object of class mhmm with following elements:

observations

State sequence object or a list of such containing the data.

transition_probs

A matrix of transition probabilities.

emission_probs

A matrix or a list of matrices of emission probabilities.

initial_probs

A vector of initial probabilities.

coefficients

A matrix of parameter coefficients for covariates (covariates in rows, clusters in columns).

X

Covariate values for each subject.

cluster_names

Names for clusters.

state_names

Names for hidden states.

symbol_names

Names for observed states.

channel_names

Names for channels of sequence data

length_of_sequences

(Maximum) length of sequences.

n_sequences

Number of sequences.

n_symbols

Number of observed states (in each channel).

n_states

Number of hidden states.

n_channels

Number of channels.

n_covariates

Number of covariates.

n_clusters

Number of clusters.

See Also

fit_model for estimating model parameters; summary.mhmm for a summary of a mixture model; separate_mhmm for organizing an mhmm object into a list of separate hmm objects; and plot.mhmm for plotting mixture models.

Examples

Run this code
# NOT RUN {

# Define sequence data
data("mvad", package = "TraMineR")
mvad_alphabet <- c("employment", "FE", "HE", "joblessness", "school",
  "training")
mvad_labels <- c("employment", "further education", "higher education",
  "joblessness", "school", "training")
mvad_scodes <- c("EM", "FE", "HE", "JL", "SC", "TR")
mvad_seq <- seqdef(mvad, 17:86, alphabet = mvad_alphabet, states = mvad_scodes,
  labels = mvad_labels, xtstep = 6)

# Initialize the MMM
set.seed(123)
mmm_mvad <- build_mmm(observations = mvad_seq,
  n_clusters = 2,
  formula = ~male, data = mvad)

# }
# NOT RUN {
# Estimate model parameters
mmm_mvad <- fit_model(mmm_mvad)$model

# Plot model (both clusters in the same plot)
require(igraph)
plot(mmm_mvad, interactive = FALSE,
  # Modify legend position and properties
  with.legend = "right", legend.prop = 0.3, cex.legend = 1.2,
  # Define vertex layout
  layout = layout_as_star,
  # Modify edge properties
  edge.label = NA, edge.arrow.size = 0.8, edge.curved = 0.2,
  # Modify vertex label positions (initial probabilities)
  vertex.label.pos = c("left", "right", "right", "left", "left", "right"))
  
# Summary of the MMM
summary(mmm_mvad)
# }

Run the code above in your browser using DataLab