View source: R/assortativity.R
| assortativity_attribute | R Documentation |
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.
assortativity_attribute(x, values, directed = NULL, digits = NULL, ...)
homophily(x, values, directed = NULL, digits = NULL, ...)
x |
Network input: matrix, igraph, network, cograph_network, or tna object. |
values |
Named vector of attribute values (names must match node names) or an unnamed vector in node order. |
directed |
Logical or NULL. If NULL (default), auto-detect. |
digits |
Integer or NULL. Round result. Default NULL. |
... |
Currently unused; |
For categorical (nominal) attributes, the coefficient is:
r = \frac{\text{tr}(\mathbf{e}) - \|\mathbf{e}^2\|}{1 - \|\mathbf{e}^2\|}
where \mathbf{e} is the mixing matrix with e_{ij} = fraction of
edges connecting type i to type j.
For numeric (scalar) attributes, the coefficient is the Pearson correlation
between attribute values at edge endpoints (computed over both orientations
of every edge when the network is undirected). Any non-numeric
values vector (character or factor) is treated as nominal.
The coefficient is NA when the network has no edges, when a nominal
attribute has a single category, or when either value vector has zero
variance.
An object of class "cograph_assortativity" with components:
Numeric scalar: assortativity coefficient.
Character: "nominal" or "scalar".
Logical.
Integer.
Integer.
The attribute values used.
Original input.
Newman, M.E.J. (2003). Mixing patterns in networks. Physical Review E, 67(2), 026126. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1103/PhysRevE.67.026126")}
assortativity, detect_communities
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.