David Lusseau, a researcher at the University of Aberdeen, observed the group of dolphins of Doubtful Sound. Every time a school of dolphins was encountered in the fjord between 1995 and 2001, each adult member of the school was photographed and identified from natural markings on the dorsal fin. This information was utilised to determine how often two individuals were seen together. Read the full story.

Dataset

Data challenges

  1. Is the network assortative by sex?
  2. Is the network assortative by node degree?

Analysis

library(tidyverse)
library(igraph)

Read dataset

edges = read_csv("dolphin_edges.csv")
## Parsed with column specification:
## cols(
##   x = col_integer(),
##   y = col_integer()
## )
nodes = read_csv("dolphin_nodes.csv")
## Parsed with column specification:
## cols(
##   name = col_character(),
##   sex = col_character()
## )
nodes = mutate(nodes, id = row_number()) %>% select(id, everything())
g = graph_from_data_frame(edges, directed = FALSE, vertices = nodes)

Assortativity by sex

# males and females 
male = V(g)$sex == "M"
names(male) = V(g)$name

# absolute modularity
modularity(g, membership = male + 1)
## [1] 0.1779795
# relative modularity
edge = as_edgelist(g)
l = c(edge[,1], edge[,2])
r = c(edge[,2], edge[,1])
sexl = male[l]
sexr = male[r]
cor(sexl, sexr)
## [1] 0.3568624

Assortativity by degree

d = degree(g)
edge = as_edgelist(g)
l = c(edge[,1], edge[,2])
r = c(edge[,2], edge[,1])
dl = d[l]
dr = d[r]
cor(dl, dr)
## [1] -0.04359403