% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mmm.R
\name{compare_mmm}
\alias{compare_mmm}
\title{Compare MMM fits across different k}
\usage{
compare_mmm(data, k = 2:5, return_fits = FALSE, ...)
}
\arguments{
\item{data}{Data frame, netobject, or tna model.}

\item{k}{Integer vector of component counts. Values must be whole finite
numbers >= 2. Default: 2:5.}

\item{return_fits}{Logical. When \code{TRUE} the fitted models are
retained on the result via \code{attr(result, "fits")} (a list of
\code{net_mmm} objects, named by \code{k}), so the user can pick
the chosen model without re-running the EM. Default \code{FALSE}
keeps the historical lightweight return shape -- only the comparison
table is allocated.}

\item{...}{Arguments passed to \code{\link{build_mmm}}.}
}
\value{
A \code{mmm_compare} data frame with BIC, AIC, ICL, AvePP,
entropy per k. When \code{return_fits = TRUE}, the fitted models are
attached as \code{attr(result, "fits")}.
}
\description{
Compare MMM fits across different k
}
\examples{
seqs <- data.frame(V1 = sample(c("A","B","C"), 30, TRUE),
                   V2 = sample(c("A","B","C"), 30, TRUE))
comp <- compare_mmm(seqs, k = 2:3, n_starts = 1, max_iter = 10, seed = 1)
comp
\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)
)
comp <- compare_mmm(seqs, k = 2:3, seed = 42)
print(comp)

# Retain fits to avoid a re-fit after picking the BIC-min model.
comp_with_fits <- compare_mmm(seqs, k = 2:3, seed = 42, return_fits = TRUE)
best_k <- comp_with_fits$k[which.min(comp_with_fits$BIC)]
best_fit <- attr(comp_with_fits, "fits")[[as.character(best_k)]]
}

}
