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(Evelyn-Mother-Farther-Sibling, Evelyn-B:S, Evelyn-A, A-B, Evelyn-G-E, Evelyn-E)

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(
  Evelyn-Tere-Alfredo-Mairany,       # chain of connections
  Evelyn-Mairany,
  Tere-Grandpa:Grandma:Mago,          # Tere is connected to Grandpa, Grandma, and Mago
  Alfredo-Selfo,
  Mairany-Mosho:Yaritza,
  Grandpa-Grandma,
  Mago-Selfo,
  Mosho-Yaritza-Brigithe,
  Evelyn-Adolfo-Brigithe
)

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).

Your answer:

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
## Tere         Tere      5     0.050       25.83
## Mairany   Mairany      4     0.048       18.17
## Evelyn     Evelyn      3     0.050       17.00
## Alfredo   Alfredo      3     0.048       13.33
## Adolfo     Adolfo      2     0.037        5.00
## Yaritza   Yaritza      3     0.037        4.50
## Mago         Mago      2     0.036        2.17
## Selfo       Selfo      2     0.034        1.50
## Brigithe Brigithe      2     0.033        1.50
## Grandpa   Grandpa      2     0.034        0.00
## Grandma   Grandma      2     0.034        0.00
## Mosho       Mosho      2     0.034        0.00