Social Network Influence Analysis

Author

Guibril Ramde

Week 3 Assignment

##Part A

  1. Import the dataset
library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.5.2
Warning: package 'tibble' was built under R version 4.5.2
Warning: package 'tidyr' was built under R version 4.5.2
Warning: package 'readr' was built under R version 4.5.2
Warning: package 'purrr' was built under R version 4.5.2
Warning: package 'dplyr' was built under R version 4.5.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.0     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.2     ✔ tibble    3.3.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.2
✔ purrr     1.2.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
network_data <- read.csv("https://raw.githubusercontent.com/japhet125/Data_Science_605_Hws/refs/heads/main/network.csv")
network_data
   User User1 User2 User3 User4 User5 User6
1 User1     0     1     1     0     0     0
2 User2     1     0     1     1     0     1
3 User3     1     1     0     1     1     0
4 User4     0     1     1     0     1     0
5 User5     0     0     1     1     0     1
6 User6     0     1     0     0     1     0
  1. Create a labeled network visualization that displays all users and their connections. Include node labels and ensure the graph is readable.
#Dimensions
dim(network_data)
[1] 6 7
#Separate user labels from numerical network values
user_labels <- network_data$User
user_labels
[1] "User1" "User2" "User3" "User4" "User5" "User6"
adj_matrix <- as.matrix(network_data[, -1])
adj_matrix
     User1 User2 User3 User4 User5 User6
[1,]     0     1     1     0     0     0
[2,]     1     0     1     1     0     1
[3,]     1     1     0     1     1     0
[4,]     0     1     1     0     1     0
[5,]     0     0     1     1     0     1
[6,]     0     1     0     0     1     0
rownames(adj_matrix) <- user_labels

##Performing the check

# Check if the adj matrix is a square
dim(adj_matrix)
[1] 6 6
nrow(adj_matrix) == ncol(adj_matrix)
[1] TRUE
## We get 6x6 and it return True, therefor the adj matrix is a square

# Check the diagonal
diag(adj_matrix)
User1 User2 User3 User4 User5 User6 
    0     0     0     0     0     0 
# Check whether all diagonal values are zero
all(diag(adj_matrix) == 0)
[1] TRUE
# Check whether the matrix is symmetric
isSymmetric(adj_matrix)
[1] TRUE
# Check row and cols labels
rownames(adj_matrix)
[1] "User1" "User2" "User3" "User4" "User5" "User6"
colnames(adj_matrix)
[1] "User1" "User2" "User3" "User4" "User5" "User6"
# Check that row and col s name match
identical(rownames(adj_matrix), colnames(adj_matrix))
[1] TRUE

##Visualization

#install.packages("igraph")
library(igraph)
Warning: package 'igraph' was built under R version 4.5.2

Attaching package: 'igraph'
The following objects are masked from 'package:lubridate':

    %--%, union
The following objects are masked from 'package:dplyr':

    as_data_frame, groups, union
The following objects are masked from 'package:purrr':

    compose, simplify
The following object is masked from 'package:tidyr':

    crossing
The following object is masked from 'package:tibble':

    as_data_frame
The following objects are masked from 'package:stats':

    decompose, spectrum
The following object is masked from 'package:base':

    union
network_graph <- graph_from_adjacency_matrix(
  adj_matrix,
  mode = "undirected",
  diag = FALSE
)
network_graph
IGRAPH 949d627 UN-- 6 9 -- 
+ attr: name (v/c)
+ edges from 949d627 (vertex names):
[1] User1--User2 User1--User3 User2--User3 User2--User4 User2--User6
[6] User3--User4 User3--User5 User4--User5 User5--User6
plot(
  network_graph,
  vertex.label = V(network_graph)$name,
  main = "Social Media Network Analysis"
)

##Interpretation of the graph

Based on the graph, User2 and User3 each have four direct connections, which is the highest number of direct connections in the network. Therefore, based only on degree, they are tied. However, counting connections alone does not consider the importance of the users they are connected to. In Part B, eigenvector analysis will be used to compare their structural influence in the network.

Part B Eigen Analysis

