% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/assortativity.R
\name{assortativity}
\alias{assortativity}
\title{Degree Assortativity Coefficient}
\usage{
assortativity(x, directed = NULL, type = NULL, digits = NULL, ...)
}
\arguments{
\item{x}{Network input: matrix, igraph, network, cograph_network, or tna
object.}

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

\item{type}{Character string specifying which degree correlation to compute.
One of \code{"out-in"} (default for directed), \code{"in-in"},
\code{"out-out"}, \code{"in-out"}, or \code{"degree"} (for undirected).
Ignored for undirected networks.}

\item{digits}{Integer or NULL. Round result to this many decimal places.
Default NULL (no rounding).}

\item{...}{Additional arguments passed to \code{\link{to_igraph}}.}
}
\value{
An object of class \code{"cograph_assortativity"} with components:
\describe{
\item{coefficient}{Numeric scalar: the assortativity coefficient in
\eqn{[-1, 1]}.}
\item{type}{Character: the degree type used.}
\item{directed}{Logical: whether the network was treated as directed.}
\item{n_nodes}{Integer: number of nodes.}
\item{n_edges}{Integer: number of edges.}
\item{network}{The original input network.}
}
}
\description{
Computes the degree assortativity coefficient, measuring the tendency of
nodes to connect to other nodes with similar degree. Positive values
indicate assortative mixing (high-degree nodes connect to high-degree nodes),
negative values indicate disassortative mixing.
}
\details{
The degree assortativity coefficient is defined as the Pearson correlation
coefficient between the degrees of nodes at either end of each edge
(Newman 2002):

\deqn{r = \frac{\sum_{jk} jk(e_{jk} - q_j q_k)}{\sigma_q^2}}

where \eqn{e_{jk}} is the fraction of edges connecting degree-\eqn{j} to
degree-\eqn{k} vertices, \eqn{q_k} is the excess degree distribution, and
\eqn{\sigma_q^2} its variance.

For directed networks, different degree combinations (in/out) at source and
target ends can be specified via the \code{type} parameter.
}
\examples{
# Assortative network (high-degree connect to high-degree)
adj <- matrix(c(
  0, 1, 1, 1, 0,
  1, 0, 1, 1, 0,
  1, 1, 0, 0, 1,
  1, 1, 0, 0, 1,
  0, 0, 1, 1, 0
), 5, 5)
rownames(adj) <- colnames(adj) <- LETTERS[1:5]
cograph::assortativity(adj)
}
\references{
Newman, M.E.J. (2002). Assortative mixing in networks.
\emph{Physical Review Letters}, 89(20), 208701.
\doi{10.1103/PhysRevLett.89.208701}
}
\seealso{
\code{\link{assortativity_attribute}}, \code{\link{centrality}},
\code{\link{network_summary}}
}
