This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
library(igraph)
# Load data from a CSV file (you may need to use setwd to set your working directory):
# 1. read data into a matrix
# 2. create a graph
# 3. plot the graph
#I plotted table1 as well just to see the slight differences.
#table1
relations_1 <- as.matrix(read.csv('846 Lesson 5 2006 Koschade Table 1.csv', header =T, row.names = 1))
g_1 <- graph.adjacency(relations_1, mode = "undirected", weighted = TRUE)
plot(g_1, layout = layout_with_kk, vertex.label.cex = 0.75, edge.width=E(g)$weight)
#table2
relations <- as.matrix(read.csv('846 Lesson 5 2006 Koschade Table 2.csv', header =T, row.names = 1))
g <- graph.adjacency(relations, mode = "undirected", weighted = TRUE)
plot(g, layout = layout_with_kk, vertex.label.cex = 0.75, edge.width=E(g)$weight)
NA
NA
NA
# 1. Look at the practice session to see how these measures are calculated
# 2. Record your observations, i.e., what can you say about the network based on these measures
#table1
size_g1 <- length(V(g_1))
average_distance_g1 <- mean_distance(g_1)
diameter_g1 <- diameter(g)
basic_topography_g1 <- matrix(c(size_g1, average_distance_g1, diameter_g1), nrow=1, ncol=3)
colnames(basic_topography_g1) <- c('size', 'average distance', 'diameter')
rownames(basic_topography_g1) <- c('Table1')
as.table(basic_topography_g1)
size average distance diameter
Table1 17.000000 1.588235 6.000000
# table 2
size_g <- length(V(g))
average_distance_g <- mean_distance(g)
diameter_g <- diameter(g)
basic_topography_g <- matrix(c(size_g, average_distance_g, diameter_g), nrow=1, ncol=3)
colnames(basic_topography_g) <- c('size', 'average distance', 'diameter')
rownames(basic_topography_g) <- c('Table2')
as.table(basic_topography_g)
size average distance diameter
Table2 17.000000 3.102941 6.000000
# 1. Look at the practice session to see how these measures are calculated
# 2. Record your observations, i.e., what can you say about the network based on these measures
#table1
degree_centralization_g1 <- centralization.degree(g_1)$centralization
degree_sd_g1 <-sd(centralization.degree(g_1)$res)
closeness_centralization_g1 <- centralization.closeness(g_1)$centralization
closeness_sd_g1 <-sd(centralization.closeness(g_1)$res)
betweenness_centralization_g1 <- centralization.betweenness(g_1)$centralization
betweenness_sd_g1 <- sd(centralization.betweenness(g_1)$res)
centralization_g1 <- matrix(c(degree_centralization_g1, degree_sd_g1, closeness_centralization_g1, closeness_sd_g1, betweenness_centralization_g1, betweenness_sd_g1), nrow=1, ncol=6)
colnames(centralization_g1) <- c('degree cent', 'degree cent. SD', 'closeness cent.', 'closeness cent. SD', 'betweenness cent.', 'betweenness cent. SD')
rownames(centralization_g1) <- c('Table1')
as.table(centralization_g1)
degree cent degree cent. SD closeness cent. closeness cent. SD betweenness cent. betweenness cent. SD
Table1 0.4742647 3.0012252 0.6503460 0.1079152 0.4999132 14.6311750
#table2
degree_centralization_g <- centralization.degree(g)$centralization
degree_sd_g <-sd(centralization.degree(g)$res)
closeness_centralization_g <- centralization.closeness(g)$centralization
closeness_sd_g <-sd(centralization.closeness(g)$res)
betweenness_centralization_g <- centralization.betweenness(g)$centralization
betweenness_sd_g <- sd(centralization.betweenness(g)$res)
centralization_g <- matrix(c(degree_centralization_g, degree_sd_g, closeness_centralization_g, closeness_sd_g, betweenness_centralization_g, betweenness_sd_g), nrow=1, ncol=6)
colnames(centralization_g) <- c('degree cent', 'degree cent. SD', 'closeness cent.', 'closeness cent. SD', 'betweenness cent.', 'betweenness cent. SD')
rownames(centralization_g) <- c('Table2')
as.table(centralization_g)
degree cent degree cent. SD closeness cent. closeness cent. SD betweenness cent. betweenness cent. SD
Table2 0.4742647 3.0012252 0.6503460 0.1079152 0.4999132 14.6311750
#table1
density_g1 <- edge_density(g_1)
average_degree_g1 <- mean(degree(g_1))
cohesion_g1 <- cohesion(g_1)
compactness_g1 <- mean(closeness(g_1))
global_clustering_coefficient_g1 <- transitivity(g_1,type="global")
interconnectedness_g1 <- matrix(c(density_g1, average_degree_g1, cohesion_g1, compactness_g1, global_clustering_coefficient_g1), nrow=1, ncol=5)
colnames(interconnectedness_g1) <- c('density', 'average degree', 'cohesion', 'compactness', 'clustering coefficient')
rownames(interconnectedness_g1) <- c('Table1')
as.table(interconnectedness_g1)
density average degree cohesion compactness clustering coefficient
Table1 0.46323529 7.41176471 1.00000000 0.04031273 0.78781513
#table2
density_g <- edge_density(g)
average_degree_g <- mean(degree(g))
cohesion_g <- cohesion(g)
compactness_g <- mean(closeness(g))
global_clustering_coefficient_g <- transitivity(g,type="global")
interconnectedness_g <- matrix(c(density_g, average_degree_g, cohesion_g, compactness_g, global_clustering_coefficient_g), nrow=1, ncol=5)
colnames(interconnectedness_g) <- c('density', 'average degree', 'cohesion', 'compactness', 'clustering coefficient')
rownames(interconnectedness_g) <- c('Table2')
as.table(interconnectedness_g)
density average degree cohesion compactness clustering coefficient
Table2 0.46323529 7.41176471 1.00000000 0.02082932 0.78781513
Add a new chunk by clicking the *Insert Chunk* button on the toolbar or by pressing *Ctrl+Alt+I*.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the *Preview* button or press *Ctrl+Shift+K* to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike *Knit*, *Preview* does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.