library(igraph)
library(dplyr)

My Network Graph

This is a network graph of my family, which is my mom and my dad. I am connected to both of them, and they are connected to each other.

g5 <- graph_from_literal(Victor-Mom-Dad, Victor-Dad)

set.seed(123)
plot(g5, vertex.color = "lightblue", vertex.label.color = "black")

Scenario

A fitness-apparel brand is launching a new product and can give free samples to only two people. The network below shows who influences whom on social media. I used network metrics to decide who should get the samples.

g_mkt <- graph_from_literal(
  Brand-Ava-Ben-Cara,
  Brand-Cara,
  Ava-Dan:Eli:Fay,
  Ben-Gus,
  Cara-Hal:Ivy,
  Dan-Eli,
  Fay-Gus,
  Hal-Ivy-Jon,
  Brand-Kim-Jon
)

set.seed(123)
plot(g_mkt, vertex.color = "lightblue", vertex.label.color = "black")

Tasks

Task 1: Visualize the network

cliques(g_mkt, min = 3)
## [[1]]
## + 3/12 vertices, named, from b689b78:
## [1] Cara Hal  Ivy 
## 
## [[2]]
## + 3/12 vertices, named, from b689b78:
## [1] Ava Dan Eli

Looking at the plot, Ava looks the most central. She is in the middle of the network and has the most connections. She links Brand and Ben to the Dan, Eli, and Fay group. Cara and Brand also look fairly central.

I found two cliques, which are groups where everyone is connected to everyone else. They are Ava, Dan, and Eli, and Cara, Hal, and Ivy.

Task 2: Compare centrality measures

centrality_df <- data.frame(
  person      = V(g_mkt)$name,
  degree      = degree(g_mkt),
  closeness   = round(closeness(g_mkt), 3),
  betweenness = round(betweenness(g_mkt), 2)
)

centrality_df %>% arrange(desc(betweenness))
##       person degree closeness betweenness
## Ava      Ava      5     0.050       25.83
## Cara    Cara      4     0.048       18.17
## Brand  Brand      3     0.050       17.00
## Ben      Ben      3     0.048       13.33
## Kim      Kim      2     0.037        5.00
## Ivy      Ivy      3     0.037        4.50
## Fay      Fay      2     0.036        2.17
## Gus      Gus      2     0.034        1.50
## Jon      Jon      2     0.033        1.50
## Dan      Dan      2     0.034        0.00
## Eli      Eli      2     0.034        0.00
## Hal      Hal      2     0.034        0.00
ranked_df <- centrality_df %>%
  mutate(
    degree_rank      = rank(-degree, ties.method = "min"),
    closeness_rank   = rank(-closeness, ties.method = "min"),
    betweenness_rank = rank(-betweenness, ties.method = "min")
  ) %>%
  arrange(betweenness_rank)

ranked_df
##       person degree closeness betweenness degree_rank closeness_rank
## Ava      Ava      5     0.050       25.83           1              1
## Cara    Cara      4     0.048       18.17           2              3
## Brand  Brand      3     0.050       17.00           3              1
## Ben      Ben      3     0.048       13.33           3              3
## Kim      Kim      2     0.037        5.00           6              5
## Ivy      Ivy      3     0.037        4.50           3              5
## Fay      Fay      2     0.036        2.17           6              7
## Gus      Gus      2     0.034        1.50           6              8
## Jon      Jon      2     0.033        1.50           6             12
## Dan      Dan      2     0.034        0.00           6              8
## Eli      Eli      2     0.034        0.00           6              8
## Hal      Hal      2     0.034        0.00           6              8
##       betweenness_rank
## Ava                  1
## Cara                 2
## Brand                3
## Ben                  4
## Kim                  5
## Ivy                  6
## Fay                  7
## Gus                  8
## Jon                  8
## Dan                 10
## Eli                 10
## Hal                 10
set.seed(123)
plot(g_mkt,
     vertex.size = 10 + betweenness(g_mkt) * 0.8,
     vertex.color = "lightblue",
     vertex.label.color = "black",
     main = "Node size = betweenness")

Ava ranks first on degree (5) and betweenness (25.83). She is tied with Brand for the top closeness score (0.050). Cara is second on degree (4) and betweenness (18.17).

The rankings mostly agree at the top. Ava, Cara, Brand, and Ben are the top four on all three measures. The rankings are different for some people lower down. Ivy has a degree of 3, the same as Brand and Ben, but her betweenness is low (4.50) because most of her connections are inside her own group. Kim only has a degree of 2, but her betweenness is higher than Ivy’s because she connects Brand to Jon. Dan, Eli, and Hal have a betweenness of 0 because nobody needs to go through them to reach anyone else.

Task 3: Choose two seed customers

seeds <- c("Ava", "Cara")
reached <- setdiff(unique(unlist(lapply(seeds, function(s) names(neighbors(g_mkt, s))))), seeds)
reached
## [1] "Brand" "Ben"   "Dan"   "Eli"   "Fay"   "Hal"   "Ivy"
length(reached)
## [1] 7

I would give the free samples to Ava and Cara. I left out Brand because Brand is the company itself.

  • Degree: Ava has the most direct connections (5) and Cara has the second most (4), so they can reach a lot of people directly.
  • Betweenness: Ava (25.83) and Cara (18.17) have the highest scores, so they are the main bridges that information passes through.
  • Different groups: Ava is connected to one side of the network (Ben, Dan, Eli, and Fay) and Cara is connected to the other side (Ben, Hal, and Ivy). Together they reach 7 of the 10 other people directly, so the product would spread to different parts of the network.
  • Degree is not the same as being a bridge: Ivy has the same degree as Ben (3), but her betweenness is much lower because her connections stay in one group. Ava and Cara have both high degree and high betweenness, so they are the best choice.