Visualizing 60 years of International Commerce

Author: Xavier Fernández-i-Marín
December 19, 2011 - 4 minutes
R Spatial models

Commercial ties between countries

Recent trends in Comparative Political Analysis include the addition of spatial techniques. By means of spatial techniques the factors that help explaining a feature of countries go beyond the usual “internal” factors and include the interaction of countries between them.

The economic links between countries seem to be amongst the most used indicators of relationship between countries. Other measures include the distances, or whether the countries share regional borders.

Kristian Skrede Gleditsch has worked in providing estimates of trade flows between independent states (1948-2000). The dataset presents the amount of imports and exports between all independent states in the post Second World War period, using different sources.

Unfortunately, the dataset stops at 2000, but it is still a valuable resource for social researchers.

Although the information aggregated and compiled by Skrede Gleditsch is very valuable, it is of low practical use due to the large amount of data, which makes it difficult to be represented in a meaningful way. In order to be able to get a sense of the relationships between countries it is not sufficient to have the raw amount of trade between countries.

Using matrices to represent the data

The most convenient way to work with such data is by using a Weighting matrix. That is, a row-normalized square matrix with zeros in the diagonal.

The following figure represents the weighting matrix of imports for all the countries in the sample for the year 2000. The color of the squares represents the strength of the relationship in commercial terms of country in the row versus all other countries (in the columns). A darker color means that the country in the row imports a great percentage of its total imports from the country in the column. By contrast, lighter squares represent weak commercial ties (from the perspective of row countries). Consult the list of abbreviations of the country names.

Historical perspective on commercial relationships

In addition to the fixed photo for a single year, the dataset provides historical perspective. In this case, a concatenation of images is necessary. The following video shows 60 years of imports between the 25 countries with higher amount of commercial activity in 2000. The weights in this case are calculated only between them.

<video width=“650”, height=“640” controls=“controls”>

There are many things to comment out about this video.

The importance of weighting matrices

The weighting matrices not only help visualizing the raw data, but also are the intermediate value needed in many research designs that employ spatial regression techniques.

Code to generate the plots and the video

The plots have been generated in R using the “color2Dmatplot” function created by Jim Lemon, in the plotrix package. Ideally, a Hinton Diagram would be the best option to represent weighting matrices, but it is not yet available in R.

## -- Imports, Global, 25 biggest countries
xc for (t in 1:length(dimnames(imp)$year)) {
  svg(file=paste("plots-weights/import-25countries-", dimnames(imp)$year[t], ".svg", sep=""),
    width=10, height=10)
  cl   color2D.matplot(W.imp[t,xc,xc],
    border="white", cellcolors=cl,
    show.legend=FALSE, axes=FALSE, xlab="", ylab="")
  axis(1, at=0.5:length(Nc[xc]), labels=namc[xc], las=2, cex.axis=1)
  axis(2, at=rev(0.5:length(Nc[xc])), labels=namc[xc], las=1, cex.axis=1)
  title(paste("Imports of row from column", dimnames(imp)$year[t], sep=" - "))

The “W.imp” object is the weighting matrix. In fact, it is three dimensions array, with the years in the first dimension, the origin country in the second and the destination countries in the third.

Independent plot files have been glued using mencoder.

mencoder mf://import-25countries-*.png \
-mf fps=1:type=png \
-ovc lavc \
-lavcopts vcodec=mpeg4 \
-oac copy \
-o video-commerce_imports_25.avi

The Ogg Theora version of the video has been obtained by using ffmpeg2theora.

ffmpeg2theora video-commerce_imports_25.avi

Comparison of Rhat versions: clarifying formulas for the potential scale reduction factor and its implications

Author: Xavier Fernández-i-Marín
March 6, 2019 - 7 minutes
Description of how to calculate Rhat (Potential Scale Reduction Factor) for Bayesian convergence usind different formulas, and its impact on the length of the chains
ggmcmc R Bayesian

Families and batches of parameters in Bayesian inference: how to treat them using ggmcmc

Author: Xavier Fernández-i-Marín
February 22, 2019 - 10 minutes
Tutorial of how to deal with families of parameters in Bayesian inference using ggmcmc
ggmcmc R Bayesian

V-Dem by default: Load and process V-Dem democracy scores in R

Author: Xavier Fernández-i-Marín
January 11, 2019 - 6 minutes
Tutorial of how to perform data analysis of the Varieties of Democracies (V-Dem) dataset in R
Governance R Data visualization
comments powered by Disqus