% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plotting.r
\name{calc_modularity}
\alias{calc_modularity}
\title{Calculate Adjusted Modularity Score}
\usage{
calc_modularity(dist_mat, labels, knn_k = 3, digits = 3)
}
\arguments{
\item{dist_mat}{Sample distance matrix.}

\item{labels}{Vector of factors or character strings. The cluster assignments
for each row in \code{dist_mat}.}

\item{knn_k}{Integer (optional, default: \code{NULL}). The number of nearest
neighbors (\code{k}) used for SNN graph construction. If \code{NULL}, it
defaults to \code{max(3, round(sqrt(N)))}, where \code{N} is the number of
samples.}

\item{digits}{Integer (default: \code{3}). The number of decimal places to
round the final adjusted score.}
}
\value{
A numeric value representing the adjusted modularity score,
ranging from -0.5 to 1.0.
}
\description{
Calculates the Modularity score for a given clustering (\code{labels}) based
on a Shared Nearest Neighbor (SNN) graph.The score is adjusted by the
theoretical maximum modularity for the number of groups to always be between
-0.5 (poor clustering) and +1 (excellent clustering)).
}
\examples{
library(SummarizedExperiment)
data(example_data)
se <- ecoda(
    data = example_data$Gongsharma_full$cell_counts$authors_HR,
    metadata = example_data$Gongsharma_full$metadata
)

# Extract necessary components
dist_mat <- dist(t(assay(se, "clr")))
labels <- colData(se)$subject.cmv

# Run the calculation
\dontrun{
calc_modularity(dist_mat, labels)
}
}
\references{
Brandes, Ulrik, et al.
"On finding graph clusterings with maximum modularity."
European Symposium on Algorithms. Springer, Berlin, Heidelberg, 2007.
}