1. Compute eigenvalues

eigen_result <- eigen(adj_matrix)

eigen_result$values
[1]  3.1691946  0.7282124  0.2798483 -0.4662996 -1.5057879 -2.2051678
eigen_result$vectors
           [,1]       [,2]       [,3]        [,4]        [,5]       [,6]
[1,] -0.3128407  0.6076307  0.1486190 -0.43625248  0.54837138 -0.1407144
[2,] -0.4824825  0.2650812  0.3661540  0.47990106 -0.14307832  0.5586567
[3,] -0.5089707  0.1774030 -0.3245633 -0.27647672 -0.68265268 -0.2483579
[4,] -0.4339344 -0.1741920 -0.4406856  0.54093404  0.40153969 -0.3651171
[5,] -0.3837695 -0.5693330 -0.1649159 -0.45566165  0.22109739  0.4948455
[6,] -0.2733351 -0.4178063  0.7190975 -0.05198249 -0.05181279 -0.4777425
# the dominant eigen value
dominant_index <- which.max(abs(eigen_result$values))
dominant_index
[1] 1
dominant_eigenvalue <- eigen_result$values[dominant_index]
dominant_eigenvalue
[1] 3.169195
v <- eigen_result$vectors[, dominant_index]
v
[1] -0.3128407 -0.4824825 -0.5089707 -0.4339344 -0.3837695 -0.2733351
# Check for dominant eigen value
all.equal(
 as.vector(adj_matrix %*% v),
 as.vector(dominant_eigenvalue * v)
)
[1] TRUE
# The most influential user
abs(v)
[1] 0.3128407 0.4824825 0.5089707 0.4339344 0.3837695 0.2733351
user_labels[which.max(abs(v))]
[1] "User3"

##Interpretation

The eigenpair satisfies the relationship Av = \(\lambda\)v, where A is the adjacency matrix, \(\lambda\)=3.1691946 is the dominant eigenvalue, and v is its corresponding eigenvector. The all.equal() result returns TRUE, confirming numerically that Av ≈ \(\lambda\)v.

# direct connections
direct_connections <- rowSums(adj_matrix)

results <- data.frame(
  User = user_labels,
  Direct_Connections = direct_connections,
  Eigenvector_Score = abs(v)
)

results[order(-results$Eigenvector_Score), ]
       User Direct_Connections Eigenvector_Score
User3 User3                  4         0.5089707
User2 User2                  4         0.4824825
User4 User4                  3         0.4339344
User5 User5                  3         0.3837695
User1 User1                  2         0.3128407
User6 User6                  2         0.2733351

#Interpretation and Analysis

The dominant eigenvalue is approximately 3.1692. Using the corresponding eigenvector, the largest absolute component is approximately 0.5090 and belongs to User3. User2 has a slightly lower score of approximately 0.4825. Although User2 and User3 are tied with four direct connections each, User3 has the highest eigenvector-centrality score. Therefore, User3 has the greatest structural influence according to this network analysis.

#Part C: Business recommendation

Based on the network analysis, User3 should be considered a priority candidate for the marketing campaign. User2 and User3 both have four direct connections, but User3 has the highest eigenvector-centrality score, approximately 0.509, while User2 has a score of approximately 0.482. This shows why counting connections alone is not enough. Eigenvector centrality also considers the structural importance of the users to whom each user is connected.

Eigenvectors are useful in this analysis because the components of the dominant eigenvector provide relative measures of structural influence within the network. A user connected to other important users can receive a higher score even if another user has the same number of direct connections. In this network, that distinction helps separate User3 from User2 even though their direct connection counts are equal.

However, network structure alone is not enough to determine the best person for a marketing campaign. The analysis does not include information such as follower count, engagement rate, audience demographics, geographic reach, brand relevance, previous campaign performance, authenticity, or cost. These factors could change the final business decision.

Therefore, User3 can be prioritized as the strongest candidate based on network structure, but additional marketing information should be collected before making the final decision. User2 may also be worth considering because User2 has the same number of direct connections and the second-highest eigenvector-centrality score.