In this exercise, we will explore some basic characteristics of social networks using the Moreno dataset. We will focus on understanding the size of the network, which is a fundamental aspect of network analysis.
First, we need to load the Moreno dataset.
The Moreno dataset is contained in the UserNetR
package, so make sure you have installed (see previous page).
The data can be loaded using the data()
function in R:
data(Moreno)
Once the dataset is loaded, we can visualize the network to get a basic understanding of its structure. In the following code, we color the nodes based on gender for better differentiation:
gender <- Moreno %v% "gender"
plot(Moreno, vertex.col = gender + 2, vertex.cex = 1.2)
Don’t worry if you don’t understand every line of code at this point. The details will become clearer as we progress through the exercises.
To determine the size of the network, we can use the network.size()
function.
This function returns the number of nodes in the network:
network.size(Moreno)
[1] 33
To determine the number of edges in the network, we can use the network.edgecount()
function.
network.edgecount(Moreno)
[1] 46
For more detailed information about the network, we can use the summary()
function.
This function provides a comprehensive overview of the network,
including the number of vertices and edges, network density, and attributes of vertices and edges:
summary(Moreno, print.adj=FALSE)
Network attributes:
vertices = 33
directed = FALSE
hyper = FALSE
loops = FALSE
multiple = FALSE
bipartite = FALSE
total edges = 46
missing edges = 0
non-missing edges = 46
density = 0.08712121
Vertex attributes:
gender:
numeric valued attribute
attribute summary:
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.000 1.000 2.000 1.515 2.000 2.000
vertex.names:
character valued attribute
33 valid vertex names
No edge attributes
Using the igraph Package
The previous sections used the network package because the Moreno dataset is a network object.
However, if you’re using the igraph package,
you can use the vcount()
function to get the number of vertices and the ecount()
function to get the number of edges.
Obtain the number of edges in the facebook dataset and store this amount in n_edges
.
To download the facebook dataset click: here1
Assume that: