% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mcml.R
\name{as_htna}
\alias{as_htna}
\alias{as_htna.mcml}
\alias{as_htna.default}
\title{Build a grouped node-level network (htna) from data and a clustering}
\usage{
as_htna(x, clusters = NULL, method = "relative", ...)

\method{as_htna}{mcml}(x, clusters = NULL, method = "relative", data = NULL, ...)

\method{as_htna}{default}(x, clusters = NULL, method = "relative", ...)
}
\arguments{
\item{x}{Data accepted by \code{\link{build_network}} (sequence data frame,
edgelist, transition matrix, \code{netobject}, or \code{tna}); or an
\code{mcml} object, in which case the original \code{data} must also be
supplied and the mcml provides the cluster membership.}

\item{clusters}{Cluster assignment: a named list of node-name vectors, a
per-node membership vector, or a two-column data frame. When \code{NULL}
and \code{x} carries node groups (or is an \code{mcml}), those are used.}

\item{method}{Estimator passed to \code{\link{build_network}}. Default
\code{"relative"} (row-normalized transitions).}

\item{...}{Further arguments forwarded to \code{\link{build_network}}
(e.g. \code{actor}, \code{action}, \code{time} for long-format data).}

\item{data}{For the \code{mcml} method, the original data the mcml was built
from (sequence/edgelist/etc.). Optional when the mcml was built from
sequence/edgelist data: \code{build_mcml()} stashes that source (and the
\code{actor}/\code{action}/\code{time} roles), so \code{as_htna(mcml)}
works on its own. Required for an mcml built from a matrix/aggregate,
which retains no node-level data.}
}
\value{
A \code{netobject} (\code{cograph_network}) over all nodes, with a
\code{cluster} column on \code{$nodes}, \code{$node_groups} populated, and
the membership stored in the \code{"cluster_members"} attribute.
}
\description{
Builds the full node-level network from the original data and attaches a
cluster grouping, producing a single \code{netobject} in which every actor
is a node and cluster membership labels the actors. This is the node-level
counterpart of \code{\link{build_mcml}}: where \code{build_mcml} collapses
the network to a cluster-level (macro) summary, \code{as_htna} keeps every
node and every transition - including the between-cluster transitions an
mcml only retains in aggregate.
}
\details{
\strong{Why this rebuilds from data.} An \code{mcml} stores cluster-level
data (the macro sequences are recoded to cluster labels, and the per-cluster
data is filtered to within-cluster nodes), so it does not retain a faithful
node-level transition network. The only faithful source of node-level
between-cluster transitions is the original data. \code{as_htna()} therefore
rebuilds from data via \code{\link{build_network}}; an \code{mcml} can supply
the cluster membership, but the data must be provided.

The result is a genuine \code{netobject}, so it supports inference
(\code{\link{bootstrap_network}}, centrality, \code{\link{permutation}})
and plots directly as a grouped network with cograph:
\code{cograph::plot_htna(as_htna(data, clusters))}.
}
\examples{
seqs <- data.frame(
  t1 = c("A", "C", "E", "B"), t2 = c("B", "D", "F", "A"),
  t3 = c("C", "A", "E", "D"), stringsAsFactors = FALSE
)
clusters <- list(C1 = c("A", "B"), C2 = c("C", "D"), C3 = c("E", "F"))
net <- as_htna(seqs, clusters)
net$nodes$cluster
\dontrun{
cograph::plot_htna(net)
}
}
\seealso{
\code{\link{build_mcml}}, \code{\link{build_network}}; plot with
\code{cograph::plot_htna()}.
}
