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(
Mom-Dad,
Mom-Dakotah,
Dad-Dakotah,
Mom-Emmah:Charlotte:Saide,
Dad-Emmah:Charlotte:Saide,
Dakotah-Emmah:Charlotte:Saide,
Dakotah-Lea
)
plot(g5)
Answer: In my network, each person is a vertex, and each line is an edge representing a connection. I have the highest degree with six direct connections. My parents are connected to each other and all four children, forming triangles with each child. I also act as a bridge between my girlfriend and my family because she connects to them through me. These patterns illustrate the tutorial’s ideas of degree, triangles, and mutual connections.
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")
Look at the plot above. Who looks most “central” visually? Identify any cliques (tightly connected groups).
Your answer: Ava and Cara stand out because they connect to several people across the network. Two tightly connected groups are Ava, Dan, and Eli, and Cara, Hal, and Ivy. Each group forms a triangle because everyone is directly connected to the other two people. Ben and Brand also help connect different parts of the network. Looking at these connections helps show how a product recommendation could move beyond one friend group.
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
Your answer: Which people rank highest on each measure? Do the rankings agree? Ava has the most direct connections with five, followed by Cara with four. Ava and Brand tie for the highest closeness at 0.050. Ava also has the highest betweenness at 25.83, followed by Cara at 18.17. The rankings partly agree, with Ava performing strongly across all three measures. However, Brand’s closeness score shows that someone can reach others through short paths without having the most direct connections. I would compare all three measures to get a better understanding of each person’s role.
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?) I would give the samples to Ava and Cara. Ava has the most connections and the highest betweenness, making her a strong choice for spreading the word. Cara ranks second in both measures and connects to another group through Hal and Ivy. Together, they could help the brand reach different social circles. Having many direct connections gives someone an immediate audience, while high betweenness suggests they help connect people across the network. I would also consider whether Ava and Cara enjoy fitness apparel and would be willing to share their experiences with others.
https://visiblenetworklabs.com/2021/04/16/understanding-network-centrality/Links to an external site.
https://cambridge-intelligence.com/learn/social-network-analysis/Links to an external site.