How to use this package

Mauricio Vargas

2019-11-24

Basic trade example

Package data

I’ll use this demo dataset to illustrate the essential usage of the functions within this package.

## # A tibble: 44,435 x 3
## # Groups:   reporter_iso [158]
##    country product   value
##    <chr>   <chr>     <dbl>
##  1 afg     0106        621
##  2 afg     0405       3380
##  3 afg     0407      60807
##  4 afg     0501    1466840
##  5 afg     0504    1466840
##  6 afg     0703      85258
##  7 afg     0712       9057
##  8 afg     0714     164694
##  9 afg     0801    8482381
## 10 afg     0802    8437060
## # … with 44,425 more rows

Revealed comparative Advantage (RCA)

You can obtain RCA with ec_rca().

## # A tibble: 44,435 x 3
##    country product value
##    <chr>   <chr>   <dbl>
##  1 afg     0106        0
##  2 afg     0405        0
##  3 afg     0407        0
##  4 afg     0501        1
##  5 afg     0504        1
##  6 afg     0703        0
##  7 afg     0712        0
##  8 afg     0714        1
##  9 afg     0801        1
## 10 afg     0802        1
## # … with 44,425 more rows

Another possibility is to obtain RCA as a matrix or tibble without discretization.

## # A tibble: 44,435 x 3
##    country product    value
##    <chr>   <chr>      <dbl>
##  1 afg     0106     0.0412 
##  2 afg     0405     0.00944
##  3 afg     0407     0.275  
##  4 afg     0501    14.4    
##  5 afg     0504    20.7    
##  6 afg     0703     0.271  
##  7 afg     0712     0.220  
##  8 afg     0714     3.18   
##  9 afg     0801    34.4    
## 10 afg     0802    48.0    
## # … with 44,425 more rows

Complexity Measures

You can compute both Economic Complexity Index (ECI) and Product Complexity Index (PCI) by using ec_complexity_measures(). The calculations methods are fitness (default), reflections and eigenvalues. See (Hausmann et al. 2014) and (Mariani et al. 2015) for the methodological details.

## $complexity_c
## # A tibble: 158 x 2
##    country value
##    <chr>   <dbl>
##  1 deu     28.8 
##  2 fra     21.4 
##  3 usa     14.1 
##  4 nld     11.5 
##  5 che     10.5 
##  6 gbr      9.81
##  7 ita      9.61
##  8 swe      7.35
##  9 aut      7.34
## 10 jpn      7.27
## # … with 148 more rows
## 
## $complexity_p
## # A tibble: 991 x 2
##    product value
##    <chr>   <dbl>
##  1 7111     75.1
##  2 2850     55.9
##  3 8804     32.1
##  4 9307     24.7
##  5 9112     20.2
##  6 3505     19.6
##  7 3813     14.3
##  8 7507     12.6
##  9 2927     12.1
## 10 2810     11.8
## # … with 981 more rows
## 
## $diversity
## # A tibble: 158 x 2
##    country value
##    <chr>   <dbl>
##  1 afg        28
##  2 ago        52
##  3 alb        32
##  4 and        23
##  5 ant        23
##  6 are         1
##  7 arg        83
##  8 aus        81
##  9 aut       290
## 10 bdi        16
## # … with 148 more rows
## 
## $ubiquity
## # A tibble: 991 x 2
##    product value
##    <chr>   <dbl>
##  1 0101       19
##  2 0102       26
##  3 0103       16
##  4 0104       19
##  5 0105       11
##  6 0106       35
##  7 0201       21
##  8 0203       15
##  9 0204        6
## 10 0205       12
## # … with 981 more rows

Proximity

Proximity matrices are used to create both country-country and product-product networks. Using proximity_matrices() is straightforward.

## $proximity_c
## # A tibble: 10,432 x 3
##    from  to      value
##    <chr> <chr>   <dbl>
##  1 ago   afg   0.0962 
##  2 alb   afg   0.219  
##  3 arg   afg   0.120  
##  4 aus   afg   0.111  
##  5 aut   afg   0.00690
##  6 bdi   afg   0.0714 
##  7 bel   afg   0.00938
##  8 ben   afg   0.107  
##  9 bfa   afg   0.0816 
## 10 bgr   afg   0.0945 
## # … with 10,422 more rows
## 
## $proximity_p
## # A tibble: 417,822 x 3
##    from  to    value
##    <chr> <chr> <dbl>
##  1 0102  0101  0.346
##  2 0103  0101  0.263
##  3 0104  0101  0.421
##  4 0106  0101  0.2  
##  5 0201  0101  0.381
##  6 0203  0101  0.474
##  7 0204  0101  0.158
##  8 0205  0101  0.368
##  9 0206  0101  0.316
## 10 0207  0101  0.368
## # … with 417,812 more rows

Networks

The proximity_networks() function is designed to use igraph for the internal computations and also to pass proximity-based networks to igraph, ggraph or export to Cytoscape by saving the output as csv/tsv.

To create some reduced networks I’ll use a high proximity cutoff, so that the networks are limited to the spanning trees for clarity and fast rendering.

## $projection_c
## # A tibble: 157 x 3
##    from  to    value
##    <chr> <chr> <dbl>
##  1 irn   alb   0.375
##  2 irn   afg   0.5  
##  3 irn   tur   0.348
##  4 npl   afg   0.214
##  5 syr   afg   0.357
##  6 ago   ben   0.339
##  7 ago   per   0.358
##  8 ago   sen   0.308
##  9 sur   ant   0.304
## 10 sur   and   0.130
## # … with 147 more rows
## 
## $projection_p
## # A tibble: 990 x 3
##    from  to    value
##    <chr> <chr> <dbl>
##  1 9614  4202  0.529
##  2 9614  0101  0.579
##  3 0102  0201  0.5  
##  4 0102  0104  0.423
##  5 0103  0505  0.647
##  6 1102  1005  0.5  
##  7 1102  0105  0.417
##  8 4803  4707  0.615
##  9 4803  0105  0.417
## 10 0106  1302  0.514
## # … with 980 more rows

Just two basic examples with ggraph.

References

Hausmann, Ricardo, César Hidalgo, Sebastián Bustos, Michele Coscia, Alexander Simoes, and Muhammed Yildirim. 2014. The Atlas of Economic Complexity: Mapping Paths to Prosperity. MIT Press. https://doi.org/10.7551/mitpress/9647.001.0001.

Mariani, Manuel, Alexandre Vidmer, Matsúš Medo, and Yi-Cheng Zhang. 2015. “Measuring Economic Complexity of Countries and Products: Which Metric to Use?” The European Physical Journal B 88 (11). Springer: 293. https://doi.org/10.1140/epjb/e2015-60298-7.