R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(igraph)
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
g5 <- graph_from_literal(
  Norma - Daniel,
  Norma - Viviana - Daniel,
  Norma - Carlos - Daniel,
  Norma - Diana - Daniel
)

plot(g5)

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. Use network metrics to decide who should receive the samples.

library(igraph)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:igraph':
## 
##     as_data_frame, groups, union
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
# A social media network around a brand
g_mkt <- graph_from_literal(
  Brand-Ava-Ben-Cara,       # chain of connections
  Brand-Cara,
  Ava-Dan:Eli:Fay,          # Ava is connected to Dan, Eli, and Fay
  Ben-Gus,
  Cara-Hal:Ivy,
  Dan-Eli,
  Fay-Gus,
  Hal-Ivy-Jon,
  Brand-Kim-Jon
)

set.seed(123)  # fixes the layout so the plot looks the same each time
plot(g_mkt, vertex.color = "lightblue", vertex.label.color = "black")

Tasks

Task 1: Visualize the network

Look at the plot above. Who looks most “central” visually? Identify any cliques (tightly connected groups).

##ANSWER: Visually Central Nodes: Ava and Cara visually appear to be the most central customer nodes in the network. Ava acts as a central hub connecting the Brand to a dense local group (Dan, Eli, Fay), while Cara links the Brand downstream to Hal, Ivy, and Jon. Brand also sits structurally in the middle, connecting Ava, Cara, and Kim. Cliques / Tightly Connected Groups: Brand - Ava - Cara: A fully connected 3-node triangle/clique at the network core. Ava - Dan - Eli: A tightly connected triangle forming a localized cluster. Hal - Ivy - Jon: A closed 3-node triangle forming another distinct community.

Task 2: Compare centrality measures

Compute degree, closeness, and betweenness, then put the results in one data frame and rank the nodes.

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

#ANSWER:Across the calculated metrics, Ava and Cara consistently rank highest across degree, closeness, and betweenness centrality. Ava leads in degree centrality with 5 direct connections, followed closely by Cara with 4 connections, meaning both individuals hold the highest direct social reach. They also rank highest in closeness centrality because they sit at the shortest average network distance to every other node in the graph, allowing information originating from them to spread rapidly. Similarly, Ava and Cara dominate betweenness centrality, operating as essential gatekeepers through which paths between distinct subgroups must pass. Overall, the rankings strongly agree for the top-performing nodes, though they diverge for secondary nodes; for example, nodes like Dan and Eli show moderate degree centrality due to their local connections but have virtually zero betweenness because they do not bridge separate network clusters.

Task 3: Choose two seed customers

Which two people should receive free samples? Justify your choice using at least two different metrics. (Hint: is high degree the same as being a bridge?) #ANSWER:The brand should select Ava and Cara as the two seed customers for the referral campaign. First, both individuals rank highest in degree centrality, meaning gifting samples to them guarantees immediate, direct exposure to nine of the eleven people in the social graph. Second, and more importantly, they possess the highest betweeness centrality in the network. While a high degree node like Dan is only connected within a single localized cluster, Ava and Cara act as strategic structural bridges that connect the Brand to two entirely separate, non-overlapping customer communities—Ava reaching the Dan-Eli-Fay subgroup and Cara reaching the Hal-Ivy-Jon subgroup. By seeding both Ava and Cara, the brand maximizes both immediate direct reach and widespread viral diffusion across all major clusters in the network.