% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cluster_data.R
\name{cluster_network}
\alias{cluster_network}
\title{Cluster data and build per-cluster networks in one step}
\usage{
cluster_network(data, k, cluster_by = "pam", dissimilarity = "hamming", ...)
}
\arguments{
\item{data}{Sequence data. Accepts a data frame, matrix, or
\code{netobject}. See \code{\link{build_clusters}} for supported formats.}

\item{k}{Integer. Number of clusters.}

\item{cluster_by}{Character. Clustering algorithm passed to
\code{\link{build_clusters}}'s \code{method} parameter (\code{"pam"},
\code{"ward.D2"}, \code{"ward.D"}, \code{"complete"}, \code{"average"},
\code{"single"}, \code{"mcquitty"}, \code{"median"}, \code{"centroid"}),
or \code{"mmm"} for Mixed Markov Model clustering. Default: \code{"pam"}.}

\item{dissimilarity}{Character. Distance metric for sequence clustering.
Only valid when \code{cluster_by != "mmm"}. Default: \code{"hamming"}.}

\item{...}{Routed to two stages. For distance clustering
(\code{cluster_by != "mmm"}), \code{\link{build_clusters}} arguments
\code{na_syms}, \code{weighted}, \code{lambda}, \code{seed}, \code{q},
\code{p}, and \code{covariates} are intercepted and forwarded to the
clusterer; recognised network-estimation arguments flow to
\code{\link{build_network}}. Unknown arguments error before either stage
is run. When
\code{cluster_by = "mmm"}, the recognised \code{\link{build_mmm}}
arguments (\code{n_starts}, \code{max_iter}, \code{tol}, \code{smooth},
\code{seed}, \code{covariates}) are intercepted instead, and the rest
flows to \code{build_network}. In both modes, when \code{data} is a
\code{netobject}, its \code{build_args} are merged into the
\code{build_network} side (caller's explicit values take precedence).}
}
\value{
A \code{netobject_group}.
}
\description{
Combines sequence clustering and network estimation into a single call.
Clusters the data using the specified algorithm, then calls
\code{\link{build_network}} on each cluster subset.
}
\details{
If \code{data} is a \code{netobject} and \code{method} is not provided in
\code{...}, the original network method is inherited automatically so the
per-cluster networks match the type of the input network.
}
\examples{
seqs <- data.frame(V1 = c("A","B","C","A","B"), V2 = c("B","C","A","B","A"),
                   V3 = c("C","A","B","C","B"))
grp <- cluster_network(seqs, k = 2)
grp
\donttest{
set.seed(1)
seqs <- data.frame(
  V1 = sample(LETTERS[1:4], 50, TRUE), V2 = sample(LETTERS[1:4], 50, TRUE),
  V3 = sample(LETTERS[1:4], 50, TRUE), V4 = sample(LETTERS[1:4], 50, TRUE)
)
# Default: PAM clustering, relative (transition) networks
grp <- cluster_network(seqs, k = 3)

# Specify network method (cor requires numeric panel data)
\dontrun{
panel <- as.data.frame(matrix(rnorm(1500), nrow = 300, ncol = 5))
grp <- cluster_network(panel, k = 2, method = "cor")
}

# MMM-based clustering
grp <- cluster_network(seqs, k = 2, cluster_by = "mmm")
}
}
\seealso{
\code{\link{build_clusters}}, \code{\link{cluster_mmm}},
\code{\link{build_network}}
}
