06: International Relations#

This week we’ll explore community structure and structural balance in a signed network of international relations. Go to the Datasets page in the textbook and download the “CoW” network. “CoW” stands for Correlates of War, and this dataset encodes countries’ alliances or enmities as a positive or negative relation.

The CoW network is a Pajek dataset, so you’ll need to use NetworkX’s read_pajek() function. This function automatically creates MultiGraphs, which we haven’t learned about yet. Before you begin, convert the multigraph to a standard Graph object with the following code:

Show code
MG = nx.read_pajek('yourfilename.net')
G = nx.Graph()

for n, nbrs in MG.adjacency():
  for nbr, edict in nbrs.items():
      sumvalue = sum([d['weight'] for d in edict.values()])
      G.add_edge(n, nbr, weight = sumvalue)

In a short Jupyter notebook report, answer the following questions about this network. Don’t simply calculate the answers: make sure you’re fully explaining (in writing) the metrics and visualizations that you generate. Consider the Criteria for Good Reports as a guide. You can create markdown cells with section headers to separate the different sections of the report. Rather than number the report as if you’re answering distinct questions, use the questions as a guide to do some data storytelling, i.e. explain this network’s data in an organized way.

  1. Is this network structurally balanced or not? Determine the number of cycles (or loops) in the network that have an even number of negative edges, and compare it to the number of cycles that have an odd number of negative edges. What does that tell you about the network?

n.b. Solving this will require some creative coding! Remember what you’ve learned about NetwortX Graph objects and about looping and iterating in Python. Refer back to the guides in the textbook for ideas. You might also find some ideas in the sections on Working with Graph Objects and Community detection.

  1. Find communities in this network using both the Girvan-Newman and Louvain methods. Which method seems to work better? There is a problem with running community detection on this graph! Interpret your results and try to define the problem—have these methods done a good job of finding communities? Once you spot the problem, can you figure out what you think is causing it? Include two visualizations of the network in Altair, with colors for each community detection method. (As an alternative, you could make one visualization with a switch that changes the colors between Louvain and Girvan-Newman.)

  2. Is the number of cycles with an odd number of negative edges statistically significant? Create a permutation test to randomly change the configuration of positive and negative edges in this network (but not the total number of positive and negative edges). Create a histogram of the random results showing your observed value, and calculate the p-value. This will be very similar to what you did for homophily last week.

When you’re finished, remove these instructions from the top of the file, leaving only your own writing and code. Export the notebook as an HTML file, check to make sure everything is formatted correctly, and submit your HTML file to Sakai.