── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): From Acoount, To Account
dbl (1): Frequency
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 7 Columns: 2
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): Source, Destination
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 7 Columns: 2
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): Name
dbl (1): age
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Undirected edgelist
library(igraph)
Warning: package 'igraph' was built under R version 4.2.1
Attaching package: 'igraph'
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
g <-graph.edgelist(as.matrix(source_accountDestination),directed =FALSE)g
IGRAPH bc1823c UN-- 7 7 --
+ attr: name (v/c)
+ edges from bc1823c (vertex names):
[1] Valentine--Mcnamara Valentine--Loid Valentine--Nyaradzo
[4] Valentine--Stephanie Valentine--George Stephanie--George
[7] George --Tinashe
Directed Edgelist
D <-graph.edgelist(as.matrix(source_accountDestination),directed =TRUE)D
IGRAPH bc2e018 DN-- 7 7 --
+ attr: name (v/c)
+ edges from bc2e018 (vertex names):
[1] Valentine->Mcnamara Valentine->Loid Valentine->Nyaradzo
[4] Valentine->Stephanie Valentine->George Stephanie->George
[7] George ->Tinashe
Inspecting our source_destination key
V(g)
+ 7/7 vertices, named, from bc1823c:
[1] Valentine Mcnamara Loid Nyaradzo Stephanie George Tinashe
E(g)
+ 7/7 edges from bc1823c (vertex names):
[1] Valentine--Mcnamara Valentine--Loid Valentine--Nyaradzo
[4] Valentine--Stephanie Valentine--George Stephanie--George
[7] George --Tinashe
gorder(g)
[1] 7
gsize(g)
[1] 7
Vizualising the Social Network undirected
plot(g)
Vizualising the Social Network directed
plot(D)
Network Attributes
Vertex attributes
g
IGRAPH bc1823c UN-- 7 7 --
+ attr: name (v/c)
+ edges from bc1823c (vertex names):
[1] Valentine--Mcnamara Valentine--Loid Valentine--Nyaradzo
[4] Valentine--Stephanie Valentine--George Stephanie--George
[7] George --Tinashe
Edge attributes
Adding Vertex A
g <-set_vertex_attr(g,"age",value =c(20,25,21,23,24,23,22))vertex_attr(g)
erdos.renyi.game(n =gorder(g), p.or.m =edge_density(g), type ="gnp")
IGRAPH be41e4f U--- 7 5 -- Erdos-Renyi (gnp) graph
+ attr: name (g/c), type (g/c), loops (g/l), p (g/n)
+ edges from be41e4f:
[1] 2--3 3--4 2--6 1--7 5--7
Random graphs & randomization tests
Generate 1000 random graphs based on the original network
e.g. with the same number of vertices and approximate density.
Calculate the average path length of the original network.
Calculate the average path length of the 1000 random networks.
Determine how many random networks have an average path length greater or less than the original network’s average path length. Generate 1000 random graphs
# Identify key nodes using eigenvector centralityg.ec <-eigen_centrality(g)which.max(g.ec$vector)