Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mbojan/netseg

Segregation and homophily measurement in social networks
https://github.com/mbojan/netseg

homophily r segregation social-networks

Last synced: 11 days ago
JSON representation

Segregation and homophily measurement in social networks

Awesome Lists containing this project

README

        

---
bibliography: vignettes/refs.bib
output: github_document
editor_options:
chunk_output_type: console
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

```{r logo, include = FALSE, eval=FALSE}
library(hexSticker)
library(ergm)
library(magrittr)
library(tidygraph)
library(ggraph)

set.seed(666)
net <- network.initialize(30, directed=FALSE)
net %v% "a1" <- sample( rep(1:2, each=15) )
net %v% "a2" <- sample( rep(1:2, each=15) )

snet <- simulate(
net ~ edges + nodematch("a1") + nodematch("a2"),
coef = c(-5, 3, 3)
)

g <- intergraph::asIgraph(snet) %>%
as_tbl_graph()

p <- g %>%
ggraph(layout="stress") +
geom_edge_link(
color="gray50",
edge_width = 1/4
) +
geom_node_point(
aes(
color=as.character(a1),
fill=as.character(a2)
),
shape = 21,
size=1,
stroke = 1
) +
scale_fill_brewer(type="qual", palette="Set1") +
scale_color_brewer(type="qual", palette="Set1") +
theme_graph(
base_family = "sans"
)

sticker(
p + theme_void() +
theme_transparent() +
theme(legend.position="none"),
p_size=20,
p_x = 1,
p_y = 1.6,
s_x = 1,
s_y= 0.9,
s_width=1.3,
s_height=1,
package = "netseg",
p_color = "gray50",
h_fill = "#ffffff",
h_color = "black",
url = "https://mbojan.github.io/netseg",
u_size = 4,
filename = "man/figures/logo.png",
dpi = 300
)
```

# `netseg`: Measures of Network Segregation and Homophily

[![CRAN status](https://www.r-pkg.org/badges/version/netseg)](https://CRAN.R-project.org/package=netseg)
[![rstudio cran mirror downloads](https://cranlogs.r-pkg.org/badges/netseg?color=2ED968)](https://cranlogs.r-pkg.org/)
[![R-CMD-check](https://github.com/mbojan/netseg/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mbojan/netseg/actions/workflows/R-CMD-check.yaml)

Segregation is a network-level property such that edges between predefined groups of vertices are relatively less likely. Network homophily is a individual-level tendency to form relations with people who are similar on some attribute (e.g. gender, music taste, social status, etc.). In general homophily leads to segregation, but segregation might arise without homophily. This package implements descriptive indices measuring homophily/segregation. It is a computational companion to @bojanowski-corten-2014.

## Installation

Install the released version of netseg from [CRAN](https://CRAN.R-project.org/) with:

```r
install.packages("netseg")
```

or the development version from [GitHub](https://github.com/) with:

```{r install, eval=FALSE}
# install.packages("remotes")
remotes::install_github("mbojan/netseg")
```

## Example

To illustrate, consider the Classroom network below:

```{r Classroom, dev="svg"}
library(netseg)
library(igraph)

data("Classroom")

plot(
Classroom,
layout = graphlayouts::layout_with_stress,
vertex.color = c("pink", "lightskyblue")[match(V(Classroom)$gender, c("Girl", "Boy"))],
vertex.label = NA,
edge.arrow.size = 0.5
)
legend(
"bottomright",
pch = 21,
legend = c("Boy", "Girl"),
pt.cex = 2,
pt.bg = c("lightskyblue", "pink"),
col = "black",
bty = "n"
)
```

The extent of gender segregation in this network can be assessed using one of the indices provided in the package, for example odds ratio of within-group tie (`orwg()`)

```{r Classroom-orwg}
orwg(Classroom, "gender")
```

tells us that same-gender tie odds are `r orwg(Classroom, "gender")` times greater than tie odds between genders.

Coleman's index [@coleman-1958] assesses the segregation on the group level:

```{r Classroom-coleman}
coleman(Classroom, "gender")
```

Qualitatively speaking it compares the proportion of same-group neighbors to the proportion of that group in the network as a whole. It is a number between -1 and 1. Value of 0 means these proportions are equal. Value of 1 means that all ties outgoing from a particular group are sent to the members of the same group. Value of -1 is the opposite -- all ties are sent to members of other group(s).

## References