** This page is now updated for igraph version 0.6.3 in R 2.15.2 (Feb 2, 2013)
In both statnet and igraph, you start with importing a dataset, which you convert into either a "network object" (statnet) or "igraph object" (igraph). Basically, it's just telling R to recognize a given set of numbers as something to be manipulated in the network analysis framework.
There are several formats in which you can save data for use in social network analysis, (1) adjacency matrix, (2) edge lists, (3) adjacency lists (or node lists) and (4) affiliation matrix/incidence matrix. I will talk about affiliation matrices in a separate section for bipartite networks.
(1) An adjacency matrix is a matrix in which the rows and columns represent different nodes or vertices (i.e., the dots on the sociogram). In an unweighted adjacency matrix, the edges (i.e., lines) are represented by 0 or 1, with indicating that these two nodes are connected. If two nodes are connected, they are said to be adjacent (hence the name, adjacency matrix). In a weighted matrix, however, you can have different values, indicating different edge qualities (or tie strenghts). Here is an example of a hypothetical adjacency matrix of birds with 5-digit ID numbers.
You can import an adjacency matrix into a usable format in either statnet or igraph using these sample codes (note, this is for an unweighted matrix):
In igraph version 0.6, the way the igraph object is displayed has changed. The above code will return:
The letters on the first line (there can be up to 4) indicates some basic information about the graph. The first letter indicates whether this is a directed ('D') or undirected ('U') graph. The 2nd letter tells you if this is a named ('N') graph--i.e., whether or not the vertex set has a 'name' attribute. The 3rd letter tells you if this graph is weighted ('W'). The fourth letter is 'B' for bipartite graphs. These letter codes are followed by two numbers: the first is the number of vertices and the second is the number of edges.
The second line gives you information about the 'attributes' associated with the graph. In this case, there is only one attribute, called 'name', which is associated with the vertex set.
equivalent in statnet:
(2) An edge list is a two-column list of the two nodes that are connected in a network. Here's the same data as above, but in an edge list form.
**You can also easily input edgelists in igraph or statnet. HOWEVER, there is one major annoyance with statnet: it tends to read the numbers as continuous numbers, inputting this list directly will produce a network with 58256 nodes (the highest number)--most of which will not be connected. The code provided below gets around the problem, but it was very annoying at first. You will not have this problem if your node IDs are not numerical.
The simplest workaround for this is to make sure that the IDs are read as characters:
**A much easier way to import an edge list in igraph is to use the graph.data.frame() function:
(3) An adjacency list, also known as a node list, presents the 'focal' node on the first column, and then all the other nodes that are connected to it (i.e., adjacent to it) as columns to the right of it.
This is sometimes a convenient way to organize the data from the field... However, the major downside is that it is not very easy to import data this way into igraph or statnet. igraph DOES support importing an adjacency list into a graph object, but you need the data to be in a specific format (a 'list object', with row as a different vector)... I can't get this to work. The best way to deal with it seems to be to use the codes below to convert the adjacency list into an edgelist. I'm going to assume the data is in the format as shown above, with the first row being column names, and saved as a .csv file:
.... now you have an edgelist, saved as "el" that you can import into igraph or statnet using the codes provided above in the "edgelist" section.
... and here's a set of codes to convert adjacency lists into adjacency matrix, written by Dave McDonald.
**Note: I have received some feedback indicating that the following code produces errors when copied & pasted. I'm not sure if it's something wonky with how the text appears on the website... In any case, I now provide a text file you can download at the bottom of the page, just in case.
(4) An affiliation network is one in which edges are defined by co-membership in groups. Many social networks are defined this way. Conceptually, this ends up being a form of bipartite graph. Thus, I will discuss these at length in a separate page called "affiliation/bipartite networks".