################################################################################
################################### 0. Setup ###################################
################################################################################
# Set random seed
set.seed(42)
# Set network
network <- intergraph::asNetwork(SNA4DSData::Sampson$Sampson_like2)
################################################################################
############################## 1. Create Network ###############################
################################################################################
### 1.1. Directed Network
survey <- data.frame(respondent = NA, alter1 = NA, alter2 = NA)
edges <- data.frame(rbind(cbind(survey$respondent, survey$alter1),
cbind(survey$respondent, survey$alter2)))
vertices <- unique(c(survey$respondent, survey$alter1, survey$alter2))
network <- igraph::graph_from_data_frame(edges, vertices, directed = TRUE)
### 1.2 Convert igraph::igraph to sna::network
intergraph::asNetwork(network)
### 1.3 Convert sna::network to igraph::igraph
intergraph::asIgraph(network)
################################################################################
############################### 2. Descriptives ################################
################################################################################
### 2.1 Print Description
igraph::print.igraph(network)
### 2.2 Print Diameter
igraph::diameter(network)
### 2.3 Print Dyad Census (???)
igraph::dyad.census(network)
### 2.4 Print Density
igraph::edge_density(network)
### 2.5 Print Reciprocity
igraph::reciprocity(network)
### 2.6 Print Transitivity
igraph::transitivity(network)
sna::gtrans(network, mode = "digraph") # digraph = directed, graph = undirected
### 2.7 Print Betweenness Centrality
igraph::centralization.betweenness(network)
### 2.8 Print Closeness Centrality
igraph::centralization.closeness(network)
### 2.9 Print Mean Distance (average path length)
igraph::mean_distance(network)
################################### 0. Setup ###################################
################################################################################
# Set random seed
set.seed(42)
# Set network
network <- intergraph::asNetwork(SNA4DSData::Sampson$Sampson_like2)
################################################################################
############################## 1. Create Network ###############################
################################################################################
### 1.1. Directed Network
survey <- data.frame(respondent = NA, alter1 = NA, alter2 = NA)
edges <- data.frame(rbind(cbind(survey$respondent, survey$alter1),
cbind(survey$respondent, survey$alter2)))
vertices <- unique(c(survey$respondent, survey$alter1, survey$alter2))
network <- igraph::graph_from_data_frame(edges, vertices, directed = TRUE)
### 1.2 Convert igraph::igraph to sna::network
intergraph::asNetwork(network)
### 1.3 Convert sna::network to igraph::igraph
intergraph::asIgraph(network)
################################################################################
############################### 2. Descriptives ################################
################################################################################
### 2.1 Print Description
igraph::print.igraph(network)
### 2.2 Print Diameter
igraph::diameter(network)
### 2.3 Print Dyad Census (???)
igraph::dyad.census(network)
### 2.4 Print Density
igraph::edge_density(network)
### 2.5 Print Reciprocity
igraph::reciprocity(network)
### 2.6 Print Transitivity
igraph::transitivity(network)
sna::gtrans(network, mode = "digraph") # digraph = directed, graph = undirected
### 2.7 Print Betweenness Centrality
igraph::centralization.betweenness(network)
### 2.8 Print Closeness Centrality
igraph::centralization.closeness(network)
### 2.9 Print Mean Distance (average path length)
igraph::mean_distance(network)