% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/assortativity.R
\name{assortativity_attribute}
\alias{assortativity_attribute}
\alias{homophily}
\title{Attribute Assortativity (Homophily)}
\usage{
assortativity_attribute(x, values, directed = NULL, digits = NULL, ...)

homophily(x, values, directed = NULL, digits = NULL, ...)
}
\arguments{
\item{x}{Network input: matrix, igraph, network, cograph_network, or tna
object.}

\item{values}{Named vector of attribute values (names must match node names)
or an unnamed vector in node order.}

\item{directed}{Logical or NULL. If NULL (default), auto-detect.}

\item{digits}{Integer or NULL. Round result. Default NULL.}

\item{...}{Additional arguments passed to \code{\link{to_igraph}}.}
}
\value{
An object of class \code{"cograph_assortativity"} with components:
\describe{
\item{coefficient}{Numeric scalar: assortativity coefficient.}
\item{type}{Character: \code{"nominal"} or \code{"scalar"}.}
\item{directed}{Logical.}
\item{n_nodes}{Integer.}
\item{n_edges}{Integer.}
\item{attribute_values}{The attribute values used.}
\item{network}{Original input.}
}
}
\description{
Computes assortativity with respect to a node attribute, measuring the
tendency of nodes to connect to others with similar attribute values.
For categorical attributes, this computes the modularity-based nominal
assortativity. For numeric attributes, this computes the Pearson
correlation between attribute values at edge endpoints.
}
\details{
For categorical (nominal) attributes, the coefficient is:
\deqn{r = \frac{\text{tr}(\mathbf{e}) - \|\mathbf{e}^2\|}{1 - \|\mathbf{e}^2\|}}
where \eqn{\mathbf{e}} is the mixing matrix with \eqn{e_{ij}} = fraction of
edges connecting type \eqn{i} to type \eqn{j}.

For numeric (scalar) attributes, the coefficient is the Pearson correlation
between attribute values at edge endpoints.
}
\examples{
adj <- matrix(c(0,1,1,0, 1,0,0,0, 1,0,0,1, 0,0,1,0), 4, 4)
rownames(adj) <- colnames(adj) <- c("A", "B", "C", "D")
groups <- c(A = "x", B = "x", C = "y", D = "y")
cograph::assortativity_attribute(adj, groups)
}
\references{
Newman, M.E.J. (2003). Mixing patterns in networks.
\emph{Physical Review E}, 67(2), 026126.
\doi{10.1103/PhysRevE.67.026126}
}
\seealso{
\code{\link{assortativity}}, \code{\link{detect_communities}}
}
