% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/network-utils.R
\name{detect_communities}
\alias{detect_communities}
\title{Detect Communities in a Network}
\usage{
detect_communities(x, method = "louvain", directed = NULL, weights = TRUE)
}
\arguments{
\item{x}{Network input: matrix, igraph, network, cograph_network, or tna object.}

\item{method}{Community detection algorithm to use. One of:
\itemize{
\item \code{"louvain"}: Louvain method (default, fast and accurate)
\item \code{"walktrap"}: Walktrap algorithm based on random walks
\item \code{"fast_greedy"}: Fast greedy modularity optimization
\item \code{"label_prop"}: Label propagation algorithm
\item \code{"infomap"}: Infomap algorithm based on information flow
\item \code{"leiden"}: Leiden algorithm (improved Louvain)
}}

\item{directed}{Logical or NULL. If NULL (default), auto-detect from matrix
symmetry. Set TRUE to force directed, FALSE to force undirected.}

\item{weights}{Logical. Use edge weights for community detection. Default TRUE.}
}
\value{
A data frame with columns:
\itemize{
\item \code{node}: Node labels/names
\item \code{community}: Integer community membership
}
}
\description{
Detects communities (clusters) in a network using various community detection
algorithms. Returns a data frame with node-community assignments.
}
\examples{
# Basic usage
adj <- matrix(c(0, .5, .8, 0,
                .5, 0, .3, .6,
                .8, .3, 0, .4,
                 0, .6, .4, 0), 4, 4, byrow = TRUE)
rownames(adj) <- colnames(adj) <- c("A", "B", "C", "D")
detect_communities(adj)

# Different algorithm
detect_communities(adj, method = "walktrap")
}
