They say that “birds of a feather flock together”, but why take their word for it?


Introduction

In social networks, actors tend to associate with others who are similar in some way, such as race, language, creed, or class. This phenomenon is called homophily.

The {homophily} package provides flexible routines to measure mixing patterns using generic methods that are compatible with <network> and <igraph> objects, including {tidygraph}’s <tbl_graph> objects.

Installation

Usage

library(homophily)
data("jemmah_islamiyah", package = "homophily") # undirected <igraph>
data("sampson", package = "ergm")               # directed <network>

Remixing Mixing Matrices

We can also build generalized mixing matrices to explore mixing patterns across different dimensions.

For example, if we want to explore ties between each individual node and a group attribute, we can provide arguments to both dim1= and dim2=.

We’ll use the {network} convention of node names being stored in an attribute called "vertex.names" to see mixing patterns between each node and the "group" attribute.

as_mixing_matrix(samplike, dim1 = "vertex.names", dim2 = "group")

Going further, we can also explore mixing patterns across group attributes. samplike’s "cloisterville" attribute notes whether each individual attended the Cloisterville monastery.

as_mixing_matrix(samplike, dim1 = "cloisterville", dim2 = "group")

For directed graphs, the default behavior considers both outgoing and inbound ties, but you can provide "out" or "in" to direction= as desired.

as_mixing_matrix(samplike, dim1 = "cloisterville", dim2 = "group",
                 direction = "out")
as_mixing_matrix(samplike, dim1 = "cloisterville", dim2 = "group",
                 direction = "in")

Assortativity

assort_discrete(jemmah_islamiyah, node_attr_name = "role")
assort_discrete(samplike, node_attr_name = "group")
assort_degree(samplike)