These functions offer ways to measure nodes' assortativity in a network:

  • node_by_heterophily() measures each node's embeddedness within groups of nodes with the same attribute.

  • node_by_homophily() measures each node's embeddedness within groups of nodes with the same attribute, using a variety of methods.

node_by_heterophily(.data, attribute)

node_by_homophily(
  .data,
  attribute,
  assortativity = c("ie", "ei", "yule", "geary")
)

Arguments

.data

A network object of class stocnet, igraph, tbl_graph, network, or similar. Internally any of these will be coerced to an efficient implementation. For more information on possible coercions, see e.g. manynet::as_stocnet().

attribute

Name of a nodal attribute, mark, measure, or membership vector.

assortativity

Which method to use for *_homophily(). Either "ie" (negative E-I index), "ei" (E-I index), "yule" (Yule's Q), or "geary" (Geary's C). Default is "ie". The E-I index is the number of ties between (or external) nodes grouped in some mutually exclusive categories minus the number of ties within (or internal) these groups divided by the total number of ties. This value can range from 1 to -1, where 1 indicates ties only between categories/groups and -1 ties only within categories/groups.

Yule's Q is a measure of association for two binary variables, calculated as: $$Q = \frac{ad - bc}{ad + bc}$$ where \(a\) is the number of ties between nodes in the same category, \(b\) is the number of ties between nodes in different categories, \(c\) is the number of non-ties between nodes in the same category, and \(d\) is the number of non-ties between nodes in different categories. This value can range from -1 to 1, where 1 indicates perfect association (all ties are between nodes in the same category), -1 indicates perfect disassociation (all ties are between nodes in different categories), and 0 indicates no association.

Geary's C is a measure of spatial autocorrelation, calculated as: $$C = \frac{(n - 1) \sum \limits_{i=1}^n \sum\limits_{j=1}^n w_{ij} (x_i - x_j)^2}{2W \sum\limits_{i=1}^n (x_i - \bar{x})^2}$$ where \(n\) is the number of nodes, \( w_{ij}\) is the weight of the tie between nodes \(i\) and \(j\), \(x_i\) is the attribute value of node \(i\), \(\bar{x}\) is the mean attribute value across all nodes, and \(W\) is the sum of all tie weights. This value can range from 0 to 2, where values less than 1 indicate positive autocorrelation (similar values are more likely to be connected), values greater than 1 indicate negative autocorrelation (dissimilar values are more likely to be connected), and a value of 1 indicates no autocorrelation. If an incompatible method is chosen for the attribute type, a suitable alternative will be used instead with a message.

Value

A node_measure numeric vector the length of the nodes in the network, providing the scores for each node. If the network is labelled, then the scores will be labelled with the nodes' names.

The object also carries the measure it computed, the range its values can fall within, and whether and how those values were normalized. These are shown as a one-line header when the object is printed. Where a measure offers a choice between several ways of counting the same thing, it also carries the variant it used. All can be retrieved with attr().

Examples

marvel_friends <- to_unsigned(to_uniplex(fict_marvel, "relationship"), "positive")
node_by_heterophily(marvel_friends, "Gender")
#> # E-I index [-1, 1]
#> ▅▂▁▂ 
#>   Abomination `Ant-Man` Apocalypse Beast `Black Panther` `Black Widow` Blade
#> 1         NaN       0.5         -1  -0.5          -0.545         0.692    -1
#> # ... and 46 more values from this nodeset. Use `print_all(...)` to print all values.
node_by_heterophily(marvel_friends, "Attractive")
#> # E-I index [-1, 1]
#> ▆▂▁▁ 
#>   Abomination `Ant-Man` Apocalypse Beast `Black Panther` `Black Widow` Blade
#> 1         NaN      -0.5         -1  -0.8          -0.818        -0.846    -1
#> # ... and 46 more values from this nodeset. Use `print_all(...)` to print all values.