1. Preparation

First, we install the required packages.

We have a workshop package that contains the data we will be working with and some utility functions.

Next, we load the libraries.

As you can see from the output, loading the ergm package also loaded the network package.

There are also these references to the statnet project. They are the main developers of ERGM functionalities in R.

2. Building our networks

First, load the data.

The data sets we will be using are part of the workshop package. We start with the militarized interstate dispute data from Zeev Maoz.

checkmat() is a utility function that plots the supplied adjacency matrix.

Note about plotting: You can ignore the plotting options if you are not using a jupyter notebook.

Next, we use the network function to create a network object.

There are different ways network data is usually stored.

The adjacency matrix format is generally the easiest to work with, but it can take a lot of space.

Sometimes, we will have edgelists instead. In fact, unless you have pre-prepared network data, edgelists are usually what you'll have.

We need to be careful when working with them.

What's the difference?

Where are the isolates?

The edgelist does not contain information about them.

When working with this kind of data, we have to make sure we have a list of the full actors in the network.

Let's manually make the adjacency matrix from the edgelist.

Let's get back to working with our network.

Let's work with vertex attributes.

The %v% operator is how to access vertex/node variables from the network object.

We can look at how democracies and nondemocracies differ in conflict behavior.

Red nodes are democracies and black are nondemocracies.

Edge attributes can also be specified in a similar way but it's easier to just use a separate matrix.

These are the geographical contiguity and joint-democracy networks.

3. Specifying the ERGM

Let's take a look at the basic function for ERGM fitting: ergm.

ergm(network ~ ergm-terms)

What are the ERGM terms that we can use?

3.1 ERGM Terms

3.2 Starting to fit an ERGM

We start with some node and dyad variables.

Let's compare it with the logistic regression.

They are exactly the same.

Let's move to some network effects.

What happened here?

So instead, we can use alternative network statistics designed to address these problems.

References:

Hunter, DR et al. 2008. "ergm: A package to fit, simulate and diagnose exponentiall-family models for networks." Journal of Statistical Software.

Snijders, T et al. 2006. "New specifications for exponential random graph models." Sociological Methodology.

Looks like it converged.

Let's also add the triadic closure effect before looking at the model in more detail.

Again, seems like we have degeneracy.

Looks like it converged.

3.2.1 Let's consider model fit, degeneracy, and decay parameters

How to understand the decay parameters?

Reference:

Levy, M. 2016. "gwdegree: Improving interpretation of geometrically-weighted degree estimates in exponential random graph models." Journal of Open Source Software.

This is easiest to demonstrate using the gwesp.

The summary function is very useful when provided with an ERGM model.

summary(network ~ ergm-terms)

What happened?

Let's look at a real example using our MIDs network.

Slightly increasing the decay value improved fit and didn't run into degeneracy issues.

3.3 Assessing ERGM fit

Back to our MIDs model; it seems like our model converged, but we should still check the fit using simulations.

What are we looking at?

But it helps to compare.

3.4 Interpreting the ERGM output

Let's bring up the model output again.

At the network level:

At the dyad level:

$P(y_{ij} = 1 | Y, \mathbf{\theta}) = logit ^{-1}(\sum^k_{r=1}\theta_r \delta_r^{(ij)}Y)$

  • conditional log odds of a tie given a one unit change in the statistic
  • for the less complicated terms, it becomes the conditional log odds of a tie given that it is part of the local configuration one more time

Let's illustrate using a simple example and the same coefficients.

Just a simple three node network with two ties to show tie formation on the empty dyad

What's the probability of a tie forming on the empty dyad (2,3) if this network has the same generative features of our conflict network?

There are two types of dyads here:

Adding an edge on the (2,3) dyad will add...

Why does gwdegree not change?

Let's look at the degree distribution:

nodes with degree: 0 1 2
w/o (2,3) edge 0 2 1
w/ (2,3) edge 0 0 3

Calculate the log-odds.

$(-4.70 \times 1) + (-0.15 \times 2) + (-0.21 \times 1) + (-0.64 \times 0) + (1.15 \times 3) = -1.76$

Calculate the corresponding probability.

At the block level:

Reference:

Desmarais, BA & Cranmer, SJ. 2012. "Micro-level interpretations of exponential random graph models with applications to estuary networks." Policy Studies Journal.

3.5 ERGM Settings

Let's conclude this section by looking at some settings and useful things to do.

See all the settings with ?control.ergm

We don't get any likelihood-based statistics. We can follow the instructions to add them.

Increasing the MCMC samples can improve our estimates.

4. Resources and References

Packages

statnet suite of packages have lots of extensions of the ERGM and other network methods

xergm package: lots of extensions to the ERGM

gwdegree package: helps with understanding gwdegree terms (https://github.com/michaellevy/gwdegree)

References

Desmarais, BA & Cranmer, SJ. 2012. "Micro-level interpretations of exponential random graph models with applications to estuary networks." Policy Studies Journal.

Hunter, DR et al. 2008. "ergm: A package to fit, simulate and diagnose exponentiall-family models for networks." Journal of Statistical Software.

Levy, M. 2016. "gwdegree: Improving interpretation of geometrically-weighted degree estimates in exponential random graph models." Journal of Open Source Software.

Snijders, T et al. 2006. "New specifications for exponential random graph models." Sociological Methodology.

5. Questions or comments?

Please visit the Github repository for this notebook.

Or email me at ted.hsuanyun.chen@gmail.com.