% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mmm.R
\name{build_mmm}
\alias{build_mmm}
\title{Fit a Mixed Markov Model}
\usage{
build_mmm(
  data,
  k = 2L,
  n_starts = 50L,
  max_iter = 200L,
  tol = 1e-06,
  smooth = 0.01,
  seed = NULL,
  covariates = NULL
)
}
\arguments{
\item{data}{A data.frame (wide format), \code{netobject}, or
\code{tna} model. For tna objects, extracts the stored data.}

\item{k}{Integer. Number of mixture components. Default: 2.}

\item{n_starts}{Integer. Number of random restarts. Default: 50.}

\item{max_iter}{Integer. Maximum EM iterations per start. Default: 200.}

\item{tol}{Numeric. Convergence tolerance. Default: 1e-6.}

\item{smooth}{Numeric. Laplace smoothing constant. Default: 0.01.}

\item{seed}{Integer or NULL. Random seed.}

\item{covariates}{Optional. Covariates integrated into the EM algorithm
to model covariate-dependent mixing proportions. Accepts formula,
character vector, string, or data.frame (same forms as
\code{\link{build_clusters}}). Unlike the post-hoc analysis in
\code{build_clusters()}, these covariates directly influence cluster
membership during estimation. Requires the \pkg{nnet} package.}
}
\value{
An object of class \code{net_mmm} with components:
\describe{
\item{models}{List of \code{netobject}s, one per component.}
\item{k}{Number of components.}
\item{mixing}{Numeric vector of mixing proportions.}
\item{posterior}{N x k matrix of posterior probabilities.}
\item{assignments}{Integer vector of hard assignments (1..k).}
\item{quality}{List: \code{avepp} (per-class), \code{avepp_overall},
\code{entropy}, \code{relative_entropy},
\code{classification_error}.}
\item{log_likelihood, BIC, AIC, ICL}{Model fit statistics.}
\item{states}{Character vector of state names.}
}
}
\description{
Discovers latent subgroups with different transition dynamics using
Expectation-Maximization. Each mixture component has its own transition
matrix. Sequences are probabilistically assigned to components.
}
\examples{
seqs <- data.frame(V1 = sample(c("A","B","C"), 30, TRUE),
                   V2 = sample(c("A","B","C"), 30, TRUE))
mmm <- build_mmm(seqs, k = 2, n_starts = 1, max_iter = 10, seed = 1)
mmm
\donttest{
seqs <- data.frame(
  V1 = sample(LETTERS[1:3], 30, TRUE), V2 = sample(LETTERS[1:3], 30, TRUE),
  V3 = sample(LETTERS[1:3], 30, TRUE), V4 = sample(LETTERS[1:3], 30, TRUE)
)
mmm <- build_mmm(seqs, k = 2, seed = 42)
print(mmm)
summary(mmm)
}

}
\seealso{
\code{\link{compare_mmm}}, \code{\link{build_network}}
}
