├── .Rbuildignore ├── .github ├── .gitignore ├── FUNDING.yml └── workflows │ └── R-CMD-check.yaml ├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── launch.json └── settings.json ├── CODE_OF_CONDUCT.md ├── CRAN-SUBMISSION ├── DESCRIPTION ├── LICENSE.md ├── NAMESPACE ├── R ├── balassa_index.R ├── complexity_measures.R ├── complexity_outlook.R ├── cpp11.R ├── density.R ├── distance.R ├── economiccomplexity-package.R ├── helpers.R ├── productivity_levels.R ├── projections.R └── proximity.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── cleanup ├── codecov.yml ├── codemeta.json ├── configure ├── cran-comments.md ├── data ├── economiccomplexity_output.rda ├── world_gdp_avg_1998_to_2000.rda └── world_trade_avg_1998_to_2000.rda ├── dev ├── economiccomplexity_output.R ├── product_space_replication.R ├── world_gdp_avg_1998_to_2000.R └── world_trade_avg_1998_to_2000.R ├── docs ├── 404.html ├── CODE_OF_CONDUCT.html ├── LICENSE-text.html ├── LICENSE.html ├── apple-touch-icon.png ├── articles │ ├── economiccomplexity.html │ ├── economiccomplexity_files │ │ ├── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ │ └── figure-html │ │ │ ├── unnamed-chunk-18-1.png │ │ │ ├── unnamed-chunk-18-2.png │ │ │ ├── unnamed-chunk-19-1.png │ │ │ ├── unnamed-chunk-19-2.png │ │ │ ├── unnamed-chunk-19-3.png │ │ │ ├── unnamed-chunk-19-4.png │ │ │ ├── unnamed-chunk-19-5.png │ │ │ ├── unnamed-chunk-19-6.png │ │ │ ├── unnamed-chunk-20-1.png │ │ │ ├── unnamed-chunk-21-1.png │ │ │ ├── unnamed-chunk-22-1.png │ │ │ ├── unnamed-chunk-23-1.png │ │ │ ├── unnamed-chunk-24-1.png │ │ │ ├── unnamed-chunk-25-1.png │ │ │ └── unnamed-chunk-26-1.png │ └── index.html ├── authors.html ├── deps │ ├── bootstrap-5.3.1 │ │ ├── bootstrap.bundle.min.js │ │ ├── bootstrap.bundle.min.js.map │ │ └── bootstrap.min.css │ ├── bootstrap-toc-1.0.1 │ │ └── bootstrap-toc.min.js │ ├── clipboard.js-2.0.11 │ │ └── clipboard.min.js │ ├── data-deps.txt │ ├── font-awesome-6.4.2 │ │ ├── css │ │ │ ├── all.css │ │ │ ├── all.min.css │ │ │ ├── v4-shims.css │ │ │ └── v4-shims.min.css │ │ └── webfonts │ │ │ ├── fa-brands-400.ttf │ │ │ ├── fa-brands-400.woff2 │ │ │ ├── fa-regular-400.ttf │ │ │ ├── fa-regular-400.woff2 │ │ │ ├── fa-solid-900.ttf │ │ │ ├── fa-solid-900.woff2 │ │ │ ├── fa-v4compatibility.ttf │ │ │ └── fa-v4compatibility.woff2 │ ├── headroom-0.11.0 │ │ ├── headroom.min.js │ │ └── jQuery.headroom.min.js │ ├── jquery-3.6.0 │ │ ├── jquery-3.6.0.js │ │ ├── jquery-3.6.0.min.js │ │ └── jquery-3.6.0.min.map │ └── search-1.0.0 │ │ ├── autocomplete.jquery.min.js │ │ ├── fuse.min.js │ │ └── mark.min.js ├── favicon-96x96.png ├── favicon.ico ├── favicon.svg ├── index.html ├── katex-auto.js ├── lightswitch.js ├── link.svg ├── logo.svg ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── balassa_index.html │ ├── complexity_measures.html │ ├── complexity_outlook.html │ ├── country_aggregation.html │ ├── country_product_aggregation.html │ ├── dataframe_to_matrix.html │ ├── density.html │ ├── distance.html │ ├── economiccomplexity-package.html │ ├── economiccomplexity_output.html │ ├── figures │ │ └── logo.svg │ ├── index.html │ ├── productivity_levels.html │ ├── projections.html │ ├── proximity.html │ ├── rca.html │ ├── world_gdp_avg_1998_to_2000.html │ └── world_trade_avg_1998_to_2000.html ├── search.json ├── site.webmanifest ├── sitemap.xml ├── web-app-manifest-192x192.png └── web-app-manifest-512x512.png ├── economiccomplexity.Rproj ├── inst ├── REFERENCES.bib ├── paper.md └── paper.pdf ├── man ├── balassa_index.Rd ├── complexity_measures.Rd ├── complexity_outlook.Rd ├── country_aggregation.Rd ├── country_product_aggregation.Rd ├── dataframe_to_matrix.Rd ├── density.Rd ├── distance.Rd ├── economiccomplexity-package.Rd ├── economiccomplexity_output.Rd ├── figures │ └── logo.svg ├── productivity_levels.Rd ├── projections.Rd ├── proximity.Rd ├── rca.Rd ├── world_gdp_avg_1998_to_2000.Rd └── world_trade_avg_1998_to_2000.Rd ├── pkgdown └── favicon │ ├── apple-touch-icon.png │ ├── favicon-96x96.png │ ├── favicon.ico │ ├── favicon.svg │ ├── site.webmanifest │ ├── web-app-manifest-192x192.png │ └── web-app-manifest-512x512.png ├── src ├── .gitignore ├── Makevars ├── Makevars.in ├── Makevars.win ├── code.cpp └── cpp11.cpp ├── tests ├── testthat.R └── testthat │ ├── test-balassa_index.R │ ├── test-complexity_measures.R │ ├── test-complexity_outlook.R │ ├── test-productivity_levels.R │ ├── test-projections.R │ └── test-proximity.R └── vignettes ├── economiccomplexity.Rmd └── economiccomplexity.html /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | .git 4 | .gitignore 5 | dev 6 | LICENSE 7 | README.Rmd 8 | README.md 9 | ^codemeta\.json$ 10 | _pkgdown.yml 11 | .travis.yml 12 | appveyor.yml 13 | docs/ 14 | ^codecov\.yml$ 15 | ^CODE_OF_CONDUCT\.md$ 16 | data-raw/ 17 | LICENSE 18 | svg/ 19 | vignettes/basic-usage_cache/ 20 | ^\.github$ 21 | ^cran-comments\.md$ 22 | ^\.vscode$ 23 | ^_pkgdown\.yml$ 24 | ^LICENSE\.md$ 25 | ^src/Makevars$ 26 | ^CRAN-SUBMISSION$ 27 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | custom: ['https://www.buymeacoffee.com/pacha'] 4 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macOS-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'release'} 24 | 25 | env: 26 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 27 | R_KEEP_PKG_SOURCE: yes 28 | 29 | steps: 30 | - uses: actions/checkout@v2 31 | 32 | - uses: r-lib/actions/setup-pandoc@v2 33 | 34 | - uses: r-lib/actions/setup-r@v2 35 | with: 36 | r-version: ${{ matrix.config.r }} 37 | http-user-agent: ${{ matrix.config.http-user-agent }} 38 | use-public-rspm: true 39 | 40 | - uses: r-lib/actions/setup-r-dependencies@v2 41 | with: 42 | extra-packages: any::rcmdcheck 43 | needs: check 44 | 45 | - uses: r-lib/actions/check-r-package@v2 46 | with: 47 | upload-snapshots: true 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | .Rapp.history 6 | .build.timestamp 7 | .DS_Store 8 | *.tex 9 | *.tar.gz 10 | svg/ 11 | dev/sitc-data/ 12 | README.html 13 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "linux-gcc-x64", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "compilerPath": "/usr/bin/gcc", 9 | "cStandard": "${default}", 10 | "cppStandard": "${default}", 11 | "intelliSenseMode": "linux-gcc-x64", 12 | "compilerArgs": [ 13 | "" 14 | ] 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "C/C++ Runner: Debug Session", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "externalConsole": false, 11 | "cwd": "/home/pacha/github/economiccomplexity/src", 12 | "program": "/home/pacha/github/economiccomplexity/src/build/Debug/outDebug", 13 | "MIMode": "gdb", 14 | "miDebuggerPath": "gdb", 15 | "setupCommands": [ 16 | { 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | } 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp_Runner.cCompilerPath": "gcc", 3 | "C_Cpp_Runner.cppCompilerPath": "g++", 4 | "C_Cpp_Runner.debuggerPath": "gdb", 5 | "C_Cpp_Runner.cStandard": "", 6 | "C_Cpp_Runner.cppStandard": "", 7 | "C_Cpp_Runner.msvcBatchPath": "", 8 | "C_Cpp_Runner.useMsvc": false, 9 | "C_Cpp_Runner.warnings": [ 10 | "-Wall", 11 | "-Wextra", 12 | "-Wpedantic", 13 | "-Wshadow", 14 | "-Wformat=2", 15 | "-Wcast-align", 16 | "-Wconversion", 17 | "-Wsign-conversion", 18 | "-Wnull-dereference" 19 | ], 20 | "C_Cpp_Runner.msvcWarnings": [ 21 | "/W4", 22 | "/permissive-", 23 | "/w14242", 24 | "/w14287", 25 | "/w14296", 26 | "/w14311", 27 | "/w14826", 28 | "/w44062", 29 | "/w44242", 30 | "/w14905", 31 | "/w14906", 32 | "/w14263", 33 | "/w44265", 34 | "/w14928" 35 | ], 36 | "C_Cpp_Runner.enableWarnings": true, 37 | "C_Cpp_Runner.warningsAsError": false, 38 | "C_Cpp_Runner.compilerArgs": [], 39 | "C_Cpp_Runner.linkerArgs": [], 40 | "C_Cpp_Runner.includePaths": [], 41 | "C_Cpp_Runner.includeSearch": [ 42 | "*", 43 | "**/*" 44 | ], 45 | "C_Cpp_Runner.excludeSearch": [ 46 | "**/build", 47 | "**/build/**", 48 | "**/.*", 49 | "**/.*/**", 50 | "**/.vscode", 51 | "**/.vscode/**" 52 | ], 53 | "C_Cpp_Runner.useAddressSanitizer": false, 54 | "C_Cpp_Runner.useUndefinedSanitizer": false, 55 | "C_Cpp_Runner.useLeakSanitizer": false, 56 | "C_Cpp_Runner.showCompilationTime": false, 57 | "C_Cpp_Runner.useLinkTimeOptimization": false, 58 | "C_Cpp_Runner.msvcSecureNoWarnings": false 59 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (http://contributor-covenant.org), version 1.0.0, available at 25 | http://contributor-covenant.org/version/1/0/0/ 26 | -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 2.0.0 2 | Date: 2024-12-13 03:41:02 UTC 3 | SHA: ddf6f0a21f4b3afa80ad21669ca92906bbdeb1ef 4 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: economiccomplexity 2 | Type: Package 3 | Title: Computational Methods for Economic Complexity 4 | Version: 2.0.0 5 | Authors@R: c( 6 | person(given = "Mauricio", 7 | family = "Vargas Sepulveda", 8 | role = c("aut", "cre", "cph"), 9 | email = "m.sepulveda@mail.utoronto.ca", 10 | comment = c(ORCID = "0000-0003-1017-7574") 11 | ), 12 | person(given = "Carlo", 13 | family = "Bottai", 14 | role = "ctb", 15 | comment = "improved the eigenvalues calculation" 16 | ), 17 | person(given = "Diego", 18 | family = "Kozlowski", 19 | role = "ctb", 20 | comment = "provided initial RCA function used up to v0.2.4" 21 | ), 22 | person(given = "Nico", 23 | family = "Pintar", 24 | role = "rev", 25 | comment = "suggested improvements to special cases in eigenvalues 26 | calculation" 27 | ), 28 | person(family = "The World Bank", 29 | role = "dtc", 30 | comment = "World GDP per capita dataset" 31 | ), 32 | person(family = "Open Trade Statistics", 33 | role = "dtc", 34 | comment = "World Trade dataset" 35 | ) 36 | ) 37 | Description: A wrapper of different methods from Linear Algebra for the equations 38 | introduced in The Atlas of Economic Complexity and related literature. This 39 | package provides standard matrix and graph output that can be used seamlessly 40 | with other packages. See for a summary 41 | of these methods and its evolution in literature. 42 | License: Apache License (>= 2) 43 | Encoding: UTF-8 44 | LazyData: true 45 | Depends: R (>= 3.5) 46 | Imports: 47 | igraph, 48 | Rdpack 49 | Suggests: 50 | testthat (>= 2.1.0), 51 | knitr, 52 | ggplot2, 53 | ggraph, 54 | rmarkdown, 55 | covr 56 | URL: https://pacha.dev/economiccomplexity/ 57 | BugReports: https://github.com/pachadotdev/economiccomplexity/issues/ 58 | RoxygenNote: 7.3.2 59 | RdMacros: Rdpack 60 | VignetteBuilder: knitr 61 | LinkingTo: 62 | cpp11, 63 | cpp11armadillo 64 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(balassa_index) 4 | export(complexity_measures) 5 | export(complexity_outlook) 6 | export(density) 7 | export(distance) 8 | export(productivity_levels) 9 | export(projections) 10 | export(proximity) 11 | export(rca) 12 | importFrom(Rdpack,reprompt) 13 | importFrom(igraph,"E<-") 14 | importFrom(igraph,E) 15 | importFrom(igraph,degree) 16 | importFrom(igraph,delete.edges) 17 | importFrom(igraph,graph.difference) 18 | importFrom(igraph,graph.union) 19 | importFrom(igraph,graph_from_adjacency_matrix) 20 | importFrom(igraph,mst) 21 | importFrom(igraph,remove.edge.attribute) 22 | importFrom(stats,aggregate) 23 | importFrom(stats,cor) 24 | importFrom(stats,setNames) 25 | useDynLib(economiccomplexity, .registration = TRUE) 26 | -------------------------------------------------------------------------------- /R/balassa_index.R: -------------------------------------------------------------------------------- 1 | #' Balassa Index 2 | #' 3 | #' @description \code{balassa_index()} computes the Balassa Index for a 4 | #' bipartite relation between countries and products. 5 | #' 6 | #' @details The current implementation follows 7 | #' \insertCite{measuringcomplexity2015}{economiccomplexity} to obtain a metric 8 | #' for specialisation. In the context of international trade, if the Balassa 9 | #' Index for a country-product pair is more than 1, it means that country is 10 | #' specialized in that product. If the input for this function is a data.frame 11 | #' instead of a matrix, the function shall aggregate the data and convert the 12 | #' input to a matrix. 13 | #' 14 | #' @return A matrix with the Balassa Index. 15 | #' 16 | #' @param trade_data (Type: data.frame or matrix) a dataset such as 17 | #' \code{world_gdp_avg_1998_to_2000} containing countries, products and exported 18 | #' values. 19 | #' @param discrete (Type: logical) whether converting the Balassa Index to 20 | #' discrete (0/1) values. Anything below the specified cutoff is converted to 0 21 | #' and 1 otherwise. By default this is set to \code{TRUE}. 22 | #' @param cutoff (Type: numeric) the cutoff to use for discretization. 23 | #' By default this is set to \code{1}. 24 | #' @param country (Type: character) the column with the countries. 25 | #' By default this is set to \code{"country"}. Used only if the input is a 26 | #' data.frame. 27 | #' @param product (Type: character) the column with the products. 28 | #' By default this is set to \code{"product"}. Used only if the input is a 29 | #' data.frame. 30 | #' @param value (Type: character) the column with the metric for 31 | #' country-product pairs. 32 | #' By default this is set to \code{"value"}. Used only if the input is a 33 | #' data.frame. 34 | #' 35 | #' @examples 36 | #' bi <- balassa_index(world_trade_avg_1998_to_2000) 37 | #' 38 | #' # partial view of index 39 | #' n <- seq_len(5) 40 | #' bi[n, n] 41 | #' 42 | #' @references 43 | #' For more information see: 44 | #' 45 | #' \insertRef{measuringcomplexity2015}{economiccomplexity} 46 | #' 47 | #' and the references therein. 48 | #' 49 | #' @keywords functions 50 | #' 51 | #' @export 52 | balassa_index <- function(trade_data, discrete = TRUE, cutoff = 1, 53 | country = "country", product = "product", 54 | value = "value") { 55 | # sanity checks ---- 56 | if (!any(class(trade_data) %in% c("data.frame", "matrix"))) { 57 | stop("'trade_data' must be a data.frame or matrix") 58 | } 59 | 60 | if (!is.character(country) || !is.character(product) || 61 | !is.character(value)) { 62 | stop("'country', 'product' and 'value' must be of type character") 63 | } 64 | 65 | if (!is.logical(discrete)) { 66 | stop("'discrete' must be TRUE or FALSE") 67 | } 68 | 69 | if (!is.numeric(cutoff)) { 70 | stop("'cutoff' must be numeric") 71 | } 72 | 73 | # convert data.frame to matrix ---- 74 | if (any(class(trade_data) %in% "data.frame")) { 75 | if(nrow(trade_data) != nrow(unique(trade_data[, c(country, product)]))) { 76 | message("Aggregating duplicated country-product pairs...") 77 | trade_data <- country_product_aggregation(trade_data, country, product, 78 | value) 79 | } 80 | trade_data <- dataframe_to_matrix(trade_data, country, product, value) 81 | } 82 | 83 | balassa_index_(trade_data, discrete, cutoff) 84 | } 85 | 86 | #' Revealed Comparative Advantage 87 | #' @description \code{balassa_index()} replaces this function 88 | #' @param ... old parameters 89 | #' @export 90 | 91 | rca <- function(...) { 92 | .Deprecated("balassa_index") 93 | } 94 | -------------------------------------------------------------------------------- /R/complexity_measures.R: -------------------------------------------------------------------------------- 1 | #' Complexity Measures 2 | #' 3 | #' @description \code{complexity_measures()} computes the Economic Complexity 4 | #' Index and the Product Complexity Index. 5 | #' 6 | #' @details The current implementation follows 7 | #' \insertCite{measuringcomplexity2015}{economiccomplexity} to obtain different 8 | #' alternatives that account for diversification in bipartite relations. 9 | #' 10 | #' @return A list of two named numeric vectors. 11 | #' 12 | #' @param balassa_index (Type: matrix) the output from 13 | #' \code{balassa_index()}) or an equivalent arrangement. 14 | #' @param method (Type: character) one of these methods: fitness, 15 | #' reflections or eigenvalues. By default this is set to \code{"fitness"}. 16 | #' @param iterations (Type: numeric) the number of iterations to use. 17 | #' By default this is set to \code{20}. 18 | #' @param extremality (Type: numeric) the parameter to use in the fitness 19 | #' method. The other methods don't use this parameter. 20 | #' By default this is set to \code{1}. 21 | #' 22 | #' @importFrom stats cor 23 | #' 24 | #' @examples 25 | #' co <- complexity_measures(economiccomplexity_output$balassa_index) 26 | #' 27 | #' # partial view of indexes 28 | #' n <- seq_len(5) 29 | #' co$complexity_index_country[n] 30 | #' co$complexity_index_product[n] 31 | #' 32 | #' @references 33 | #' For more information on this index see: 34 | #' 35 | #' \insertRef{measuringcomplexity2015}{economiccomplexity} 36 | #' 37 | #' and the references therein. 38 | #' 39 | #' @keywords functions 40 | #' 41 | #' @export 42 | complexity_measures <- function(balassa_index, method = "fitness", 43 | iterations = 20, extremality = 1) { 44 | # sanity checks ---- 45 | if (!(any(class(balassa_index) %in% "matrix") == TRUE)) { 46 | stop("'balassa_index' must be a matrix") 47 | } 48 | 49 | if (!(any(method %in% c("fitness", "reflections", "eigenvalues")) == TRUE)) { 50 | stop("'method' must be 'fitness', 'reflections' or 'eigenvalues'") 51 | } 52 | 53 | if (!is.integer(iterations)) { 54 | iterations <- as.integer(iterations) 55 | 56 | if (iterations < 2L) { 57 | stop("'iterations' must be integer and >= 2") 58 | } 59 | } 60 | 61 | if (iterations %% 2 != 0) { 62 | iterations <- iterations + 1 63 | warning(paste("'iterations' was changed to 'iterations + 1' to work with", 64 | "an even number of iterations")) 65 | } 66 | 67 | # compute complexity measures ---- 68 | rows_balassa_index <- rowSums(balassa_index)[rowSums(balassa_index) > 0] 69 | cols_balassa_index <- colSums(balassa_index)[colSums(balassa_index) > 0] 70 | 71 | balassa_index <- balassa_index[ 72 | rownames(balassa_index) %in% names(rows_balassa_index), 73 | colnames(balassa_index) %in% names(cols_balassa_index) 74 | ] 75 | 76 | if (method == "fitness") { 77 | return(fitness_method_(balassa_index, iterations, extremality)) 78 | } 79 | 80 | if (method == "reflections") { 81 | return(reflections_method_(balassa_index, iterations)) 82 | } 83 | 84 | if (method == "eigenvalues") { 85 | # to check if a sign correction is needed 86 | reflections_output <- reflections_method_(balassa_index, iterations) 87 | eigenvalues_output <- eigenvalues_method_(balassa_index, iterations) 88 | 89 | # correct complexity_index_country sign when required 90 | if (isTRUE(cor(eigenvalues_output$complexity_index_country, 91 | reflections_output$complexity_index_country, 92 | use = "pairwise.complete.obs") < 0)) { 93 | message("applying sign correction to country index...") 94 | eigenvalues_output$complexity_index_country <- (-1) * 95 | eigenvalues_output$complexity_index_country 96 | } 97 | 98 | # correct complexity_index_product sign when required 99 | if (isTRUE(cor(eigenvalues_output$complexity_index_product, 100 | reflections_output$complexity_index_product, 101 | use = "pairwise.complete.obs") < 0)) { 102 | message("applying sign correction to product index...") 103 | eigenvalues_output$complexity_index_product <- (-1) * 104 | eigenvalues_output$complexity_index_product 105 | } 106 | 107 | return(eigenvalues_output) 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /R/complexity_outlook.R: -------------------------------------------------------------------------------- 1 | #' Complexity Outlook 2 | #' 3 | #' @description \code{complexity_outlook()} computes the Complexity Outlook 4 | #' Index and the Complexity Outlook Gain. 5 | #' 6 | #' @details The current implementation follows 7 | #' \insertCite{atlas2014}{economiccomplexity} to measure unexploited 8 | #' export oppportunities. 9 | #' 10 | #' @return A list of two named numeric vectors. 11 | #' 12 | #' @param balassa_index (Type: matrix) the output from 13 | #' \code{balassa_index()}) or an equivalent arrangement. 14 | #' @param proximity_product (Type: matrix) the output from 15 | #' \code{proximity()}) or an equivalent arrangement. 16 | #' @param complexity_index_product (Type: numeric) the output from 17 | #' \code{complexity_measures()}) or an equivalent arrangement. 18 | #' 19 | #' @examples 20 | #' co <- complexity_outlook( 21 | #' economiccomplexity_output$balassa_index, 22 | #' economiccomplexity_output$proximity$proximity_product, 23 | #' economiccomplexity_output$complexity_measures$complexity_index_product 24 | #' ) 25 | #' 26 | #' # partial view of complexity outlook 27 | #' n <- seq_len(5) 28 | #' co$complexity_outlook_index[n] 29 | #' co$complexity_outlook_gain[n, n] 30 | #' 31 | #' @references 32 | #' For more information on this index see: 33 | #' 34 | #' \insertRef{atlas2014}{economiccomplexity} 35 | #' 36 | #' and the references therein. 37 | #' 38 | #' @keywords functions 39 | #' 40 | #' @export 41 | 42 | complexity_outlook <- function(balassa_index, proximity_product, 43 | complexity_index_product) { 44 | # sanity checks ---- 45 | if (!(any(class(balassa_index) %in% "matrix") == TRUE)) { 46 | stop("'balassa_index' must be a matrix") 47 | } 48 | 49 | if (!(any(class(proximity_product) %in% "matrix") == TRUE)) { 50 | stop("'proximity_product' must be a matrix") 51 | } 52 | 53 | if (!(any(class(complexity_index_product) %in% "numeric") == TRUE)) { 54 | stop("'complexity_index_product' must be numeric") 55 | } 56 | 57 | # compute matrices ---- 58 | dist <- distance(balassa_index, proximity_product) 59 | 60 | coi <- colSums(t((1 - dist) * (1 - balassa_index)) * complexity_index_product) 61 | 62 | cog <- (1 - balassa_index) * tcrossprod( 63 | (1 - balassa_index), 64 | t(proximity_product * (complexity_index_product / 65 | rowSums(proximity_product))) 66 | ) 67 | 68 | return( 69 | list( 70 | complexity_outlook_index = coi, 71 | complexity_outlook_gain = cog 72 | ) 73 | ) 74 | } 75 | -------------------------------------------------------------------------------- /R/cpp11.R: -------------------------------------------------------------------------------- 1 | # Generated by cpp11: do not edit by hand 2 | 3 | balassa_index_ <- function(trade_matrix, discrete, cutoff) { 4 | .Call(`_economiccomplexity_balassa_index_`, trade_matrix, discrete, cutoff) 5 | } 6 | 7 | fitness_method_ <- function(balassa_index, iterations, extremality) { 8 | .Call(`_economiccomplexity_fitness_method_`, balassa_index, iterations, extremality) 9 | } 10 | 11 | reflections_method_ <- function(balassa_index, iterations) { 12 | .Call(`_economiccomplexity_reflections_method_`, balassa_index, iterations) 13 | } 14 | 15 | eigenvalues_method_ <- function(balassa_index, iterations) { 16 | .Call(`_economiccomplexity_eigenvalues_method_`, balassa_index, iterations) 17 | } 18 | 19 | distance_ <- function(balassa_index, proximity_product) { 20 | .Call(`_economiccomplexity_distance_`, balassa_index, proximity_product) 21 | } 22 | 23 | proximity_ <- function(balassa_index, compute) { 24 | .Call(`_economiccomplexity_proximity_`, balassa_index, compute) 25 | } 26 | -------------------------------------------------------------------------------- /R/density.R: -------------------------------------------------------------------------------- 1 | #' Density 2 | #' 3 | #' @description \code{density()} computes the density matrix that 4 | #' accounts for the weighted proportions of the products connected to 5 | #' each good that the countries are exporting. 6 | #' 7 | #' @details The current implementation follows 8 | #' \insertCite{atlas2014}{economiccomplexity} to measure the oppotunities 9 | #' implied by a country's position. 10 | #' 11 | #' @return A matrix. 12 | #' 13 | #' @param balassa_index (Type: matrix) the output from 14 | #' \code{balassa_index()}) or an equivalent arrangement. 15 | #' @param proximity_product (Type: matrix) the output from 16 | #' \code{proximity()}) or an equivalent arrangement. 17 | #' 18 | #' @examples 19 | #' d <- density( 20 | #' economiccomplexity_output$balassa_index, 21 | #' economiccomplexity_output$proximity$proximity_product 22 | #' ) 23 | #' 24 | #' # partial view of the density matrix 25 | #' n <- seq_len(5) 26 | #' d[n, n] 27 | #' 28 | #' @references 29 | #' For more information on this index see: 30 | #' 31 | #' \insertRef{atlas2014}{economiccomplexity} 32 | #' 33 | #' and the references therein. 34 | #' 35 | #' @keywords functions 36 | #' 37 | #' @export 38 | 39 | density <- function(balassa_index, proximity_product) { 40 | return( 41 | 1 - economiccomplexity::distance(balassa_index, proximity_product) 42 | ) 43 | } 44 | -------------------------------------------------------------------------------- /R/distance.R: -------------------------------------------------------------------------------- 1 | #' Distance 2 | #' 3 | #' @description \code{distance()} computes the distance matrix that 4 | #' accounts for the weighted proportions of the products connected to 5 | #' each good that the countries are not exporting. 6 | #' 7 | #' @details The current implementation follows 8 | #' \insertCite{atlas2014}{economiccomplexity} to measure the oppotunities 9 | #' implied by a country's position. 10 | #' 11 | #' @return A matrix. 12 | #' 13 | #' @param balassa_index (Type: matrix) the output from 14 | #' \code{balassa_index()}) or an equivalent arrangement. 15 | #' @param proximity_product (Type: matrix) the output from 16 | #' \code{proximity()}) or an equivalent arrangement. 17 | #' 18 | #' @examples 19 | #' d <- distance( 20 | #' economiccomplexity_output$balassa_index, 21 | #' economiccomplexity_output$proximity$proximity_product 22 | #' ) 23 | #' 24 | #' # partial view of the distance matrix 25 | #' n <- seq_len(5) 26 | #' d[n, n] 27 | #' 28 | #' @references 29 | #' For more information on this index see: 30 | #' 31 | #' \insertRef{atlas2014}{economiccomplexity} 32 | #' 33 | #' and the references therein. 34 | #' 35 | #' @keywords functions 36 | #' 37 | #' @export 38 | 39 | distance <- function(balassa_index, proximity_product) { 40 | # sanity checks ---- 41 | if (!(any(class(balassa_index) %in% "matrix") == TRUE)) { 42 | stop("'balassa_index' must be a matrix") 43 | } 44 | 45 | distance_(balassa_index, proximity_product) 46 | } 47 | -------------------------------------------------------------------------------- /R/economiccomplexity-package.R: -------------------------------------------------------------------------------- 1 | #' @importFrom stats cor aggregate setNames 2 | #' @importFrom igraph graph_from_adjacency_matrix mst 3 | #' degree delete.edges graph.difference graph.union remove.edge.attribute E E<- 4 | #' @importFrom Rdpack reprompt 5 | #' @useDynLib economiccomplexity, .registration = TRUE 6 | #' @keywords internal 7 | "_PACKAGE" 8 | 9 | #' World Trade Averages for the Period 1998-2000 10 | #' 11 | #' A data frame that summarizes all the products that different countries exported to the rest of the world. This data uses the SITC revision 2 classification with four digits product codes. The unit is year 2000 USD. 12 | #' 13 | #' @docType data 14 | #' @usage data(world_trade_avg_1998_to_2000) 15 | #' @format A data frame with 124,336 rows and 3 columns. 16 | #' @examples 17 | #' data(world_trade_avg_1998_to_2000) 18 | #' head(world_trade_avg_1998_to_2000) 19 | #' @keywords datasets 20 | "world_trade_avg_1998_to_2000" 21 | 22 | #' World Trade Per-Capita GDP for the Period 1998-2000 23 | #' 24 | #' A data frame that summarizes the per-capita GDP of different countries. The unit is year 2000 USD. 25 | #' 26 | #' @docType data 27 | #' @usage data(world_gdp_avg_1998_to_2000) 28 | #' @format A data frame with 240 rows and 2 columns. 29 | #' @examples 30 | #' data(world_gdp_avg_1998_to_2000) 31 | #' head(world_gdp_avg_1998_to_2000) 32 | #' @keywords datasets 33 | "world_gdp_avg_1998_to_2000" 34 | 35 | #' Example Outputs of the Functions within the Package 36 | #' 37 | #' List of different computations obtained by using the functions within the package. 38 | #' 39 | #' @docType data 40 | #' @usage data(economiccomplexity_output) 41 | #' @format Lists of vectors, matrices, and graphs. 42 | #' @examples 43 | #' data(economiccomplexity_output) 44 | #' economiccomplexity_output$balassa_index 45 | #' economiccomplexity_output$complexity_measures$complexity_index_country 46 | #' @keywords datasets 47 | "economiccomplexity_output" 48 | -------------------------------------------------------------------------------- /R/helpers.R: -------------------------------------------------------------------------------- 1 | #' country-product aggregation 2 | #' @keywords internal 3 | country_product_aggregation <- function(dataframe, country = "country", 4 | product = "product", value = "value") { 5 | dataframe <- subset(dataframe, select = c(country, product, value)) 6 | names(dataframe) <- c("country", "product", "value") 7 | 8 | dataframe <- aggregate(dataframe$value, by = list(country = dataframe$country, 9 | product = dataframe$product), FUN = sum) 10 | names(dataframe) <- c("country", "product", "value") 11 | 12 | dataframe <- dataframe[dataframe$value > 0, ] 13 | 14 | dataframe$country <- as.factor(dataframe$country) 15 | dataframe$product <- as.factor(dataframe$product) 16 | 17 | return(dataframe) 18 | } 19 | 20 | #' country aggregation 21 | #' @keywords internal 22 | country_aggregation <- function(dataframe, country = "country", 23 | value = "value") { 24 | dataframe <- subset(dataframe, select = c(country, value)) 25 | names(dataframe) <- c("country", "value") 26 | 27 | dataframe <- aggregate(dataframe$value, 28 | by = list(country = dataframe$country), FUN = sum) 29 | names(dataframe) <- c("country", "value") 30 | 31 | dataframe <- dataframe[dataframe$value > 0, ] 32 | 33 | dataframe$country <- as.factor(dataframe$country) 34 | 35 | return(dataframe) 36 | } 37 | 38 | #' Dataframe to matrix 39 | #' @keywords internal 40 | dataframe_to_matrix <- function(dataframe, country = "country", 41 | product = "product", value = "value") { 42 | countries <- as.factor(dataframe[[country]]) 43 | products <- as.factor(dataframe[[product]]) 44 | values <- dataframe[[value]] 45 | 46 | matrix_data <- matrix(0, 47 | nrow = length(levels(countries)), ncol = length(levels(products)), 48 | dimnames = list(levels(countries), levels(products)) 49 | ) 50 | 51 | indices <- cbind(as.numeric(countries), as.numeric(products)) 52 | matrix_data[indices] <- values 53 | 54 | matrix_data 55 | } 56 | -------------------------------------------------------------------------------- /R/productivity_levels.R: -------------------------------------------------------------------------------- 1 | #' Productivity Levels 2 | #' 3 | #' @description \code{productivity_levels()} computes EXPY and PRODY measures. 4 | #' 5 | #' @details The current implementation follows 6 | #' \insertCite{exportmatters2005}{economiccomplexity} to obtain the 7 | #' productivity and income levels associated to exports. 8 | #' 9 | #' @return A list of two named numeric vectors. 10 | #' 11 | #' @param data_exp (Type: data.frame, matrix or matrix) a dataset containing 12 | #' countries, products and exported values. 13 | #' @param data_gdp (Type: data.frame, matrix or matrix) a dataset 14 | #' containing countries and per-capita GDP values. 15 | #' @param country (Type: character) the column with the countries. 16 | #' By default this is set to \code{"country"}. Used only if the input is a 17 | #' data.frame. 18 | #' @param product (Type: character) the column with the products. 19 | #' By default this is set to \code{"product"}. Used only if the input is a 20 | #' data.frame. 21 | #' @param value (Type: character) the column with the metric for 22 | #' country-product pairs. 23 | #' By default this is set to \code{"value"}. Used only if the input is a 24 | #' data.frame. 25 | #' 26 | #' @examples 27 | #' pl <- productivity_levels( 28 | #' world_trade_avg_1998_to_2000, 29 | #' world_gdp_avg_1998_to_2000 30 | #' ) 31 | #' 32 | #' # partial view of productivity levels 33 | #' n <- seq_len(5) 34 | #' pl$productivity_level_country[n] 35 | #' pl$productivity_level_product[n] 36 | #' 37 | #' @references 38 | #' For more information on prody and its applications see: 39 | #' 40 | #' \insertRef{exportmatters2005}{economiccomplexity} 41 | #' 42 | #' @keywords functions 43 | #' 44 | #' @export 45 | 46 | productivity_levels <- function(data_exp, data_gdp, 47 | country = "country", product = "product", 48 | value = "value") { 49 | # sanity checks ---- 50 | if (all(class(data_exp) %in% c("data.frame", "matrix") == FALSE)) { 51 | stop("'data_exp' must be a data.frame or matrix") 52 | } 53 | 54 | if (all(class(data_gdp) %in% c("data.frame", "numeric") == FALSE)) { 55 | stop("'data_gdp' must be a data.frame or numeric") 56 | } 57 | 58 | # tidy input data data_exp ---- 59 | if (any(class(data_exp) %in% "data.frame")) { 60 | data_exp <- country_product_aggregation(data_exp, country, product, value) 61 | data_exp <- dataframe_to_matrix(data_exp, country, product, value) 62 | } 63 | 64 | if (!(any(class(data_exp) %in% "matrix") == TRUE)) { 65 | data_exp <- matrix(data_exp) 66 | } 67 | 68 | # tidy input data data_gdp ---- 69 | if (any(class(data_gdp) %in% "data.frame")) { 70 | data_gdp <- country_aggregation(data_gdp, country, value) 71 | data_gdp <- setNames(as.numeric(data_gdp$value), data_gdp$country) 72 | } 73 | 74 | intersect_country_1 <- sort(rownames(data_exp)[rownames(data_exp) %in% 75 | names(data_gdp)]) 76 | intersect_country_2 <- sort(names(data_gdp)[names(data_gdp) %in% 77 | rownames(data_exp)]) 78 | 79 | if (any(intersect_country_1 != intersect_country_2) == TRUE | 80 | nrow(data_exp) != length(intersect_country_2) | 81 | length(data_gdp) != length(intersect_country_1)) { 82 | warning(paste("'data_exp' and 'data_gdp' don\'t have the same countries,", 83 | "some elements will be dropped")) 84 | } 85 | 86 | data_exp <- data_exp[rownames(data_exp) %in% names(data_gdp), ] 87 | data_gdp <- data_gdp[names(data_gdp) %in% rownames(data_exp)] 88 | 89 | p1 <- data_exp / rowSums(data_exp) 90 | p2 <- colSums(p1) 91 | 92 | prody <- crossprod(p1, data_gdp) / p2 93 | expy <- p1 %*% prody 94 | 95 | prody <- setNames(as.numeric(prody), rownames(prody)) 96 | expy <- setNames(as.numeric(expy), rownames(expy)) 97 | 98 | return( 99 | list( 100 | productivity_level_country = expy, 101 | productivity_level_product = prody 102 | ) 103 | ) 104 | } 105 | -------------------------------------------------------------------------------- /R/projections.R: -------------------------------------------------------------------------------- 1 | #' Projections of a Country-Product Network 2 | #' 3 | #' @description \code{projections()} computes two graphs that are particularly 4 | #' useful to visualize product-product and country-country similarity. 5 | #' 6 | #' @details The current implementation follows 7 | #' \insertCite{atlas2014}{economiccomplexity} to create simplified graphs 8 | #' that correspond to a simplification of the proximity matrices. The result is 9 | #' obtained by iterating and reducing links until the desired average number of 10 | #' links per node is obtained, or a spaning tree after the strongest links is 11 | #' returned when is not possible to return the desired network. 12 | #' 13 | #' @return A list of two graphs. 14 | #' 15 | #' @param proximity_country (Type: matrix) the output from 16 | #' \code{proximity()}) or an equivalent arrangement. 17 | #' @param proximity_product (Type: matrix) the output from 18 | #' \code{proximity()}) or an equivalent arrangement. 19 | #' @param avg_links average number of connections for the projections. 20 | #' By default this is set to \code{5}. 21 | #' @param tolerance tolerance for proximity variation on each iteration until 22 | #' obtaining the desired average number of connections. 23 | #' By default this is set to \code{0.05}. 24 | #' @param compute (Type: character) the proximity to compute. By default this is 25 | #' \code{"both"} (both projections) but it can also be \code{"country"} 26 | #' or \code{"product"}. 27 | #' 28 | #' @examples 29 | #' net <- projections( 30 | #' economiccomplexity_output$proximity$proximity_country, 31 | #' economiccomplexity_output$proximity$proximity_product, 32 | #' avg_links = 10, 33 | #' tolerance = 0.1 34 | #' ) 35 | #' 36 | #' # partial view of projections 37 | #' n <- seq_len(5) 38 | #' igraph::E(net$network_country)[n] 39 | #' igraph::E(net$network_product)[n] 40 | #' 41 | #' @references 42 | #' For more information see: 43 | #' 44 | #' \insertRef{atlas2014}{economiccomplexity} 45 | #' 46 | #' and the references therein. 47 | #' 48 | #' @keywords functions 49 | #' 50 | #' @export 51 | 52 | projections <- function(proximity_country, proximity_product, 53 | avg_links = 5, tolerance = 0.05, compute = "both") { 54 | # sanity checks ---- 55 | if (!(any(class(proximity_country) %in% "matrix") == TRUE) | 56 | !(any(class(proximity_product) %in% "matrix") == TRUE)) { 57 | stop("'proximity_country' and 'proximity_product' must be matrix") 58 | } 59 | 60 | if (!is.numeric(avg_links)) { 61 | stop("'avg_links' must be numeric") 62 | } 63 | 64 | if (!any(compute %in% c("both", "country", "product"))) { 65 | stop("'compute' must be 'both', 'country' or 'product'") 66 | } 67 | 68 | trim_network <- function(proximity_mat, proximity_avg) { 69 | # this -1 is because the book by Hausmann mentions "maximum spanning tree" 70 | proximity_mat <- (-1) * proximity_mat 71 | 72 | g <- graph_from_adjacency_matrix(proximity_mat, weighted = TRUE, 73 | mode = "undirected", diag = FALSE) 74 | 75 | g_mst <- mst(g, algorithm = "prim") 76 | 77 | threshold <- 0 78 | avg_links_n <- FALSE 79 | 80 | while (avg_links_n == FALSE) { 81 | if (threshold < 1) { 82 | message(sprintf("%s threshold...", threshold)) 83 | 84 | g_not_in_mst <- delete.edges(g, which(abs(E(g)$weight) <= threshold)) 85 | g_not_in_mst <- graph.difference(g_not_in_mst, g_mst) 86 | 87 | g <- graph.union(g_mst, g_not_in_mst) 88 | E(g)$weight <- pmin(E(g)$weight_1, E(g)$weight_2, na.rm = TRUE) 89 | g <- remove.edge.attribute(g, "weight_1") 90 | g <- remove.edge.attribute(g, "weight_2") 91 | 92 | avg_links_n <- ifelse(mean(degree(g)) <= avg_links, TRUE, FALSE) 93 | threshold <- threshold + tolerance 94 | 95 | if (avg_links_n == TRUE) { 96 | message(sprintf("%s threshold achieves the avg number of connections", 97 | threshold)) 98 | E(g)$weight <- (-1) * E(g)$weight 99 | return(g) 100 | } 101 | } else { 102 | warning(paste("no threshold achieves the avg number of connections", 103 | "returning maximum spanning tree")) 104 | avg_links_n <- TRUE 105 | E(g_mst)$weight <- (-1) * E(g_mst)$weight 106 | return(g_mst) 107 | } 108 | } 109 | } 110 | 111 | if (any(compute == "country" || compute == "both") == TRUE) { 112 | message("computing country projection...") 113 | message(rep("-", 50)) 114 | xg <- trim_network(proximity_country, avg_links) 115 | } else { 116 | xg <- NULL 117 | } 118 | 119 | if (any(compute == "product" || compute == "both") == TRUE) { 120 | message("computing product projection...") 121 | message(rep("-", 50)) 122 | yg <- trim_network(proximity_product, avg_links) 123 | } else { 124 | yg <- NULL 125 | } 126 | 127 | return( 128 | list( 129 | network_country = xg, 130 | network_product = yg 131 | ) 132 | ) 133 | } 134 | -------------------------------------------------------------------------------- /R/proximity.R: -------------------------------------------------------------------------------- 1 | #' Proximity 2 | #' 3 | #' @description \code{proximity()} computes two matrices that account for the 4 | #' similarity between pairs of countries and pairs of products. 5 | #' 6 | #' @details The current implementation follows 7 | #' \insertCite{atlas2014}{economiccomplexity} to obtain the likelihood that two 8 | #' products "p1" and "p2" are exported by the same country and, conversely, 9 | #' that two countries "c1" and "c2" export the same product. 10 | #' 11 | #' @return A list of two matrices. 12 | #' 13 | #' @param balassa_index (Type: matrix) the output from 14 | #' \code{balassa_index()}) or an equivalent arrangement. 15 | #' @param compute (Type: character) the proximity to compute. By default this is 16 | #' \code{"both"} (both proximity matrices) but it can also be \code{"country"} 17 | #' or \code{"product"}. 18 | #' 19 | #' @examples 20 | #' pro <- proximity(economiccomplexity_output$balassa_index) 21 | #' 22 | #' # partial view of proximity matrices 23 | #' n <- seq_len(5) 24 | #' pro$proximity_country[n, n] 25 | #' pro$proximity_product[n, n] 26 | #' 27 | #' @references 28 | #' For more information see: 29 | #' 30 | #' \insertRef{atlas2014}{economiccomplexity} 31 | #' 32 | #' and the references therein. 33 | #' 34 | #' @keywords functions 35 | #' 36 | #' @export 37 | 38 | proximity <- function(balassa_index, compute = "both") { 39 | # sanity checks ---- 40 | if (!(any(class(balassa_index) %in% "matrix") == TRUE)) { 41 | stop("'balassa_index' must be a matrix") 42 | } 43 | 44 | if (!any(compute %in% c("both", "country", "product"))) { 45 | stop("'compute' must be 'both', 'country' or 'product'") 46 | } 47 | 48 | # compute proximity matrices ---- 49 | balassa_index <- balassa_index[rowSums(balassa_index) != 0, 50 | colSums(balassa_index) != 0] 51 | 52 | proximity_(balassa_index, compute) 53 | } 54 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, echo = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/" 12 | ) 13 | ``` 14 | 15 | # economiccomplexity sticker 16 | 17 | 18 | [![CRAN status](https://www.r-pkg.org/badges/version/economiccomplexity)](https://cran.r-project.org/package=economiccomplexity) 19 | [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) 20 | [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) 21 | [![DOI](https://joss.theoj.org/papers/10.21105/joss.01866/status.svg)](https://doi.org/10.21105/joss.01866) 22 | [![R-CMD-check](https://github.com/pachadotdev/economiccomplexity/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/pachadotdev/economiccomplexity/actions/workflows/R-CMD-check.yaml) 23 | [![Codecov test coverage](https://codecov.io/gh/pachadotdev/economiccomplexity/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pachadotdev/economiccomplexity?branch=master) 24 | 25 | 26 | A wrapper of different methods from Linear Algebra for the equations introduced in The Atlas of Economic Complexity and related literature. This package provides standard matrix and graph output that can be used seamlessly with other packages. See for a summary of these methods and its evolution in literature. 27 | 28 | The references for this work are Mariani, et al. (2015) , Hausmann, et al. (2014) , and Hausmann, et al. (2005) . 29 | 30 | ## Installation 31 | 32 | ```{r, eval = FALSE} 33 | # Install stable version from CRAN 34 | install.packages("economiccomplexity") 35 | 36 | # Install development version from GitHub 37 | devtools::install_github("pachadotdev/economiccomplexity") 38 | ``` 39 | 40 | ## Community Guidelines 41 | 42 | If you want to contribute to the software, report issues or problems with the software, please fork the repo and send me a Pull Request or open an issue. I'm happy to receive ideas and I would do my best to coordinate efforts and improve this package without reinventing the wheel. 43 | 44 | If you seek support or have questions you can start a thread on the issues section, or you can email me but I prefer open issues as probably more users have the same questions as you. 45 | 46 | ## Code of Conduct 47 | 48 | Please note that this project is released with a [Contributor Code of Conduct](https://pacha.dev/economiccomplexity/CODE_OF_CONDUCT.html). 49 | By participating in this project you agree to abide by its terms. 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # economiccomplexity sticker 5 | 6 | 7 | 8 | [![CRAN 9 | status](https://www.r-pkg.org/badges/version/economiccomplexity)](https://cran.r-project.org/package=economiccomplexity) 10 | [![Project Status: Active – The project has reached a stable, usable 11 | state and is being actively 12 | developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) 13 | [![Lifecycle: 14 | stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) 15 | [![DOI](https://joss.theoj.org/papers/10.21105/joss.01866/status.svg)](https://doi.org/10.21105/joss.01866) 16 | [![R-CMD-check](https://github.com/pachadotdev/economiccomplexity/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/pachadotdev/economiccomplexity/actions/workflows/R-CMD-check.yaml) 17 | [![Codecov test 18 | coverage](https://codecov.io/gh/pachadotdev/economiccomplexity/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pachadotdev/economiccomplexity?branch=master) 19 | 20 | 21 | A wrapper of different methods from Linear Algebra for the equations 22 | introduced in The Atlas of Economic Complexity and related literature. 23 | This package provides standard matrix and graph output that can be used 24 | seamlessly with other packages. See for a 25 | summary of these methods and its evolution in literature. 26 | 27 | The references for this work are Mariani, et al. (2015) 28 | , Hausmann, et al. (2014) 29 | , and Hausmann, et al. (2005) 30 | . 31 | 32 | ## Installation 33 | 34 | ``` r 35 | # Install stable version from CRAN 36 | install.packages("economiccomplexity") 37 | 38 | # Install development version from GitHub 39 | devtools::install_github("pachadotdev/economiccomplexity") 40 | ``` 41 | 42 | ## Community Guidelines 43 | 44 | If you want to contribute to the software, report issues or problems 45 | with the software, please fork the repo and send me a Pull Request or 46 | open an issue. I’m happy to receive ideas and I would do my best to 47 | coordinate efforts and improve this package without reinventing the 48 | wheel. 49 | 50 | If you seek support or have questions you can start a thread on the 51 | issues section, or you can email me but I prefer open issues as probably 52 | more users have the same questions as you. 53 | 54 | ## Code of Conduct 55 | 56 | Please note that this project is released with a [Contributor Code of 57 | Conduct](https://pacha.dev/economiccomplexity/CODE_OF_CONDUCT.html). By 58 | participating in this project you agree to abide by its terms. 59 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | template: 2 | bootstrap: 5 3 | -------------------------------------------------------------------------------- /cleanup: -------------------------------------------------------------------------------- 1 | rm -f src/Makevars configure.log 2 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /codemeta.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": "https://doi.org/10.5063/schema/codemeta-2.0", 3 | "@type": "SoftwareSourceCode", 4 | "identifier": "economiccomplexity", 5 | "description": "A wrapper of different methods from Linear Algebra for the equations introduced in The Atlas of Economic Complexity and related literature. This package provides standard matrix and graph output that can be used seamlessly with other packages. See for a summary of these methods and its evolution in literature.", 6 | "name": "economiccomplexity: Computational Methods for Economic Complexity", 7 | "codeRepository": "https://github.com/pachadotdev/economiccomplexity", 8 | "issueTracker": "https://github.com/pachadotdev/economiccomplexity/issues/", 9 | "license": "https://spdx.org/licenses/GPL-3.0", 10 | "version": "2.0.0", 11 | "programmingLanguage": { 12 | "@type": "ComputerLanguage", 13 | "name": "R", 14 | "url": "https://r-project.org" 15 | }, 16 | "runtimePlatform": "R version 4.4.1 (2024-06-14)", 17 | "provider": { 18 | "@id": "https://cran.r-project.org", 19 | "@type": "Organization", 20 | "name": "Comprehensive R Archive Network (CRAN)", 21 | "url": "https://cran.r-project.org" 22 | }, 23 | "author": [ 24 | { 25 | "@type": "Person", 26 | "givenName": "Mauricio", 27 | "familyName": "Vargas Sepulveda", 28 | "email": "m.sepulveda@mail.utoronto.ca", 29 | "@id": "https://orcid.org/0000-0003-1017-7574" 30 | } 31 | ], 32 | "contributor": [ 33 | { 34 | "@type": "Person", 35 | "givenName": "Carlo", 36 | "familyName": "Bottai" 37 | }, 38 | { 39 | "@type": "Person", 40 | "givenName": "Diego", 41 | "familyName": "Kozlowski" 42 | }, 43 | { 44 | "@type": "Organization", 45 | "name": "The World Bank" 46 | }, 47 | { 48 | "@type": "Organization", 49 | "name": "Open Trade Statistics" 50 | } 51 | ], 52 | "copyrightHolder": [ 53 | { 54 | "@type": "Person", 55 | "givenName": "Mauricio", 56 | "familyName": "Vargas Sepulveda", 57 | "email": "m.sepulveda@mail.utoronto.ca", 58 | "@id": "https://orcid.org/0000-0003-1017-7574" 59 | } 60 | ], 61 | "maintainer": [ 62 | { 63 | "@type": "Person", 64 | "givenName": "Mauricio", 65 | "familyName": "Vargas Sepulveda", 66 | "email": "m.sepulveda@mail.utoronto.ca", 67 | "@id": "https://orcid.org/0000-0003-1017-7574" 68 | } 69 | ], 70 | "softwareSuggestions": [ 71 | { 72 | "@type": "SoftwareApplication", 73 | "identifier": "testthat", 74 | "name": "testthat", 75 | "version": ">= 2.1.0", 76 | "provider": { 77 | "@id": "https://cran.r-project.org", 78 | "@type": "Organization", 79 | "name": "Comprehensive R Archive Network (CRAN)", 80 | "url": "https://cran.r-project.org" 81 | }, 82 | "sameAs": "https://CRAN.R-project.org/package=testthat" 83 | }, 84 | { 85 | "@type": "SoftwareApplication", 86 | "identifier": "knitr", 87 | "name": "knitr", 88 | "provider": { 89 | "@id": "https://cran.r-project.org", 90 | "@type": "Organization", 91 | "name": "Comprehensive R Archive Network (CRAN)", 92 | "url": "https://cran.r-project.org" 93 | }, 94 | "sameAs": "https://CRAN.R-project.org/package=knitr" 95 | }, 96 | { 97 | "@type": "SoftwareApplication", 98 | "identifier": "ggplot2", 99 | "name": "ggplot2", 100 | "provider": { 101 | "@id": "https://cran.r-project.org", 102 | "@type": "Organization", 103 | "name": "Comprehensive R Archive Network (CRAN)", 104 | "url": "https://cran.r-project.org" 105 | }, 106 | "sameAs": "https://CRAN.R-project.org/package=ggplot2" 107 | }, 108 | { 109 | "@type": "SoftwareApplication", 110 | "identifier": "ggraph", 111 | "name": "ggraph", 112 | "provider": { 113 | "@id": "https://cran.r-project.org", 114 | "@type": "Organization", 115 | "name": "Comprehensive R Archive Network (CRAN)", 116 | "url": "https://cran.r-project.org" 117 | }, 118 | "sameAs": "https://CRAN.R-project.org/package=ggraph" 119 | }, 120 | { 121 | "@type": "SoftwareApplication", 122 | "identifier": "rmarkdown", 123 | "name": "rmarkdown", 124 | "provider": { 125 | "@id": "https://cran.r-project.org", 126 | "@type": "Organization", 127 | "name": "Comprehensive R Archive Network (CRAN)", 128 | "url": "https://cran.r-project.org" 129 | }, 130 | "sameAs": "https://CRAN.R-project.org/package=rmarkdown" 131 | }, 132 | { 133 | "@type": "SoftwareApplication", 134 | "identifier": "covr", 135 | "name": "covr", 136 | "provider": { 137 | "@id": "https://cran.r-project.org", 138 | "@type": "Organization", 139 | "name": "Comprehensive R Archive Network (CRAN)", 140 | "url": "https://cran.r-project.org" 141 | }, 142 | "sameAs": "https://CRAN.R-project.org/package=covr" 143 | } 144 | ], 145 | "softwareRequirements": { 146 | "1": { 147 | "@type": "SoftwareApplication", 148 | "identifier": "R", 149 | "name": "R", 150 | "version": ">= 3.5" 151 | }, 152 | "2": { 153 | "@type": "SoftwareApplication", 154 | "identifier": "igraph", 155 | "name": "igraph", 156 | "provider": { 157 | "@id": "https://cran.r-project.org", 158 | "@type": "Organization", 159 | "name": "Comprehensive R Archive Network (CRAN)", 160 | "url": "https://cran.r-project.org" 161 | }, 162 | "sameAs": "https://CRAN.R-project.org/package=igraph" 163 | }, 164 | "3": { 165 | "@type": "SoftwareApplication", 166 | "identifier": "Rdpack", 167 | "name": "Rdpack", 168 | "provider": { 169 | "@id": "https://cran.r-project.org", 170 | "@type": "Organization", 171 | "name": "Comprehensive R Archive Network (CRAN)", 172 | "url": "https://cran.r-project.org" 173 | }, 174 | "sameAs": "https://CRAN.R-project.org/package=Rdpack" 175 | }, 176 | "SystemRequirements": null 177 | }, 178 | "fileSize": "9405.69KB", 179 | "relatedLink": ["https://pacha.dev/economiccomplexity/", "https://CRAN.R-project.org/package=economiccomplexity"], 180 | "readme": "https://github.com/pachadotdev/economiccomplexity/blob/main/README.md", 181 | "contIntegration": ["https://github.com/pachadotdev/economiccomplexity/actions/workflows/R-CMD-check.yaml", "https://app.codecov.io/gh/pachadotdev/economiccomplexity?branch=master"], 182 | "developmentStatus": ["https://www.repostatus.org/#active", "https://www.tidyverse.org/lifecycle/#stable"], 183 | "keywords": ["r", "matrix", "eigenvalues", "eigenvectors", "recursive-algorithm", "networks", "graphs", "international-trade", "economic-complexity"] 184 | } 185 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Set the number of cores 4 | if [ -z "$PKG_NCORES" ]; then 5 | PKG_NCORES=$(getconf _NPROCESSORS_ONLN) 6 | if [ -z "$PKG_NCORES" ] || [ "$PKG_NCORES" -lt 1 ]; then 7 | PKG_NCORES=1 8 | elif [ "$PKG_NCORES" -gt 1 ]; then 9 | PKG_NCORES=$((PKG_NCORES / 2)) 10 | fi 11 | fi 12 | 13 | # Write Makevars 14 | sed -e "s|@ncores@|$PKG_NCORES|" \ 15 | src/Makevars.in > src/Makevars 16 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## R CMD check results 2 | 3 | 0 errors | 0 warnings | 1 note 4 | 5 | * This is a new release. 6 | -------------------------------------------------------------------------------- /data/economiccomplexity_output.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/data/economiccomplexity_output.rda -------------------------------------------------------------------------------- /data/world_gdp_avg_1998_to_2000.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/data/world_gdp_avg_1998_to_2000.rda -------------------------------------------------------------------------------- /data/world_trade_avg_1998_to_2000.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/data/world_trade_avg_1998_to_2000.rda -------------------------------------------------------------------------------- /dev/economiccomplexity_output.R: -------------------------------------------------------------------------------- 1 | ba_ind <- balassa_index(world_trade_avg_1998_to_2000) 2 | 3 | x <- test_eig(ba_ind, 10L) 4 | y <- test_eig_(ba_ind, 10L) 5 | 6 | dim(x) 7 | dim(y) 8 | 9 | head(x[1, ]) 10 | head(y[1, ]) 11 | 12 | com_fit <- complexity_measures(ba_ind) 13 | 14 | prox <- proximity(ba_ind, "both") 15 | 16 | # proj <- projections( 17 | # proximity_country = prox$proximity_country, 18 | # proximity_product = prox$proximity_product, 19 | # tolerance = 0.01, 20 | # avg_links = 4 21 | # ) 22 | 23 | economiccomplexity_output <- list( 24 | balassa_index = ba_ind, 25 | complexity_measures = com_fit, 26 | proximity = prox 27 | ) 28 | 29 | save(economiccomplexity_output, file = "data/economiccomplexity_output.rda", compress = "xz") 30 | -------------------------------------------------------------------------------- /dev/product_space_replication.R: -------------------------------------------------------------------------------- 1 | library(economiccomplexity) 2 | library(dplyr) 3 | library(igraph) 4 | library(ggraph) 5 | 6 | trade <- readRDS("~/github/economiccomplexity/dev/world_trade_avg_1998_to_2000.rds") 7 | 8 | bi <- balassa_index( 9 | data = trade, 10 | country = "reporter_iso", 11 | product = "product_code", 12 | value = "trade_value_usd" 13 | ) 14 | 15 | com_fit <- complexity_measures(balassa_index = bi) 16 | 17 | pro <- proximity( 18 | balassa_index = bi 19 | ) 20 | 21 | net <- projections( 22 | proximity_country = pro$proximity_country, 23 | proximity_product = pro$proximity_product, 24 | tolerance = 0.05 25 | ) 26 | 27 | aggregated_products <- trade %>% 28 | group_by(product_code) %>% 29 | summarise(trade_value_usd = sum(trade_value_usd)) 30 | 31 | aggregated_products <- setNames(aggregated_products$trade_value_usd, aggregated_products$product_code) 32 | V(net$network_product)$size <- aggregated_products[match(V(net$network_product)$name, names(aggregated_products))] 33 | 34 | set.seed(200100) 35 | 36 | g_products <- net$network_product %>% 37 | ggraph(layout = "fr") + 38 | # geom_edge_link(aes(edge_width = weight), edge_colour = "#a8a8a8") + 39 | geom_edge_link(edge_colour = "#888888") + 40 | geom_node_point(aes(size = size), color = "#86494d") + 41 | # geom_node_text(aes(label = name), vjust = 2.2) + 42 | ggtitle("Proximity Based Network Projection for Products") + 43 | theme_void() 44 | 45 | g_products 46 | -------------------------------------------------------------------------------- /dev/world_gdp_avg_1998_to_2000.R: -------------------------------------------------------------------------------- 1 | library(wbstats) 2 | library(rlang) 3 | library(Matrix) 4 | library(dplyr) 5 | library(purrr) 6 | 7 | reference_year <- 2000 8 | 9 | # inflation <- purrr::map_df( 10 | # 1998:2000, 11 | # function(year) { 12 | # tradestatistics::ots_inflation %>% 13 | # dplyr::filter( 14 | # !!sym("to") <= 2010, 15 | # !!sym("to") > year 16 | # ) %>% 17 | # dplyr::summarise( 18 | # conversion_factor = dplyr::last(cumprod(!!sym("conversion_factor"))) 19 | # ) %>% 20 | # dplyr::mutate( 21 | # year = year, 22 | # conversion_year = 2010 23 | # ) %>% 24 | # dplyr::select(!!!rlang::syms(c("year", "conversion_year", "conversion_factor"))) 25 | # } 26 | # ) 27 | 28 | inflation2 <- purrr::map_df( 29 | 2000, 30 | function(year) { 31 | tradestatistics::ots_inflation %>% 32 | dplyr::filter( 33 | !!sym("to") <= 2010, 34 | !!sym("to") > year 35 | ) %>% 36 | dplyr::summarise( 37 | conversion_factor = dplyr::last(cumprod(!!sym("conversion_factor"))) 38 | ) %>% 39 | dplyr::mutate( 40 | year = year, 41 | conversion_year = 2010 42 | ) %>% 43 | dplyr::select(!!!rlang::syms(c("year", "conversion_year", "conversion_factor"))) 44 | } 45 | ) 46 | 47 | gdp <- wb(indicator = "NY.GDP.PCAP.KD", startdate = 1998, enddate = 2000) 48 | 49 | gdp2 <- gdp %>% 50 | select(year = date, iso3c, gdppc = value) %>% 51 | mutate(year = as.integer(year), iso3c = tolower(iso3c)) %>% 52 | mutate(gdppc = gdppc / inflation2$conversion_factor) 53 | 54 | gdp2 <- gdp2 %>% 55 | group_by(iso3c) %>% 56 | summarise(gdppc = mean(gdppc, na.rm = T)) %>% 57 | mutate(gdppc = round(gdppc, 0)) 58 | 59 | world_gdp_avg_1998_to_2000 <- gdp2 60 | names(world_gdp_avg_1998_to_2000) <- c("country","value") 61 | 62 | save(world_gdp_avg_1998_to_2000, file = 'data/world_gdp_avg_1998_to_2000.rda', compress = "xz") 63 | -------------------------------------------------------------------------------- /dev/world_trade_avg_1998_to_2000.R: -------------------------------------------------------------------------------- 1 | # library(Matrix) 2 | library(rlang) 3 | library(dplyr) 4 | library(tidyr) 5 | library(purrr) 6 | 7 | finp <- list.files(path = "dev/sitc-data", full.names = T) 8 | 9 | reference_year <- 2000 10 | 11 | inflation <- purrr::map_df( 12 | 1998:2000, 13 | function(year) { 14 | tradestatistics::ots_inflation %>% 15 | dplyr::filter( 16 | !!sym("to") <= reference_year, 17 | !!sym("to") > year 18 | ) %>% 19 | dplyr::summarise( 20 | conversion_factor = dplyr::last(cumprod(!!sym("conversion_factor"))) 21 | ) %>% 22 | dplyr::mutate( 23 | year = year, 24 | conversion_year = reference_year 25 | ) %>% 26 | dplyr::select(!!!rlang::syms(c("year", "conversion_year", "conversion_factor"))) 27 | } 28 | ) 29 | 30 | inflation <- inflation %>% mutate(conversion_factor = ifelse(is.na(conversion_factor), 1, conversion_factor)) 31 | 32 | trade <- map_df(finp, readRDS) 33 | 34 | trade <- trade %>% 35 | filter(product_code_length == 4) 36 | 37 | trade <- trade %>% 38 | left_join(inflation) %>% 39 | mutate(trade_value_usd = trade_value_usd * conversion_factor) 40 | 41 | trade <- trade %>% 42 | group_by(reporter_iso, product_code) %>% 43 | summarise(trade_value_usd = mean(trade_value_usd, na.rm = T)) %>% 44 | mutate(trade_value_usd = round(trade_value_usd, 0)) 45 | 46 | # world_trade_avg_1998_to_2000 <- trade %>% 47 | # ungroup() %>% 48 | # mutate_if(is.character, as.factor) 49 | # 50 | # world_trade_avg_1998_to_2000 <- with( 51 | # world_trade_avg_1998_to_2000, 52 | # sparseMatrix( 53 | # i = as.numeric(reporter_iso), 54 | # j = as.numeric(product_code), 55 | # x = trade_value_usd, 56 | # dimnames = list(levels(reporter_iso), levels(product_code)) 57 | # ) 58 | # ) 59 | 60 | world_trade_avg_1998_to_2000 <- trade 61 | names(world_trade_avg_1998_to_2000) <- c("country", "product", "value") 62 | 63 | world_trade_avg_1998_to_2000 <- world_trade_avg_1998_to_2000 %>% 64 | ungroup() 65 | 66 | save(world_trade_avg_1998_to_2000, file = 'data/world_trade_avg_1998_to_2000.rda', compress = "xz") 67 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • economiccomplexity 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Skip to contents 24 | 25 | 26 |
53 |
54 |
58 | 59 | Content not found. Please use links in the navbar. 60 | 61 |
62 |
63 | 64 | 65 |
68 | 69 | 72 | 73 |
74 |
75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /docs/CODE_OF_CONDUCT.html: -------------------------------------------------------------------------------- 1 | 2 | Contributor Code of Conduct • economiccomplexity 3 | Skip to contents 4 | 5 | 6 |
28 |
29 |
33 | 34 |
35 |

As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

36 |

We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.

37 |

Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.

38 |

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.

39 |

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.

40 |

This Code of Conduct is adapted from the Contributor Covenant (http://contributor-covenant.org), version 1.0.0, available at http://contributor-covenant.org/version/1/0/0/

41 |
42 | 43 |
44 | 45 | 46 |
49 | 50 | 53 | 54 |
55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /docs/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-18-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-18-2.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-19-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-19-1.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-19-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-19-2.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-19-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-19-3.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-19-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-19-4.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-19-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-19-5.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-19-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-19-6.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-20-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-20-1.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-21-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-21-1.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-22-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-22-1.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-23-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-23-1.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-24-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-24-1.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-25-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-25-1.png -------------------------------------------------------------------------------- /docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-26-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/articles/economiccomplexity_files/figure-html/unnamed-chunk-26-1.png -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • economiccomplexity 3 | Skip to contents 4 | 5 | 6 |
28 |
29 |
32 | 33 |
34 |

All vignettes

35 |
36 | 37 |
How To Use This Package
38 |
39 |
40 |
41 | 42 | 43 |
46 | 47 | 50 | 51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | Authors and Citation • economiccomplexity 3 | Skip to contents 4 | 5 | 6 |
28 |
29 |
32 | 33 |
34 |

Authors

35 | 36 |
  • 37 |

    Mauricio Vargas Sepulveda. Author, maintainer, copyright holder. 38 |

    39 |
  • 40 |
  • 41 |

    Carlo Bottai. Contributor. 42 |
    improved the eigenvalues calculation

    43 |
  • 44 |
  • 45 |

    Diego Kozlowski. Contributor. 46 |
    provided initial RCA function used up to v0.2.4

    47 |
  • 48 |
  • 49 |

    Nico Pintar. Reviewer. 50 |
    suggested improvements to special cases in eigenvalues 51 | calculation

    52 |
  • 53 |
  • 54 |

    The World Bank. Data contributor. 55 |
    World GDP per capita dataset

    56 |
  • 57 |
  • 58 |

    Open Trade Statistics. Data contributor. 59 |
    World Trade dataset

    60 |
  • 61 |
62 | 63 |
64 |

Citation

65 |

Source: DESCRIPTION

66 | 67 |

Vargas Sepulveda M (2024). 68 | economiccomplexity: Computational Methods for Economic Complexity. 69 | R package version 2.0.0, https://pacha.dev/economiccomplexity/. 70 |

71 |
@Manual{,
 72 |   title = {economiccomplexity: Computational Methods for Economic Complexity},
 73 |   author = {Mauricio {Vargas Sepulveda}},
 74 |   year = {2024},
 75 |   note = {R package version 2.0.0},
 76 |   url = {https://pacha.dev/economiccomplexity/},
 77 | }
78 |
79 | 80 |
82 | 83 | 84 |
87 | 88 | 91 | 92 |
93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /docs/deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v1.0.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | !function(a){"use strict";window.Toc={helpers:{findOrFilter:function(e,t){var n=e.find(t);return e.filter(t).add(n).filter(":not([data-toc-skip])")},generateUniqueIdBase:function(e){return a(e).text().trim().replace(/\'/gi,"").replace(/[& +$,:;=?@"#{}|^~[`%!'<>\]\.\/\(\)\*\\\n\t\b\v]/g,"-").replace(/-{2,}/g,"-").substring(0,64).replace(/^-+|-+$/gm,"").toLowerCase()||e.tagName.toLowerCase()},generateUniqueId:function(e){for(var t=this.generateUniqueIdBase(e),n=0;;n++){var r=t;if(0')},createChildNavList:function(e){var t=this.createNavList();return e.append(t),t},generateNavEl:function(e,t){var n=a('');n.attr("href","#"+e),n.text(t);var r=a("
  • ");return r.append(n),r},generateNavItem:function(e){var t=this.generateAnchor(e),n=a(e),r=n.data("toc-text")||n.text();return this.generateNavEl(t,r)},getTopLevel:function(e){for(var t=1;t<=6;t++){if(1 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-brands-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/deps/font-awesome-6.4.2/webfonts/fa-brands-400.ttf -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-brands-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/deps/font-awesome-6.4.2/webfonts/fa-brands-400.woff2 -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-regular-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/deps/font-awesome-6.4.2/webfonts/fa-regular-400.ttf -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-regular-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/deps/font-awesome-6.4.2/webfonts/fa-regular-400.woff2 -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-solid-900.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/deps/font-awesome-6.4.2/webfonts/fa-solid-900.ttf -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-solid-900.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/deps/font-awesome-6.4.2/webfonts/fa-solid-900.woff2 -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-v4compatibility.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/deps/font-awesome-6.4.2/webfonts/fa-v4compatibility.ttf -------------------------------------------------------------------------------- /docs/deps/font-awesome-6.4.2/webfonts/fa-v4compatibility.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/deps/font-awesome-6.4.2/webfonts/fa-v4compatibility.woff2 -------------------------------------------------------------------------------- /docs/deps/headroom-0.11.0/headroom.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * headroom.js v0.11.0 - Give your page some headroom. Hide your header until you need it 3 | * Copyright (c) 2020 Nick Williams - http://wicky.nillia.ms/headroom.js 4 | * License: MIT 5 | */ 6 | 7 | !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).Headroom=n()}(this,function(){"use strict";function t(){return"undefined"!=typeof window}function d(t){return function(t){return t&&t.document&&function(t){return 9===t.nodeType}(t.document)}(t)?function(t){var n=t.document,o=n.body,s=n.documentElement;return{scrollHeight:function(){return Math.max(o.scrollHeight,s.scrollHeight,o.offsetHeight,s.offsetHeight,o.clientHeight,s.clientHeight)},height:function(){return t.innerHeight||s.clientHeight||o.clientHeight},scrollY:function(){return void 0!==t.pageYOffset?t.pageYOffset:(s||o.parentNode||o).scrollTop}}}(t):function(t){return{scrollHeight:function(){return Math.max(t.scrollHeight,t.offsetHeight,t.clientHeight)},height:function(){return Math.max(t.offsetHeight,t.clientHeight)},scrollY:function(){return t.scrollTop}}}(t)}function n(t,s,e){var n,o=function(){var n=!1;try{var t={get passive(){n=!0}};window.addEventListener("test",t,t),window.removeEventListener("test",t,t)}catch(t){n=!1}return n}(),i=!1,r=d(t),l=r.scrollY(),a={};function c(){var t=Math.round(r.scrollY()),n=r.height(),o=r.scrollHeight();a.scrollY=t,a.lastScrollY=l,a.direction=ls.tolerance[a.direction],e(a),l=t,i=!1}function h(){i||(i=!0,n=requestAnimationFrame(c))}var u=!!o&&{passive:!0,capture:!1};return t.addEventListener("scroll",h,u),c(),{destroy:function(){cancelAnimationFrame(n),t.removeEventListener("scroll",h,u)}}}function o(t,n){n=n||{},Object.assign(this,o.options,n),this.classes=Object.assign({},o.options.classes,n.classes),this.elem=t,this.tolerance=function(t){return t===Object(t)?t:{down:t,up:t}}(this.tolerance),this.initialised=!1,this.frozen=!1}return o.prototype={constructor:o,init:function(){return o.cutsTheMustard&&!this.initialised&&(this.addClass("initial"),this.initialised=!0,setTimeout(function(t){t.scrollTracker=n(t.scroller,{offset:t.offset,tolerance:t.tolerance},t.update.bind(t))},100,this)),this},destroy:function(){this.initialised=!1,Object.keys(this.classes).forEach(this.removeClass,this),this.scrollTracker.destroy()},unpin:function(){!this.hasClass("pinned")&&this.hasClass("unpinned")||(this.addClass("unpinned"),this.removeClass("pinned"),this.onUnpin&&this.onUnpin.call(this))},pin:function(){this.hasClass("unpinned")&&(this.addClass("pinned"),this.removeClass("unpinned"),this.onPin&&this.onPin.call(this))},freeze:function(){this.frozen=!0,this.addClass("frozen")},unfreeze:function(){this.frozen=!1,this.removeClass("frozen")},top:function(){this.hasClass("top")||(this.addClass("top"),this.removeClass("notTop"),this.onTop&&this.onTop.call(this))},notTop:function(){this.hasClass("notTop")||(this.addClass("notTop"),this.removeClass("top"),this.onNotTop&&this.onNotTop.call(this))},bottom:function(){this.hasClass("bottom")||(this.addClass("bottom"),this.removeClass("notBottom"),this.onBottom&&this.onBottom.call(this))},notBottom:function(){this.hasClass("notBottom")||(this.addClass("notBottom"),this.removeClass("bottom"),this.onNotBottom&&this.onNotBottom.call(this))},shouldUnpin:function(t){return"down"===t.direction&&!t.top&&t.toleranceExceeded},shouldPin:function(t){return"up"===t.direction&&t.toleranceExceeded||t.top},addClass:function(t){this.elem.classList.add.apply(this.elem.classList,this.classes[t].split(" "))},removeClass:function(t){this.elem.classList.remove.apply(this.elem.classList,this.classes[t].split(" "))},hasClass:function(t){return this.classes[t].split(" ").every(function(t){return this.classList.contains(t)},this.elem)},update:function(t){t.isOutOfBounds||!0!==this.frozen&&(t.top?this.top():this.notTop(),t.bottom?this.bottom():this.notBottom(),this.shouldUnpin(t)?this.unpin():this.shouldPin(t)&&this.pin())}},o.options={tolerance:{up:0,down:0},offset:0,scroller:t()?window:null,classes:{frozen:"headroom--frozen",pinned:"headroom--pinned",unpinned:"headroom--unpinned",top:"headroom--top",notTop:"headroom--not-top",bottom:"headroom--bottom",notBottom:"headroom--not-bottom",initial:"headroom"}},o.cutsTheMustard=!!(t()&&function(){}.bind&&"classList"in document.documentElement&&Object.assign&&Object.keys&&requestAnimationFrame),o}); -------------------------------------------------------------------------------- /docs/deps/headroom-0.11.0/jQuery.headroom.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * headroom.js v0.9.4 - Give your page some headroom. Hide your header until you need it 3 | * Copyright (c) 2017 Nick Williams - http://wicky.nillia.ms/headroom.js 4 | * License: MIT 5 | */ 6 | 7 | !function(a){a&&(a.fn.headroom=function(b){return this.each(function(){var c=a(this),d=c.data("headroom"),e="object"==typeof b&&b;e=a.extend(!0,{},Headroom.options,e),d||(d=new Headroom(this,e),d.init(),c.data("headroom",d)),"string"==typeof b&&(d[b](),"destroy"===b&&c.removeData("headroom"))})},a("[data-headroom]").each(function(){var b=a(this);b.headroom(b.data())}))}(window.Zepto||window.jQuery); -------------------------------------------------------------------------------- /docs/favicon-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/favicon-96x96.png -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/favicon.ico -------------------------------------------------------------------------------- /docs/katex-auto.js: -------------------------------------------------------------------------------- 1 | // https://github.com/jgm/pandoc/blob/29fa97ab96b8e2d62d48326e1b949a71dc41f47a/src/Text/Pandoc/Writers/HTML.hs#L332-L345 2 | document.addEventListener("DOMContentLoaded", function () { 3 | var mathElements = document.getElementsByClassName("math"); 4 | var macros = []; 5 | for (var i = 0; i < mathElements.length; i++) { 6 | var texText = mathElements[i].firstChild; 7 | if (mathElements[i].tagName == "SPAN") { 8 | katex.render(texText.data, mathElements[i], { 9 | displayMode: mathElements[i].classList.contains("display"), 10 | throwOnError: false, 11 | macros: macros, 12 | fleqn: false 13 | }); 14 | }}}); 15 | -------------------------------------------------------------------------------- /docs/lightswitch.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * Color mode toggler for Bootstrap's docs (https://getbootstrap.com/) 4 | * Copyright 2011-2023 The Bootstrap Authors 5 | * Licensed under the Creative Commons Attribution 3.0 Unported License. 6 | * Updates for {pkgdown} by the {bslib} authors, also licensed under CC-BY-3.0. 7 | */ 8 | 9 | const getStoredTheme = () => localStorage.getItem('theme') 10 | const setStoredTheme = theme => localStorage.setItem('theme', theme) 11 | 12 | const getPreferredTheme = () => { 13 | const storedTheme = getStoredTheme() 14 | if (storedTheme) { 15 | return storedTheme 16 | } 17 | 18 | return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' 19 | } 20 | 21 | const setTheme = theme => { 22 | if (theme === 'auto') { 23 | document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) 24 | } else { 25 | document.documentElement.setAttribute('data-bs-theme', theme) 26 | } 27 | } 28 | 29 | function bsSetupThemeToggle () { 30 | 'use strict' 31 | 32 | const showActiveTheme = (theme, focus = false) => { 33 | var activeLabel, activeIcon; 34 | 35 | document.querySelectorAll('[data-bs-theme-value]').forEach(element => { 36 | const buttonTheme = element.getAttribute('data-bs-theme-value') 37 | const isActive = buttonTheme == theme 38 | 39 | element.classList.toggle('active', isActive) 40 | element.setAttribute('aria-pressed', isActive) 41 | 42 | if (isActive) { 43 | activeLabel = element.textContent; 44 | activeIcon = element.querySelector('span').classList.value; 45 | } 46 | }) 47 | 48 | const themeSwitcher = document.querySelector('#dropdown-lightswitch') 49 | if (!themeSwitcher) { 50 | return 51 | } 52 | 53 | themeSwitcher.setAttribute('aria-label', activeLabel) 54 | themeSwitcher.querySelector('span').classList.value = activeIcon; 55 | 56 | if (focus) { 57 | themeSwitcher.focus() 58 | } 59 | } 60 | 61 | window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { 62 | const storedTheme = getStoredTheme() 63 | if (storedTheme !== 'light' && storedTheme !== 'dark') { 64 | setTheme(getPreferredTheme()) 65 | } 66 | }) 67 | 68 | window.addEventListener('DOMContentLoaded', () => { 69 | showActiveTheme(getPreferredTheme()) 70 | 71 | document 72 | .querySelectorAll('[data-bs-theme-value]') 73 | .forEach(toggle => { 74 | toggle.addEventListener('click', () => { 75 | const theme = toggle.getAttribute('data-bs-theme-value') 76 | setTheme(theme) 77 | setStoredTheme(theme) 78 | showActiveTheme(theme, true) 79 | }) 80 | }) 81 | }) 82 | } 83 | 84 | setTheme(getPreferredTheme()); 85 | bsSetupThemeToggle(); 86 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('nav.navbar').headroom(); 6 | 7 | Toc.init({ 8 | $nav: $("#toc"), 9 | $scope: $("main h2, main h3, main h4, main h5, main h6") 10 | }); 11 | 12 | if ($('#toc').length) { 13 | $('body').scrollspy({ 14 | target: '#toc', 15 | offset: $("nav.navbar").outerHeight() + 1 16 | }); 17 | } 18 | 19 | // Activate popovers 20 | $('[data-bs-toggle="popover"]').popover({ 21 | container: 'body', 22 | html: true, 23 | trigger: 'focus', 24 | placement: "top", 25 | sanitize: false, 26 | }); 27 | 28 | $('[data-bs-toggle="tooltip"]').tooltip(); 29 | 30 | /* Clipboard --------------------------*/ 31 | 32 | function changeTooltipMessage(element, msg) { 33 | var tooltipOriginalTitle=element.getAttribute('data-bs-original-title'); 34 | element.setAttribute('data-bs-original-title', msg); 35 | $(element).tooltip('show'); 36 | element.setAttribute('data-bs-original-title', tooltipOriginalTitle); 37 | } 38 | 39 | if(ClipboardJS.isSupported()) { 40 | $(document).ready(function() { 41 | var copyButton = ""; 42 | 43 | $("div.sourceCode").addClass("hasCopyButton"); 44 | 45 | // Insert copy buttons: 46 | $(copyButton).prependTo(".hasCopyButton"); 47 | 48 | // Initialize tooltips: 49 | $('.btn-copy-ex').tooltip({container: 'body'}); 50 | 51 | // Initialize clipboard: 52 | var clipboard = new ClipboardJS('[data-clipboard-copy]', { 53 | text: function(trigger) { 54 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 55 | } 56 | }); 57 | 58 | clipboard.on('success', function(e) { 59 | changeTooltipMessage(e.trigger, 'Copied!'); 60 | e.clearSelection(); 61 | }); 62 | 63 | clipboard.on('error', function(e) { 64 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 65 | }); 66 | 67 | }); 68 | } 69 | 70 | /* Search marking --------------------------*/ 71 | var url = new URL(window.location.href); 72 | var toMark = url.searchParams.get("q"); 73 | var mark = new Mark("main#main"); 74 | if (toMark) { 75 | mark.mark(toMark, { 76 | accuracy: { 77 | value: "complementary", 78 | limiters: [",", ".", ":", "/"], 79 | } 80 | }); 81 | } 82 | 83 | /* Search --------------------------*/ 84 | /* Adapted from https://github.com/rstudio/bookdown/blob/2d692ba4b61f1e466c92e78fd712b0ab08c11d31/inst/resources/bs4_book/bs4_book.js#L25 */ 85 | // Initialise search index on focus 86 | var fuse; 87 | $("#search-input").focus(async function(e) { 88 | if (fuse) { 89 | return; 90 | } 91 | 92 | $(e.target).addClass("loading"); 93 | var response = await fetch($("#search-input").data("search-index")); 94 | var data = await response.json(); 95 | 96 | var options = { 97 | keys: ["what", "text", "code"], 98 | ignoreLocation: true, 99 | threshold: 0.1, 100 | includeMatches: true, 101 | includeScore: true, 102 | }; 103 | fuse = new Fuse(data, options); 104 | 105 | $(e.target).removeClass("loading"); 106 | }); 107 | 108 | // Use algolia autocomplete 109 | var options = { 110 | autoselect: true, 111 | debug: true, 112 | hint: false, 113 | minLength: 2, 114 | }; 115 | var q; 116 | async function searchFuse(query, callback) { 117 | await fuse; 118 | 119 | var items; 120 | if (!fuse) { 121 | items = []; 122 | } else { 123 | q = query; 124 | var results = fuse.search(query, { limit: 20 }); 125 | items = results 126 | .filter((x) => x.score <= 0.75) 127 | .map((x) => x.item); 128 | if (items.length === 0) { 129 | items = [{dir:"Sorry 😿",previous_headings:"",title:"No results found.",what:"No results found.",path:window.location.href}]; 130 | } 131 | } 132 | callback(items); 133 | } 134 | $("#search-input").autocomplete(options, [ 135 | { 136 | name: "content", 137 | source: searchFuse, 138 | templates: { 139 | suggestion: (s) => { 140 | if (s.title == s.what) { 141 | return `${s.dir} >
    ${s.title}
    `; 142 | } else if (s.previous_headings == "") { 143 | return `${s.dir} >
    ${s.title}
    > ${s.what}`; 144 | } else { 145 | return `${s.dir} >
    ${s.title}
    > ${s.previous_headings} > ${s.what}`; 146 | } 147 | }, 148 | }, 149 | }, 150 | ]).on('autocomplete:selected', function(event, s) { 151 | window.location.href = s.path + "?q=" + q + "#" + s.id; 152 | }); 153 | }); 154 | })(window.jQuery || window.$) 155 | 156 | document.addEventListener('keydown', function(event) { 157 | // Check if the pressed key is '/' 158 | if (event.key === '/') { 159 | event.preventDefault(); // Prevent any default action associated with the '/' key 160 | document.getElementById('search-input').focus(); // Set focus to the search input 161 | } 162 | }); 163 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.9.2.1 2 | pkgdown: 2.1.1.9000 3 | pkgdown_sha: 71fd32ce95f17b379e57e7e33f2294bc034727fd 4 | articles: 5 | economiccomplexity: economiccomplexity.html 6 | last_built: 2024-12-16T15:14Z 7 | -------------------------------------------------------------------------------- /docs/reference/country_aggregation.html: -------------------------------------------------------------------------------- 1 | 2 | country aggregation — country_aggregation • economiccomplexity 3 | Skip to contents 4 | 5 | 6 |
    28 |
    29 |
    34 | 35 |
    36 |

    country aggregation

    37 |
    38 | 39 |
    40 |

    Usage

    41 |
    country_aggregation(dataframe, country = "country", value = "value")
    42 |
    43 | 44 | 45 |
    46 | 47 | 48 |
    51 | 52 | 55 | 56 |
    57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /docs/reference/country_product_aggregation.html: -------------------------------------------------------------------------------- 1 | 2 | country-product aggregation — country_product_aggregation • economiccomplexity 3 | Skip to contents 4 | 5 | 6 |
    28 |
    29 |
    34 | 35 |
    36 |

    country-product aggregation

    37 |
    38 | 39 |
    40 |

    Usage

    41 |
    country_product_aggregation(
    42 |   dataframe,
    43 |   country = "country",
    44 |   product = "product",
    45 |   value = "value"
    46 | )
    47 |
    48 | 49 | 50 |
    51 | 52 | 53 |
    56 | 57 | 60 | 61 |
    62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /docs/reference/dataframe_to_matrix.html: -------------------------------------------------------------------------------- 1 | 2 | Dataframe to matrix — dataframe_to_matrix • economiccomplexity 3 | Skip to contents 4 | 5 | 6 |
    28 |
    29 |
    34 | 35 |
    36 |

    Dataframe to matrix

    37 |
    38 | 39 |
    40 |

    Usage

    41 |
    dataframe_to_matrix(
    42 |   dataframe,
    43 |   country = "country",
    44 |   product = "product",
    45 |   value = "value"
    46 | )
    47 |
    48 | 49 | 50 |
    51 | 52 | 53 |
    56 | 57 | 60 | 61 |
    62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /docs/reference/economiccomplexity-package.html: -------------------------------------------------------------------------------- 1 | 2 | economiccomplexity: Computational Methods for Economic Complexity — economiccomplexity-package • economiccomplexity 5 | Skip to contents 6 | 7 | 8 |
    30 |
    31 |
    36 | 37 |
    38 |

    A wrapper of different methods from Linear Algebra for the equations introduced in The Atlas of Economic Complexity and related literature. This package provides standard matrix and graph output that can be used seamlessly with other packages. See doi:10.21105/joss.01866 39 | for a summary of these methods and its evolution in literature.

    40 |
    41 | 42 | 43 |
    44 |

    See also

    45 | 48 |
    49 |
    50 |

    Author

    51 |

    Maintainer: Mauricio Vargas Sepulveda m.sepulveda@mail.utoronto.ca (ORCID) [copyright holder]

    52 |

    Other contributors:

    • Carlo Bottai (improved the eigenvalues calculation) [contributor]

    • 53 |
    • Diego Kozlowski (provided initial RCA function used up to v0.2.4) [contributor]

    • 54 |
    • Nico Pintar (suggested improvements to special cases in eigenvalues calculation) [reviewer]

    • 55 |
    • The World Bank (World GDP per capita dataset) [data contributor]

    • 56 |
    • Open Trade Statistics (World Trade dataset) [data contributor]

    • 57 |
    58 | 59 |
    61 | 62 | 63 |
    66 | 67 | 70 | 71 |
    72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | Package index • economiccomplexity 3 | Skip to contents 4 | 5 | 6 |
    28 |
    29 |
    32 | 33 |
    34 |

    All functions

    35 | 36 | 37 | 38 | 39 |
    40 | 41 | 42 | 43 | 44 |
    45 | 46 | balassa_index() 47 | 48 |
    49 |
    Balassa Index
    50 |
    51 | 52 | complexity_measures() 53 | 54 |
    55 |
    Complexity Measures
    56 |
    57 | 58 | complexity_outlook() 59 | 60 |
    61 |
    Complexity Outlook
    62 |
    63 | 64 | density() 65 | 66 |
    67 |
    Density
    68 |
    69 | 70 | distance() 71 | 72 |
    73 |
    Distance
    74 |
    75 | 76 | economiccomplexity_output 77 | 78 |
    79 |
    Example Outputs of the Functions within the Package
    80 |
    81 | 82 | productivity_levels() 83 | 84 |
    85 |
    Productivity Levels
    86 |
    87 | 88 | projections() 89 | 90 |
    91 |
    Projections of a Country-Product Network
    92 |
    93 | 94 | proximity() 95 | 96 |
    97 |
    Proximity
    98 |
    99 | 100 | rca() 101 | 102 |
    103 |
    Revealed Comparative Advantage
    104 |
    105 | 106 | world_gdp_avg_1998_to_2000 107 | 108 |
    109 |
    World Trade Per-Capita GDP for the Period 1998-2000
    110 |
    111 | 112 | world_trade_avg_1998_to_2000 113 | 114 |
    115 |
    World Trade Averages for the Period 1998-2000
    116 |
    117 |
    118 | 119 | 120 |
    123 | 124 | 127 | 128 |
    129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /docs/reference/rca.html: -------------------------------------------------------------------------------- 1 | 2 | Revealed Comparative Advantage — rca • economiccomplexity 3 | Skip to contents 4 | 5 | 6 |
    28 |
    29 |
    34 | 35 |
    36 |

    balassa_index() replaces this function

    37 |
    38 | 39 |
    40 |

    Usage

    41 |
    rca(...)
    42 |
    43 | 44 |
    45 |

    Arguments

    46 | 47 | 48 |
    ...
    49 |

    old parameters

    50 | 51 |
    52 | 53 |
    55 | 56 | 57 |
    60 | 61 | 64 | 65 |
    66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /docs/reference/world_gdp_avg_1998_to_2000.html: -------------------------------------------------------------------------------- 1 | 2 | World Trade Per-Capita GDP for the Period 1998-2000 — world_gdp_avg_1998_to_2000 • economiccomplexity 3 | Skip to contents 4 | 5 | 6 |
    28 |
    29 |
    34 | 35 |
    36 |

    A data frame that summarizes the per-capita GDP of different countries. The unit is year 2000 USD.

    37 |
    38 | 39 |
    40 |

    Usage

    41 |
    data(world_gdp_avg_1998_to_2000)
    42 |
    43 | 44 |
    45 |

    Format

    46 |

    A data frame with 240 rows and 2 columns.

    47 |
    48 | 49 |
    50 |

    Examples

    51 |
    data(world_gdp_avg_1998_to_2000)
    52 | head(world_gdp_avg_1998_to_2000)
    53 | #> # A tibble: 6 × 2
    54 | #>   country value
    55 | #>   <chr>   <dbl>
    56 | #> 1 abw     19185
    57 | #> 2 ago      1540
    58 | #> 3 alb      1433
    59 | #> 4 and     27765
    60 | #> 5 arb      3312
    61 | #> 6 are     43082
    62 | 
    63 |
    64 |
    66 | 67 | 68 |
    71 | 72 | 75 | 76 |
    77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /docs/reference/world_trade_avg_1998_to_2000.html: -------------------------------------------------------------------------------- 1 | 2 | World Trade Averages for the Period 1998-2000 — world_trade_avg_1998_to_2000 • economiccomplexity 3 | Skip to contents 4 | 5 | 6 |
    28 |
    29 |
    34 | 35 |
    36 |

    A data frame that summarizes all the products that different countries exported to the rest of the world. This data uses the SITC revision 2 classification with four digits product codes. The unit is year 2000 USD.

    37 |
    38 | 39 |
    40 |

    Usage

    41 |
    data(world_trade_avg_1998_to_2000)
    42 |
    43 | 44 |
    45 |

    Format

    46 |

    A data frame with 124,336 rows and 3 columns.

    47 |
    48 | 49 |
    50 |

    Examples

    51 |
    data(world_trade_avg_1998_to_2000)
    52 | head(world_trade_avg_1998_to_2000)
    53 | #> # A tibble: 6 × 3
    54 | #>   country product value
    55 | #>   <chr>   <chr>   <dbl>
    56 | #> 1 afg     0011    30068
    57 | #> 2 afg     0012    16366
    58 | #> 3 afg     0111    19273
    59 | #> 4 afg     0112      893
    60 | #> 5 afg     0113      350
    61 | #> 6 afg     0116     1561
    62 | 
    63 |
    64 |
    66 | 67 | 68 |
    71 | 72 | 75 | 76 |
    77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /docs/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "short_name": "", 4 | "icons": [ 5 | { 6 | "src": "/web-app-manifest-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png", 9 | "purpose": "maskable" 10 | }, 11 | { 12 | "src": "/web-app-manifest-512x512.png", 13 | "sizes": "512x512", 14 | "type": "image/png", 15 | "purpose": "maskable" 16 | } 17 | ], 18 | "theme_color": "#ffffff", 19 | "background_color": "#ffffff", 20 | "display": "standalone" 21 | } -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | /404.html 3 | /CODE_OF_CONDUCT.html 4 | /LICENSE-text.html 5 | /LICENSE.html 6 | /articles/economiccomplexity.html 7 | /articles/index.html 8 | /authors.html 9 | /index.html 10 | /reference/balassa_index.html 11 | /reference/complexity_measures.html 12 | /reference/complexity_outlook.html 13 | /reference/country_aggregation.html 14 | /reference/country_product_aggregation.html 15 | /reference/dataframe_to_matrix.html 16 | /reference/density.html 17 | /reference/distance.html 18 | /reference/economiccomplexity-package.html 19 | /reference/economiccomplexity_output.html 20 | /reference/index.html 21 | /reference/productivity_levels.html 22 | /reference/projections.html 23 | /reference/proximity.html 24 | /reference/rca.html 25 | /reference/world_gdp_avg_1998_to_2000.html 26 | /reference/world_trade_avg_1998_to_2000.html 27 | 28 | 29 | -------------------------------------------------------------------------------- /docs/web-app-manifest-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/web-app-manifest-192x192.png -------------------------------------------------------------------------------- /docs/web-app-manifest-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/docs/web-app-manifest-512x512.png -------------------------------------------------------------------------------- /economiccomplexity.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace,vignette 22 | -------------------------------------------------------------------------------- /inst/REFERENCES.bib: -------------------------------------------------------------------------------- 1 | @techreport{exportmatters2005, 2 | title = {What You Export Matters}, 3 | author = {Hausmann, Ricardo and Hwang, Jason and Rodrik, Dani}, 4 | institution = {National Bureau of Economic Research}, 5 | type = {Working Paper}, 6 | series = {Working Paper Series}, 7 | number = {11905}, 8 | year = {2005}, 9 | month = {December}, 10 | doi = {10.3386/w11905} 11 | } 12 | 13 | @article{computing2009, 14 | author = {Stodden, Victoria}, 15 | journal = {Computing in Science Engineering}, 16 | title = {The Legal Framework for Reproducible Scientific Research: Licensing and Copyright}, 17 | year = {2009}, 18 | volume = {11}, 19 | number = {1}, 20 | pages = {35-40}, 21 | doi = {10.1109/MCSE.2009.19}, 22 | month = {Jan} 23 | } 24 | 25 | @article{productspace2007, 26 | author = {Hidalgo, C. A. and Klinger, B. and Barab{\'a}si, A.-L. and Hausmann, R.}, 27 | title = {The Product Space Conditions the Development of Nations}, 28 | volume = {317}, 29 | number = {5837}, 30 | pages = {482--487}, 31 | year = {2007}, 32 | doi = {10.1126/science.1144581}, 33 | publisher = {American Association for the Advancement of Science}, 34 | issn = {0036-8075}, 35 | URL = {https://science.sciencemag.org/content/317/5837/482}, 36 | eprint = {https://science.sciencemag.org/content/317/5837/482.full.pdf}, 37 | journal = {Science} 38 | } 39 | 40 | @article {buildingblocks2009, 41 | author = {Hidalgo, C{\'e}sar A. and Hausmann, Ricardo}, 42 | title = {The building blocks of economic complexity}, 43 | volume = {106}, 44 | number = {26}, 45 | pages = {10570--10575}, 46 | year = {2009}, 47 | doi = {10.1073/pnas.0900943106}, 48 | publisher = {National Academy of Sciences}, 49 | issn = {0027-8424}, 50 | URL = {https://www.pnas.org/content/106/26/10570}, 51 | eprint = {https://www.pnas.org/content/106/26/10570.full.pdf}, 52 | journal = {Proceedings of the National Academy of Sciences} 53 | } 54 | 55 | @article{reproducible2011, 56 | author = {Peng, Roger D.}, 57 | title = {Reproducible Research in Computational Science}, 58 | volume = {334}, 59 | number = {6060}, 60 | pages = {1226--1227}, 61 | year = {2011}, 62 | doi = {10.1126/science.1213847}, 63 | publisher = {American Association for the Advancement of Science}, 64 | issn = {0036-8075}, 65 | URL = {https://science.sciencemag.org/content/334/6060/1226}, 66 | eprint = {https://science.sciencemag.org/content/334/6060/1226.full.pdf}, 67 | journal = {Science} 68 | } 69 | 70 | @article{metrics2012, 71 | title={A new metrics for countries' fitness and products' complexity}, 72 | author={Tacchella, Andrea and Cristelli, Matthieu and Caldarelli, Guido and Gabrielli, Andrea and Pietronero, Luciano}, 73 | journal={Scientific reports}, 74 | volume={2}, 75 | pages={723}, 76 | year={2012}, 77 | publisher={Nature Publishing Group}, 78 | doi={10.1038/srep00723} 79 | } 80 | 81 | @book{atlas2014, 82 | title = {The atlas of economic complexity: Mapping paths to prosperity}, 83 | author = {Hausmann, Ricardo and Hidalgo, C{\'e}sar and Bustos, Sebasti{\'a}n and Coscia, Michele and Simoes, Alexander and Yildirim, Muhammed}, 84 | year = {2014}, 85 | doi = {10.7551/mitpress/9647.001.0001}, 86 | publisher = {MIT Press} 87 | } 88 | 89 | @article{measuring2014, 90 | title={Measuring reproducibility in computer systems research}, 91 | author={Collberg, Christian and Proebsting, Todd and Moraila, Gina and Shankaran, Akash and Shi, Zuoming and Warren, Alex M}, 92 | journal={Department of Computer Science, University of Arizona, Tech. Rep}, 93 | volume={37}, 94 | year={2014} 95 | } 96 | 97 | @article{scientific2014, 98 | author = {Cimini, Giulio and Gabrielli, Andrea and Sylos Labini, Francesco}, 99 | journal = {PLOS ONE}, 100 | publisher = {Public Library of Science}, 101 | title = {The Scientific Competitiveness of Nations}, 102 | year = {2014}, 103 | month = {12}, 104 | volume = {9}, 105 | url = {https://doi.org/10.1371/journal.pone.0113470}, 106 | pages = {1-11}, 107 | number = {12}, 108 | doi = {10.1371/journal.pone.0113470} 109 | } 110 | 111 | @article{measuringcomplexity2015, 112 | title = {Measuring economic complexity of countries and products: which metric to use?}, 113 | author = {Mariani, Manuel and Vidmer, Alexandre and Medo, Mats{\'u}{\v{s}} and Zhang, Yi-Cheng}, 114 | journal = {The European Physical Journal B}, 115 | volume = {88}, 116 | number = {11}, 117 | pages = {293}, 118 | year = {2015}, 119 | doi = {10.1140/epjb/e2015-60298-7}, 120 | publisher = {Springer} 121 | } 122 | 123 | @article{ranking2015, 124 | title={Ranking species in mutualistic networks}, 125 | author={Dom{\'i}nguez-Garc{\'i}a, Virginia and Munoz, Miguel A}, 126 | journal={Scientific reports}, 127 | volume={5}, 128 | pages={8182}, 129 | year={2015}, 130 | publisher={Nature Publishing Group}, 131 | doi={10.1038/srep08182} 132 | } 133 | 134 | @article{linking2017, 135 | author = {Hartmann, Dominik and Guevara, Miguel R. and Jara-Figueroa, Cristian and Aristarán, Manuel and Hidalgo, César A.}, 136 | title = {Linking Economic Complexity, Institutions, and Income Inequality}, 137 | volume = {93}, 138 | pages = {75 - 93}, 139 | year = {2017}, 140 | doi = {10.1016/j.worlddev.2016.12.020}, 141 | issn = {0305-750X}, 142 | URL = {http://www.sciencedirect.com/science/article/pii/S0305750X15309876}, 143 | journal = {World Development} 144 | } 145 | 146 | @Manual{matrix, 147 | title = {Matrix: Sparse and Dense Matrix Classes and Methods}, 148 | author = {Douglas Bates and Martin Maechler}, 149 | year = {2019}, 150 | note = {R package version 1.2-18}, 151 | url = {https://CRAN.R-project.org/package=Matrix} 152 | } 153 | 154 | @Article{igraph, 155 | title = {The igraph software package for complex network research}, 156 | author = {Gabor Csardi and Tamas Nepusz}, 157 | journal = {InterJournal}, 158 | volume = {Complex Systems}, 159 | pages = {1695}, 160 | year = {2006}, 161 | url = {http://igraph.org} 162 | } 163 | -------------------------------------------------------------------------------- /inst/paper.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Economiccomplexity: Computational Methods for Economic Complexity' 3 | authors: 4 | - affiliation: 1 5 | name: Mauricio Vargas 6 | orcid: 0000-0003-1017-7574 7 | date: "23 August 2018" 8 | output: pdf_document 9 | bibliography: REFERENCES.bib 10 | tags: 11 | - R 12 | - economic complexity 13 | - international trade 14 | - income inequality 15 | - migration 16 | affiliations: 17 | - index: 1 18 | name: Pontifical Catholic University of Chile 19 | --- 20 | 21 | # Summary 22 | 23 | Economic complexity introduces network theory concepts to different social 24 | science considerations related to international trade and income inequality. 25 | With the bulk of literature established in the last decade, the field of 26 | economic complexity is relatively new. Its approach starts from representing 27 | international trade data as a bipartite network that connects countries to the 28 | products that they export. 29 | 30 | Seminal papers in economic complexity are: @productspace2007, which introduces 31 | graphs to explore trade diversification and export opportunities; and 32 | @buildingblocks2009, which develops dedicated metrics of complexity. These two 33 | articles are expanded and interpreted by @atlas2014, whose typesetted equations 34 | were translated to code in the R package **economiccomplexity**. 35 | 36 | This R package provides different methods to compute complexity metrics that ease 37 | access to this line of research for social scientists. `economiccomplexity::` 38 | depends on `Matrix::` and `igraph::`, and 39 | follows the same design philosophy, grammar, and data structures from it 40 | [@matrix; @igraph]. 41 | 42 | Recent articles such as @linking2017 introduce the question whereas a country's 43 | mix of products could predict its pattern of diversification and income 44 | inequality, but do not include linked and executable code and data. This 45 | separation between the research, the complete process that produced the 46 | results, and its presentation, makes it difficult for others to verify the 47 | findings in the study. 48 | 49 | `economiccomplexity::` might help to evaluate research findings in this 50 | particular area, reducing the number of studies that are not reproducible, or 51 | only partially reproducible with some discrepancies, conditional on the 52 | availability of data, metadata, and computing power that may be unavailable to 53 | all researchers. 54 | 55 | The central contribution of `economiccomplexity::` is to provide functions that 56 | use recursive linear algebra methods from @buildingblocks2009 in R, with tests 57 | and full documentation for release on CRAN, the dominant repository of R 58 | software. 59 | 60 | @metrics2012 presents non-linear iterative methods that extend 61 | the linear approach from @buildingblocks2009 in order to capture the link 62 | between the export basket of different countries and their industrial 63 | competitiveness. This approach is also implemented in `economiccomplexity::`, but 64 | following the formulation from @measuringcomplexity2015 that introduces 65 | extremality parameters that generalize the original formulation. 66 | 67 | @reproducible2011 states that reproducibility has the potential to serve as a 68 | minimum standard when full independent replication of a study is not possible, 69 | and that becomes even more important to evaluate scientific claims in studies 70 | with public policy implications. A tenet of the scientific method holds that 71 | every research finding should be reproducible before it becomes accepted as a 72 | genuine contribution to human knowledge [@computing2009]. 73 | 74 | Complexity methods are also used outside its original research area. In 75 | particular, the fitness method from @metrics2012 has been used in ecology to 76 | study species interaction [@ranking2015] and, more directly related, to 77 | study the scientific competitiveness of nations [@scientific2014]. 78 | 79 | The application widespread of economic complexity should be considered with 80 | caution. Any theoretical or computational implementation shall be far 81 | from becoming a keystone if reproducibility is ignored. The extent to which code 82 | in computational research would build with reasonable effort is lower than 20% 83 | [@measuring2014]. A desirable growth pattern should focus on reproducibility, 84 | and I hope this package means a contribution to transparent research 85 | practices. 86 | 87 | @atlas2014 proposes the equivalency between the reflections and 88 | the eigenvalues methods that they present. My code on GitHub 89 | checks for the sign of the correlation for the vector output of the two methods and 90 | corrects the eigenvalues output when necessary. What motivated those additional 91 | steps is that, what I initially tought it was an error, turned out to be a 92 | particular case that emerges with some datasets. Shortly after implementing that, 93 | both Python and Stata users started sending me emails when they, independently, 94 | found the same problem and then search engines led them to my package. 95 | 96 | # References 97 | -------------------------------------------------------------------------------- /inst/paper.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/inst/paper.pdf -------------------------------------------------------------------------------- /man/balassa_index.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/balassa_index.R 3 | \name{balassa_index} 4 | \alias{balassa_index} 5 | \title{Balassa Index} 6 | \usage{ 7 | balassa_index( 8 | trade_data, 9 | discrete = TRUE, 10 | cutoff = 1, 11 | country = "country", 12 | product = "product", 13 | value = "value" 14 | ) 15 | } 16 | \arguments{ 17 | \item{trade_data}{(Type: data.frame or matrix) a dataset such as 18 | \code{world_gdp_avg_1998_to_2000} containing countries, products and exported 19 | values.} 20 | 21 | \item{discrete}{(Type: logical) whether converting the Balassa Index to 22 | discrete (0/1) values. Anything below the specified cutoff is converted to 0 23 | and 1 otherwise. By default this is set to \code{TRUE}.} 24 | 25 | \item{cutoff}{(Type: numeric) the cutoff to use for discretization. 26 | By default this is set to \code{1}.} 27 | 28 | \item{country}{(Type: character) the column with the countries. 29 | By default this is set to \code{"country"}. Used only if the input is a 30 | data.frame.} 31 | 32 | \item{product}{(Type: character) the column with the products. 33 | By default this is set to \code{"product"}. Used only if the input is a 34 | data.frame.} 35 | 36 | \item{value}{(Type: character) the column with the metric for 37 | country-product pairs. 38 | By default this is set to \code{"value"}. Used only if the input is a 39 | data.frame.} 40 | } 41 | \value{ 42 | A matrix with the Balassa Index. 43 | } 44 | \description{ 45 | \code{balassa_index()} computes the Balassa Index for a 46 | bipartite relation between countries and products. 47 | } 48 | \details{ 49 | The current implementation follows 50 | \insertCite{measuringcomplexity2015}{economiccomplexity} to obtain a metric 51 | for specialisation. In the context of international trade, if the Balassa 52 | Index for a country-product pair is more than 1, it means that country is 53 | specialized in that product. If the input for this function is a data.frame 54 | instead of a matrix, the function shall aggregate the data and convert the 55 | input to a matrix. 56 | } 57 | \examples{ 58 | bi <- balassa_index(world_trade_avg_1998_to_2000) 59 | 60 | # partial view of index 61 | n <- seq_len(5) 62 | bi[n, n] 63 | 64 | } 65 | \references{ 66 | For more information see: 67 | 68 | \insertRef{measuringcomplexity2015}{economiccomplexity} 69 | 70 | and the references therein. 71 | } 72 | \keyword{functions} 73 | -------------------------------------------------------------------------------- /man/complexity_measures.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/complexity_measures.R 3 | \name{complexity_measures} 4 | \alias{complexity_measures} 5 | \title{Complexity Measures} 6 | \usage{ 7 | complexity_measures( 8 | balassa_index, 9 | method = "fitness", 10 | iterations = 20, 11 | extremality = 1 12 | ) 13 | } 14 | \arguments{ 15 | \item{balassa_index}{(Type: matrix) the output from 16 | \code{balassa_index()}) or an equivalent arrangement.} 17 | 18 | \item{method}{(Type: character) one of these methods: fitness, 19 | reflections or eigenvalues. By default this is set to \code{"fitness"}.} 20 | 21 | \item{iterations}{(Type: numeric) the number of iterations to use. 22 | By default this is set to \code{20}.} 23 | 24 | \item{extremality}{(Type: numeric) the parameter to use in the fitness 25 | method. The other methods don't use this parameter. 26 | By default this is set to \code{1}.} 27 | } 28 | \value{ 29 | A list of two named numeric vectors. 30 | } 31 | \description{ 32 | \code{complexity_measures()} computes the Economic Complexity 33 | Index and the Product Complexity Index. 34 | } 35 | \details{ 36 | The current implementation follows 37 | \insertCite{measuringcomplexity2015}{economiccomplexity} to obtain different 38 | alternatives that account for diversification in bipartite relations. 39 | } 40 | \examples{ 41 | co <- complexity_measures(economiccomplexity_output$balassa_index) 42 | 43 | # partial view of indexes 44 | n <- seq_len(5) 45 | co$complexity_index_country[n] 46 | co$complexity_index_product[n] 47 | 48 | } 49 | \references{ 50 | For more information on this index see: 51 | 52 | \insertRef{measuringcomplexity2015}{economiccomplexity} 53 | 54 | and the references therein. 55 | } 56 | \keyword{functions} 57 | -------------------------------------------------------------------------------- /man/complexity_outlook.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/complexity_outlook.R 3 | \name{complexity_outlook} 4 | \alias{complexity_outlook} 5 | \title{Complexity Outlook} 6 | \usage{ 7 | complexity_outlook(balassa_index, proximity_product, complexity_index_product) 8 | } 9 | \arguments{ 10 | \item{balassa_index}{(Type: matrix) the output from 11 | \code{balassa_index()}) or an equivalent arrangement.} 12 | 13 | \item{proximity_product}{(Type: matrix) the output from 14 | \code{proximity()}) or an equivalent arrangement.} 15 | 16 | \item{complexity_index_product}{(Type: numeric) the output from 17 | \code{complexity_measures()}) or an equivalent arrangement.} 18 | } 19 | \value{ 20 | A list of two named numeric vectors. 21 | } 22 | \description{ 23 | \code{complexity_outlook()} computes the Complexity Outlook 24 | Index and the Complexity Outlook Gain. 25 | } 26 | \details{ 27 | The current implementation follows 28 | \insertCite{atlas2014}{economiccomplexity} to measure unexploited 29 | export oppportunities. 30 | } 31 | \examples{ 32 | co <- complexity_outlook( 33 | economiccomplexity_output$balassa_index, 34 | economiccomplexity_output$proximity$proximity_product, 35 | economiccomplexity_output$complexity_measures$complexity_index_product 36 | ) 37 | 38 | # partial view of complexity outlook 39 | n <- seq_len(5) 40 | co$complexity_outlook_index[n] 41 | co$complexity_outlook_gain[n, n] 42 | 43 | } 44 | \references{ 45 | For more information on this index see: 46 | 47 | \insertRef{atlas2014}{economiccomplexity} 48 | 49 | and the references therein. 50 | } 51 | \keyword{functions} 52 | -------------------------------------------------------------------------------- /man/country_aggregation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{country_aggregation} 4 | \alias{country_aggregation} 5 | \title{country aggregation} 6 | \usage{ 7 | country_aggregation(dataframe, country = "country", value = "value") 8 | } 9 | \description{ 10 | country aggregation 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/country_product_aggregation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{country_product_aggregation} 4 | \alias{country_product_aggregation} 5 | \title{country-product aggregation} 6 | \usage{ 7 | country_product_aggregation( 8 | dataframe, 9 | country = "country", 10 | product = "product", 11 | value = "value" 12 | ) 13 | } 14 | \description{ 15 | country-product aggregation 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/dataframe_to_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{dataframe_to_matrix} 4 | \alias{dataframe_to_matrix} 5 | \title{Dataframe to matrix} 6 | \usage{ 7 | dataframe_to_matrix( 8 | dataframe, 9 | country = "country", 10 | product = "product", 11 | value = "value" 12 | ) 13 | } 14 | \description{ 15 | Dataframe to matrix 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/density.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/density.R 3 | \name{density} 4 | \alias{density} 5 | \title{Density} 6 | \usage{ 7 | density(balassa_index, proximity_product) 8 | } 9 | \arguments{ 10 | \item{balassa_index}{(Type: matrix) the output from 11 | \code{balassa_index()}) or an equivalent arrangement.} 12 | 13 | \item{proximity_product}{(Type: matrix) the output from 14 | \code{proximity()}) or an equivalent arrangement.} 15 | } 16 | \value{ 17 | A matrix. 18 | } 19 | \description{ 20 | \code{density()} computes the density matrix that 21 | accounts for the weighted proportions of the products connected to 22 | each good that the countries are exporting. 23 | } 24 | \details{ 25 | The current implementation follows 26 | \insertCite{atlas2014}{economiccomplexity} to measure the oppotunities 27 | implied by a country's position. 28 | } 29 | \examples{ 30 | d <- density( 31 | economiccomplexity_output$balassa_index, 32 | economiccomplexity_output$proximity$proximity_product 33 | ) 34 | 35 | # partial view of the density matrix 36 | n <- seq_len(5) 37 | d[n, n] 38 | 39 | } 40 | \references{ 41 | For more information on this index see: 42 | 43 | \insertRef{atlas2014}{economiccomplexity} 44 | 45 | and the references therein. 46 | } 47 | \keyword{functions} 48 | -------------------------------------------------------------------------------- /man/distance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/distance.R 3 | \name{distance} 4 | \alias{distance} 5 | \title{Distance} 6 | \usage{ 7 | distance(balassa_index, proximity_product) 8 | } 9 | \arguments{ 10 | \item{balassa_index}{(Type: matrix) the output from 11 | \code{balassa_index()}) or an equivalent arrangement.} 12 | 13 | \item{proximity_product}{(Type: matrix) the output from 14 | \code{proximity()}) or an equivalent arrangement.} 15 | } 16 | \value{ 17 | A matrix. 18 | } 19 | \description{ 20 | \code{distance()} computes the distance matrix that 21 | accounts for the weighted proportions of the products connected to 22 | each good that the countries are not exporting. 23 | } 24 | \details{ 25 | The current implementation follows 26 | \insertCite{atlas2014}{economiccomplexity} to measure the oppotunities 27 | implied by a country's position. 28 | } 29 | \examples{ 30 | d <- distance( 31 | economiccomplexity_output$balassa_index, 32 | economiccomplexity_output$proximity$proximity_product 33 | ) 34 | 35 | # partial view of the distance matrix 36 | n <- seq_len(5) 37 | d[n, n] 38 | 39 | } 40 | \references{ 41 | For more information on this index see: 42 | 43 | \insertRef{atlas2014}{economiccomplexity} 44 | 45 | and the references therein. 46 | } 47 | \keyword{functions} 48 | -------------------------------------------------------------------------------- /man/economiccomplexity-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/economiccomplexity-package.R 3 | \docType{package} 4 | \name{economiccomplexity-package} 5 | \alias{economiccomplexity} 6 | \alias{economiccomplexity-package} 7 | \title{economiccomplexity: Computational Methods for Economic Complexity} 8 | \description{ 9 | A wrapper of different methods from Linear Algebra for the equations introduced in The Atlas of Economic Complexity and related literature. This package provides standard matrix and graph output that can be used seamlessly with other packages. See \doi{10.21105/joss.01866} for a summary of these methods and its evolution in literature. 10 | } 11 | \seealso{ 12 | Useful links: 13 | \itemize{ 14 | \item \url{https://pacha.dev/economiccomplexity/} 15 | \item Report bugs at \url{https://github.com/pachadotdev/economiccomplexity/issues/} 16 | } 17 | 18 | } 19 | \author{ 20 | \strong{Maintainer}: Mauricio Vargas Sepulveda \email{m.sepulveda@mail.utoronto.ca} (\href{https://orcid.org/0000-0003-1017-7574}{ORCID}) [copyright holder] 21 | 22 | Other contributors: 23 | \itemize{ 24 | \item Carlo Bottai (improved the eigenvalues calculation) [contributor] 25 | \item Diego Kozlowski (provided initial RCA function used up to v0.2.4) [contributor] 26 | \item Nico Pintar (suggested improvements to special cases in eigenvalues calculation) [reviewer] 27 | \item The World Bank (World GDP per capita dataset) [data contributor] 28 | \item Open Trade Statistics (World Trade dataset) [data contributor] 29 | } 30 | 31 | } 32 | \keyword{internal} 33 | -------------------------------------------------------------------------------- /man/economiccomplexity_output.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/economiccomplexity-package.R 3 | \docType{data} 4 | \name{economiccomplexity_output} 5 | \alias{economiccomplexity_output} 6 | \title{Example Outputs of the Functions within the Package} 7 | \format{ 8 | Lists of vectors, matrices, and graphs. 9 | } 10 | \usage{ 11 | data(economiccomplexity_output) 12 | } 13 | \description{ 14 | List of different computations obtained by using the functions within the package. 15 | } 16 | \examples{ 17 | data(economiccomplexity_output) 18 | economiccomplexity_output$balassa_index 19 | economiccomplexity_output$complexity_measures$complexity_index_country 20 | } 21 | \keyword{datasets} 22 | -------------------------------------------------------------------------------- /man/productivity_levels.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/productivity_levels.R 3 | \name{productivity_levels} 4 | \alias{productivity_levels} 5 | \title{Productivity Levels} 6 | \usage{ 7 | productivity_levels( 8 | data_exp, 9 | data_gdp, 10 | country = "country", 11 | product = "product", 12 | value = "value" 13 | ) 14 | } 15 | \arguments{ 16 | \item{data_exp}{(Type: data.frame, matrix or matrix) a dataset containing 17 | countries, products and exported values.} 18 | 19 | \item{data_gdp}{(Type: data.frame, matrix or matrix) a dataset 20 | containing countries and per-capita GDP values.} 21 | 22 | \item{country}{(Type: character) the column with the countries. 23 | By default this is set to \code{"country"}. Used only if the input is a 24 | data.frame.} 25 | 26 | \item{product}{(Type: character) the column with the products. 27 | By default this is set to \code{"product"}. Used only if the input is a 28 | data.frame.} 29 | 30 | \item{value}{(Type: character) the column with the metric for 31 | country-product pairs. 32 | By default this is set to \code{"value"}. Used only if the input is a 33 | data.frame.} 34 | } 35 | \value{ 36 | A list of two named numeric vectors. 37 | } 38 | \description{ 39 | \code{productivity_levels()} computes EXPY and PRODY measures. 40 | } 41 | \details{ 42 | The current implementation follows 43 | \insertCite{exportmatters2005}{economiccomplexity} to obtain the 44 | productivity and income levels associated to exports. 45 | } 46 | \examples{ 47 | pl <- productivity_levels( 48 | world_trade_avg_1998_to_2000, 49 | world_gdp_avg_1998_to_2000 50 | ) 51 | 52 | # partial view of productivity levels 53 | n <- seq_len(5) 54 | pl$productivity_level_country[n] 55 | pl$productivity_level_product[n] 56 | 57 | } 58 | \references{ 59 | For more information on prody and its applications see: 60 | 61 | \insertRef{exportmatters2005}{economiccomplexity} 62 | } 63 | \keyword{functions} 64 | -------------------------------------------------------------------------------- /man/projections.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/projections.R 3 | \name{projections} 4 | \alias{projections} 5 | \title{Projections of a Country-Product Network} 6 | \usage{ 7 | projections( 8 | proximity_country, 9 | proximity_product, 10 | avg_links = 5, 11 | tolerance = 0.05, 12 | compute = "both" 13 | ) 14 | } 15 | \arguments{ 16 | \item{proximity_country}{(Type: matrix) the output from 17 | \code{proximity()}) or an equivalent arrangement.} 18 | 19 | \item{proximity_product}{(Type: matrix) the output from 20 | \code{proximity()}) or an equivalent arrangement.} 21 | 22 | \item{avg_links}{average number of connections for the projections. 23 | By default this is set to \code{5}.} 24 | 25 | \item{tolerance}{tolerance for proximity variation on each iteration until 26 | obtaining the desired average number of connections. 27 | By default this is set to \code{0.05}.} 28 | 29 | \item{compute}{(Type: character) the proximity to compute. By default this is 30 | \code{"both"} (both projections) but it can also be \code{"country"} 31 | or \code{"product"}.} 32 | } 33 | \value{ 34 | A list of two graphs. 35 | } 36 | \description{ 37 | \code{projections()} computes two graphs that are particularly 38 | useful to visualize product-product and country-country similarity. 39 | } 40 | \details{ 41 | The current implementation follows 42 | \insertCite{atlas2014}{economiccomplexity} to create simplified graphs 43 | that correspond to a simplification of the proximity matrices. The result is 44 | obtained by iterating and reducing links until the desired average number of 45 | links per node is obtained, or a spaning tree after the strongest links is 46 | returned when is not possible to return the desired network. 47 | } 48 | \examples{ 49 | net <- projections( 50 | economiccomplexity_output$proximity$proximity_country, 51 | economiccomplexity_output$proximity$proximity_product, 52 | avg_links = 10, 53 | tolerance = 0.1 54 | ) 55 | 56 | # partial view of projections 57 | n <- seq_len(5) 58 | igraph::E(net$network_country)[n] 59 | igraph::E(net$network_product)[n] 60 | 61 | } 62 | \references{ 63 | For more information see: 64 | 65 | \insertRef{atlas2014}{economiccomplexity} 66 | 67 | and the references therein. 68 | } 69 | \keyword{functions} 70 | -------------------------------------------------------------------------------- /man/proximity.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/proximity.R 3 | \name{proximity} 4 | \alias{proximity} 5 | \title{Proximity} 6 | \usage{ 7 | proximity(balassa_index, compute = "both") 8 | } 9 | \arguments{ 10 | \item{balassa_index}{(Type: matrix) the output from 11 | \code{balassa_index()}) or an equivalent arrangement.} 12 | 13 | \item{compute}{(Type: character) the proximity to compute. By default this is 14 | \code{"both"} (both proximity matrices) but it can also be \code{"country"} 15 | or \code{"product"}.} 16 | } 17 | \value{ 18 | A list of two matrices. 19 | } 20 | \description{ 21 | \code{proximity()} computes two matrices that account for the 22 | similarity between pairs of countries and pairs of products. 23 | } 24 | \details{ 25 | The current implementation follows 26 | \insertCite{atlas2014}{economiccomplexity} to obtain the likelihood that two 27 | products "p1" and "p2" are exported by the same country and, conversely, 28 | that two countries "c1" and "c2" export the same product. 29 | } 30 | \examples{ 31 | pro <- proximity(economiccomplexity_output$balassa_index) 32 | 33 | # partial view of proximity matrices 34 | n <- seq_len(5) 35 | pro$proximity_country[n, n] 36 | pro$proximity_product[n, n] 37 | 38 | } 39 | \references{ 40 | For more information see: 41 | 42 | \insertRef{atlas2014}{economiccomplexity} 43 | 44 | and the references therein. 45 | } 46 | \keyword{functions} 47 | -------------------------------------------------------------------------------- /man/rca.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/balassa_index.R 3 | \name{rca} 4 | \alias{rca} 5 | \title{Revealed Comparative Advantage} 6 | \usage{ 7 | rca(...) 8 | } 9 | \arguments{ 10 | \item{...}{old parameters} 11 | } 12 | \description{ 13 | \code{balassa_index()} replaces this function 14 | } 15 | -------------------------------------------------------------------------------- /man/world_gdp_avg_1998_to_2000.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/economiccomplexity-package.R 3 | \docType{data} 4 | \name{world_gdp_avg_1998_to_2000} 5 | \alias{world_gdp_avg_1998_to_2000} 6 | \title{World Trade Per-Capita GDP for the Period 1998-2000} 7 | \format{ 8 | A data frame with 240 rows and 2 columns. 9 | } 10 | \usage{ 11 | data(world_gdp_avg_1998_to_2000) 12 | } 13 | \description{ 14 | A data frame that summarizes the per-capita GDP of different countries. The unit is year 2000 USD. 15 | } 16 | \examples{ 17 | data(world_gdp_avg_1998_to_2000) 18 | head(world_gdp_avg_1998_to_2000) 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/world_trade_avg_1998_to_2000.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/economiccomplexity-package.R 3 | \docType{data} 4 | \name{world_trade_avg_1998_to_2000} 5 | \alias{world_trade_avg_1998_to_2000} 6 | \title{World Trade Averages for the Period 1998-2000} 7 | \format{ 8 | A data frame with 124,336 rows and 3 columns. 9 | } 10 | \usage{ 11 | data(world_trade_avg_1998_to_2000) 12 | } 13 | \description{ 14 | A data frame that summarizes all the products that different countries exported to the rest of the world. This data uses the SITC revision 2 classification with four digits product codes. The unit is year 2000 USD. 15 | } 16 | \examples{ 17 | data(world_trade_avg_1998_to_2000) 18 | head(world_trade_avg_1998_to_2000) 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/pkgdown/favicon/favicon-96x96.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /pkgdown/favicon/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "short_name": "", 4 | "icons": [ 5 | { 6 | "src": "/web-app-manifest-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png", 9 | "purpose": "maskable" 10 | }, 11 | { 12 | "src": "/web-app-manifest-512x512.png", 13 | "sizes": "512x512", 14 | "type": "image/png", 15 | "purpose": "maskable" 16 | } 17 | ], 18 | "theme_color": "#ffffff", 19 | "background_color": "#ffffff", 20 | "display": "standalone" 21 | } -------------------------------------------------------------------------------- /pkgdown/favicon/web-app-manifest-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/pkgdown/favicon/web-app-manifest-192x192.png -------------------------------------------------------------------------------- /pkgdown/favicon/web-app-manifest-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pachadotdev/economiccomplexity/423d5b48a958cb04dd8bda8a06ae25233487cefa/pkgdown/favicon/web-app-manifest-512x512.png -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | *.dll 4 | -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | # DARMA_OPENMP_THREADS is a natural number between 1 and the number of cores 2 | PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DARMA_OPENMP_THREADS=4 3 | PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) 4 | 5 | # Debugging 6 | 7 | # uncomment one of the following lines to enable debugging 8 | # PKG_CPPFLAGS = -UDEBUG -g 9 | # PKG_CPPFLAGS = -UDEBUG -g -I vendor/ 10 | 11 | # uncomment to disable compiler optimizations 12 | # PKG_CXXFLAGS = -Wall -O0 -pedantic 13 | -------------------------------------------------------------------------------- /src/Makevars.in: -------------------------------------------------------------------------------- 1 | # DARMA_OPENMP_THREADS is a natural number between 1 and the number of cores 2 | PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DARMA_OPENMP_THREADS=@ncores@ 3 | PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) 4 | 5 | # Debugging 6 | 7 | # uncomment one of the following lines to enable debugging 8 | # PKG_CPPFLAGS = -UDEBUG -g 9 | # PKG_CPPFLAGS = -UDEBUG -g -I vendor/ 10 | 11 | # uncomment to disable compiler optimizations 12 | # PKG_CXXFLAGS = -Wall -O0 -pedantic 13 | -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | # DARMA_OPENMP_THREADS is a natural number between 1 and the number of cores 2 | PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DARMA_OPENMP_THREADS=1 3 | PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) 4 | 5 | # Debugging 6 | 7 | # uncomment one of the following lines to enable debugging 8 | # PKG_CPPFLAGS = -UDEBUG -g 9 | # PKG_CPPFLAGS = -UDEBUG -g -I vendor/ 10 | 11 | # uncomment to disable compiler optimizations 12 | # PKG_CXXFLAGS = -Wall -O0 -pedantic 13 | -------------------------------------------------------------------------------- /src/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace arma; 5 | using namespace cpp11; 6 | 7 | /////////////////////////////////////////////////////////////////////////////// 8 | // Balassa Index 9 | /////////////////////////////////////////////////////////////////////////////// 10 | 11 | [[cpp11::register]] sexp balassa_index_(const doubles_matrix<>& trade_matrix, 12 | const bool& discrete, 13 | const double& cutoff) { 14 | Mat res = as_Mat(trade_matrix); 15 | 16 | Col row_sums = sum(res, 1); 17 | Row col_sums = sum(res, 0); 18 | double total_sum = as_scalar(sum(row_sums)); 19 | res.each_col() /= row_sums; 20 | res.each_row() /= col_sums / total_sum; 21 | 22 | if (discrete) { 23 | res.transform( 24 | [cutoff](double val) { return (val < cutoff) ? 0.0 : 1.0; }); 25 | } 26 | 27 | sexp res2 = as_cpp(as_doubles_matrix(res)); 28 | res2.attr("dimnames") = as_cpp(trade_matrix.attr("dimnames")); 29 | 30 | return res2; 31 | } 32 | 33 | /////////////////////////////////////////////////////////////////////////////// 34 | // Complexity Measures 35 | /////////////////////////////////////////////////////////////////////////////// 36 | 37 | [[cpp11::register]] list fitness_method_(const doubles_matrix<>& balassa_index, 38 | const int& iterations, 39 | const double& extremality) { 40 | Mat res = as_Mat(balassa_index); 41 | 42 | // Create empty matrices 43 | Mat kx(res.n_rows, iterations); 44 | Mat ky(res.n_cols, iterations); 45 | 46 | // Fill the first columns with 1 to start iterating 47 | kx.col(0).fill(1); 48 | ky.col(0).fill(1); 49 | 50 | // Compute cols 2 to "no. of iterations" by iterating from col 1 51 | int j; 52 | for (j = 1; j < iterations; ++j) { 53 | kx.col(j) = res * ky.col(j - 1); 54 | kx.col(j) /= mean(kx.col(j)); 55 | 56 | ky.col(j) = 57 | 1 / pow(res.t() * pow(1 / kx.col(j - 1), extremality), 1 / extremality); 58 | ky.col(j) /= mean(ky.col(j)); 59 | } 60 | 61 | writable::doubles xci = as_doubles(kx.col(iterations - 1)); 62 | writable::doubles yci = as_doubles(ky.col(iterations - 1)); 63 | 64 | // Set names for the results 65 | writable::list dimnames = as_cpp(balassa_index.attr("dimnames")); 66 | xci.attr("names") = dimnames[0]; 67 | yci.attr("names") = dimnames[1]; 68 | 69 | return writable::list({"complexity_index_country"_nm = xci, 70 | "complexity_index_product"_nm = yci}); 71 | } 72 | 73 | [[cpp11::register]] list reflections_method_( 74 | const doubles_matrix<>& balassa_index, const int& iterations) { 75 | Mat res = as_Mat(balassa_index); 76 | 77 | // Create empty matrices 78 | Mat kx(res.n_rows, iterations); 79 | Mat ky(res.n_cols, iterations); 80 | 81 | // Fill the first columns with rowSums(balassa_index) and 82 | // colSums(balassa_index) to start iterating 83 | Col row_sums = sum(res, 1); 84 | Col col_sums = sum(res, 0).t(); 85 | kx.col(0) = row_sums; 86 | ky.col(0) = col_sums; 87 | 88 | // Compute cols 2 to "no. of iterations" by iterating from col 1 89 | for (int j = 1; j < iterations; ++j) { 90 | kx.col(j) = (res * ky.col(j - 1)) / row_sums; 91 | ky.col(j) = (res.t() * kx.col(j - 1)) / col_sums; 92 | } 93 | 94 | // xci is of odd order and normalized 95 | // yci is of even order and normalized 96 | Col xci_col = 97 | (kx.col(iterations - 2) - mean(kx.col(iterations - 2))) / 98 | stddev(kx.col(iterations - 2)); 99 | Col yci_col = 100 | (ky.col(iterations - 1) - mean(ky.col(iterations - 1))) / 101 | stddev(ky.col(iterations - 1)); 102 | 103 | writable::doubles xci = as_doubles(xci_col); 104 | writable::doubles yci = as_doubles(yci_col); 105 | 106 | // Set names for the results 107 | writable::list dimnames = as_cpp(balassa_index.attr("dimnames")); 108 | xci.attr("names") = dimnames[0]; 109 | yci.attr("names") = dimnames[1]; 110 | 111 | return writable::list({"complexity_index_country"_nm = xci, 112 | "complexity_index_product"_nm = yci}); 113 | } 114 | 115 | [[cpp11::register]] list eigenvalues_method_( 116 | const doubles_matrix<>& balassa_index, const int& iterations) { 117 | Mat res = as_Mat(balassa_index); 118 | 119 | Col row_sums = sum(res, 1); 120 | Row col_sums = sum(res, 0); 121 | 122 | Mat res_row_normalized = res.each_col() / row_sums; 123 | Mat res_col_normalized = res.each_row() / col_sums; 124 | 125 | // Compute eigenvalues for xci 126 | Col eigval_xci; 127 | Mat eigvec_xci; 128 | eig_gen(eigval_xci, eigvec_xci, res_row_normalized * res_col_normalized.t()); 129 | Col xci = real(eigvec_xci.col(1)); 130 | 131 | // Compute eigenvalues for yci 132 | Col eigval_yci; 133 | Mat eigvec_yci; 134 | eig_gen(eigval_yci, eigvec_yci, res_col_normalized.t() * res_row_normalized); 135 | Col yci = real(eigvec_yci.col(1)); 136 | 137 | // Normalize xci and yci 138 | xci = (xci - mean(xci)) / stddev(xci); 139 | yci = (yci - mean(yci)) / stddev(yci); 140 | writable::doubles xci_r = as_doubles(xci); 141 | writable::doubles yci_r = as_doubles(yci); 142 | 143 | // Set names for the results 144 | writable::list dimnames = as_cpp(balassa_index.attr("dimnames")); 145 | xci_r.attr("names") = dimnames[0]; 146 | yci_r.attr("names") = dimnames[1]; 147 | 148 | return writable::list({"complexity_index_country"_nm = xci_r, 149 | "complexity_index_product"_nm = yci_r}); 150 | } 151 | 152 | /////////////////////////////////////////////////////////////////////////////// 153 | // Distance 154 | /////////////////////////////////////////////////////////////////////////////// 155 | 156 | [[cpp11::register]] sexp distance_(const doubles_matrix<>& balassa_index, 157 | const doubles_matrix<>& proximity_product) { 158 | Mat res = as_Mat(balassa_index); 159 | Mat res2 = as_Mat(proximity_product); 160 | 161 | Col row_sums = sum(res2, 1); 162 | Mat res2_normalized = res2.each_col() / row_sums; 163 | Mat distance_matrix = (1.0 - res) * res2_normalized.t(); 164 | 165 | sexp res3 = as_cpp(as_doubles_matrix(distance_matrix)); 166 | writable::list dimnames = as_cpp(balassa_index.attr("dimnames")); 167 | res3.attr("dimnames") = dimnames; 168 | 169 | return res3; 170 | } 171 | 172 | /////////////////////////////////////////////////////////////////////////////// 173 | // Proximity 174 | /////////////////////////////////////////////////////////////////////////////// 175 | 176 | [[cpp11::register]] list proximity_(const doubles_matrix<>& balassa_index, 177 | const std::string& compute) { 178 | Mat res = as_Mat(balassa_index); 179 | 180 | Col row_sums = sum(res, 1); 181 | Col col_sums = sum(res, 0).t(); 182 | 183 | Mat prox_x; 184 | Mat prox_y; 185 | 186 | // Set names for the results 187 | writable::list dimnames = as_cpp(balassa_index.attr("dimnames")); 188 | writable::list res2; 189 | 190 | if ((compute == "country") || (compute == "both")) { 191 | prox_x = res * res.t(); 192 | uword n = prox_x.n_rows; 193 | uword m = prox_x.n_cols; 194 | for (uword i = 0; i < n; ++i) { 195 | for (uword j = 0; j < m; ++j) { 196 | prox_x(i, j) /= std::max(row_sums(i), row_sums(j)); 197 | } 198 | } 199 | sexp prox_x_r = as_cpp(as_doubles_matrix(prox_x)); 200 | prox_x_r.attr("dimnames") = writable::list({dimnames[0], dimnames[0]}); 201 | res2.push_back({"proximity_country"_nm = prox_x_r}); 202 | } 203 | 204 | if ((compute == "product") || (compute == "both")) { 205 | prox_y = res.t() * res; 206 | uword n = prox_y.n_rows; 207 | uword m = prox_y.n_cols; 208 | for (uword i = 0; i < n; ++i) { 209 | for (uword j = 0; j < m; ++j) { 210 | prox_y(i, j) /= std::max(col_sums(i), col_sums(j)); 211 | } 212 | } 213 | sexp prox_y_r = as_cpp(as_doubles_matrix(prox_y)); 214 | prox_y_r.attr("dimnames") = writable::list({dimnames[1], dimnames[1]}); 215 | res2.push_back({"proximity_product"_nm = prox_y_r}); 216 | } 217 | 218 | return res2; 219 | } 220 | -------------------------------------------------------------------------------- /src/cpp11.cpp: -------------------------------------------------------------------------------- 1 | // Generated by cpp11: do not edit by hand 2 | // clang-format off 3 | 4 | 5 | #include "cpp11/declarations.hpp" 6 | #include 7 | 8 | // code.cpp 9 | sexp balassa_index_(const doubles_matrix<>& trade_matrix, const bool& discrete, const double& cutoff); 10 | extern "C" SEXP _economiccomplexity_balassa_index_(SEXP trade_matrix, SEXP discrete, SEXP cutoff) { 11 | BEGIN_CPP11 12 | return cpp11::as_sexp(balassa_index_(cpp11::as_cpp&>>(trade_matrix), cpp11::as_cpp>(discrete), cpp11::as_cpp>(cutoff))); 13 | END_CPP11 14 | } 15 | // code.cpp 16 | list fitness_method_(const doubles_matrix<>& balassa_index, const int& iterations, const double& extremality); 17 | extern "C" SEXP _economiccomplexity_fitness_method_(SEXP balassa_index, SEXP iterations, SEXP extremality) { 18 | BEGIN_CPP11 19 | return cpp11::as_sexp(fitness_method_(cpp11::as_cpp&>>(balassa_index), cpp11::as_cpp>(iterations), cpp11::as_cpp>(extremality))); 20 | END_CPP11 21 | } 22 | // code.cpp 23 | list reflections_method_(const doubles_matrix<>& balassa_index, const int& iterations); 24 | extern "C" SEXP _economiccomplexity_reflections_method_(SEXP balassa_index, SEXP iterations) { 25 | BEGIN_CPP11 26 | return cpp11::as_sexp(reflections_method_(cpp11::as_cpp&>>(balassa_index), cpp11::as_cpp>(iterations))); 27 | END_CPP11 28 | } 29 | // code.cpp 30 | list eigenvalues_method_(const doubles_matrix<>& balassa_index, const int& iterations); 31 | extern "C" SEXP _economiccomplexity_eigenvalues_method_(SEXP balassa_index, SEXP iterations) { 32 | BEGIN_CPP11 33 | return cpp11::as_sexp(eigenvalues_method_(cpp11::as_cpp&>>(balassa_index), cpp11::as_cpp>(iterations))); 34 | END_CPP11 35 | } 36 | // code.cpp 37 | sexp distance_(const doubles_matrix<>& balassa_index, const doubles_matrix<>& proximity_product); 38 | extern "C" SEXP _economiccomplexity_distance_(SEXP balassa_index, SEXP proximity_product) { 39 | BEGIN_CPP11 40 | return cpp11::as_sexp(distance_(cpp11::as_cpp&>>(balassa_index), cpp11::as_cpp&>>(proximity_product))); 41 | END_CPP11 42 | } 43 | // code.cpp 44 | list proximity_(const doubles_matrix<>& balassa_index, const std::string& compute); 45 | extern "C" SEXP _economiccomplexity_proximity_(SEXP balassa_index, SEXP compute) { 46 | BEGIN_CPP11 47 | return cpp11::as_sexp(proximity_(cpp11::as_cpp&>>(balassa_index), cpp11::as_cpp>(compute))); 48 | END_CPP11 49 | } 50 | 51 | extern "C" { 52 | static const R_CallMethodDef CallEntries[] = { 53 | {"_economiccomplexity_balassa_index_", (DL_FUNC) &_economiccomplexity_balassa_index_, 3}, 54 | {"_economiccomplexity_distance_", (DL_FUNC) &_economiccomplexity_distance_, 2}, 55 | {"_economiccomplexity_eigenvalues_method_", (DL_FUNC) &_economiccomplexity_eigenvalues_method_, 2}, 56 | {"_economiccomplexity_fitness_method_", (DL_FUNC) &_economiccomplexity_fitness_method_, 3}, 57 | {"_economiccomplexity_proximity_", (DL_FUNC) &_economiccomplexity_proximity_, 2}, 58 | {"_economiccomplexity_reflections_method_", (DL_FUNC) &_economiccomplexity_reflections_method_, 2}, 59 | {NULL, NULL, 0} 60 | }; 61 | } 62 | 63 | extern "C" attribute_visible void R_init_economiccomplexity(DllInfo* dll){ 64 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 65 | R_useDynamicSymbols(dll, FALSE); 66 | R_forceSymbols(dll, TRUE); 67 | } 68 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(economiccomplexity) 3 | 4 | test_check("economiccomplexity") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-balassa_index.R: -------------------------------------------------------------------------------- 1 | test_that("balassa_index works with a data.frame", { 2 | bi <- expect_warning(rca()) 3 | bi <- balassa_index(world_trade_avg_1998_to_2000) 4 | 5 | expect_is(bi, "matrix") 6 | expect_equal(nrow(bi), 226) 7 | expect_equal(ncol(bi), 785) 8 | expect_equal(min(bi), 0) 9 | expect_equal(max(bi), 1) 10 | }) 11 | 12 | test_that("balassa_index works with a matrix", { 13 | wt <- world_trade_avg_1998_to_2000 14 | wt$country <- as.factor(wt$country) 15 | wt$product <- as.factor(wt$product) 16 | 17 | wt <- dataframe_to_matrix(wt, country = "country", product = "product", 18 | value = "value") 19 | 20 | bi <- balassa_index(world_trade_avg_1998_to_2000) 21 | 22 | bi2 <- balassa_index(wt) 23 | 24 | expect_is(bi2, "matrix") 25 | expect_equal(bi, bi2) 26 | expect_equal(nrow(bi2), 226) 27 | expect_equal(ncol(bi2), 785) 28 | expect_equal(min(bi2), 0) 29 | expect_equal(max(bi2), 1) 30 | }) 31 | 32 | test_that("balassa_index returns error with vector data", { 33 | expect_error( 34 | balassa_index( 35 | data = seq(200, 100, 1), 36 | country = "country", 37 | product = "product", 38 | value = "export_value" 39 | ) 40 | ) 41 | }) 42 | 43 | test_that("balassa_index returns error with numeric country/product", { 44 | expect_error( 45 | balassa_index( 46 | data = world_trade_avg_1998_to_2000, 47 | country = 200, 48 | product = 100, 49 | value = "export_value" 50 | ) 51 | ) 52 | }) 53 | 54 | test_that("balassa_index returns error with character discrete", { 55 | expect_error( 56 | balassa_index( 57 | data = world_trade_avg_1998_to_2000, 58 | country = "country", 59 | product = "product", 60 | value = "export_value", 61 | discrete = "yes" 62 | ) 63 | ) 64 | }) 65 | 66 | test_that("balassa_index returns error with character cutoff", { 67 | expect_error( 68 | balassa_index( 69 | data = world_trade_avg_1998_to_2000, 70 | country = "country", 71 | product = "product", 72 | value = "export_value", 73 | cutoff = "one" 74 | ) 75 | ) 76 | }) 77 | -------------------------------------------------------------------------------- /tests/testthat/test-complexity_measures.R: -------------------------------------------------------------------------------- 1 | test_that("fitness method works in complexity_measures", { 2 | cm <- expect_warning(complexity_measures( 3 | balassa_index = economiccomplexity_output$balassa_index, 4 | method = "fitness", 5 | iterations = 3, 6 | extremality = 2 7 | )) 8 | 9 | cm <- complexity_measures( 10 | balassa_index = economiccomplexity_output$balassa_index, 11 | method = "fitness", 12 | iterations = 4, 13 | extremality = 2 14 | ) 15 | 16 | expect_is(cm, "list") 17 | expect_is(cm$complexity_index_country, "numeric") 18 | expect_is(cm$complexity_index_product, "numeric") 19 | expect_equal(length(cm$complexity_index_country), 226) 20 | expect_equal(length(cm$complexity_index_product), 785) 21 | }) 22 | 23 | test_that("reflections method works in complexity_measures", { 24 | cm <- complexity_measures( 25 | balassa_index = economiccomplexity_output$balassa_index, 26 | method = "reflections", 27 | iterations = 4 28 | ) 29 | 30 | expect_is(cm, "list") 31 | expect_is(cm$complexity_index_country, "numeric") 32 | expect_is(cm$complexity_index_product, "numeric") 33 | expect_equal(length(cm$complexity_index_country), 226) 34 | expect_equal(length(cm$complexity_index_product), 785) 35 | }) 36 | 37 | test_that("eigenvalues method works in complexity_measures", { 38 | cm <- complexity_measures( 39 | balassa_index = economiccomplexity_output$balassa_index, 40 | method = "eigenvalues", 41 | iterations = 4 42 | ) 43 | 44 | expect_is(cm, "list") 45 | expect_is(cm$complexity_index_country, "numeric") 46 | expect_is(cm$complexity_index_product, "numeric") 47 | expect_equal(length(cm$complexity_index_country), 226) 48 | expect_equal(length(cm$complexity_index_product), 785) 49 | }) 50 | 51 | test_that("complexity_measures fails with NULL balassa_index", { 52 | expect_error( 53 | complexity_measures( 54 | balassa_index = NULL 55 | ) 56 | ) 57 | }) 58 | 59 | test_that("complexity_measures fails with NULL iterations", { 60 | expect_error( 61 | complexity_measures( 62 | balassa_index = economiccomplexity_output$balassa_index, 63 | method = "fitness", 64 | iterations = NULL, 65 | extremality = 2 66 | ) 67 | ) 68 | }) 69 | 70 | test_that("complexity_measures fails with iterations < 2", { 71 | expect_error( 72 | complexity_measures( 73 | balassa_index = economiccomplexity_output$balassa_index, 74 | method = "fitness", 75 | iterations = 1, 76 | extremality = 2 77 | ) 78 | ) 79 | }) 80 | 81 | test_that("complexity_measures fails with NULL extremality", { 82 | expect_error( 83 | complexity_measures( 84 | balassa_index = economiccomplexity_output$balassa_index, 85 | method = "fitness", 86 | iterations = 4, 87 | extremality = NULL 88 | ) 89 | ) 90 | }) 91 | 92 | test_that("complexity_measures fails with NULL method", { 93 | expect_error( 94 | complexity_measures( 95 | balassa_index = economiccomplexity_output$balassa_index, 96 | method = NULL 97 | ) 98 | ) 99 | }) 100 | -------------------------------------------------------------------------------- /tests/testthat/test-complexity_outlook.R: -------------------------------------------------------------------------------- 1 | test_that("complexity_outlook works with a sparse matrix + named vector", { 2 | co <- complexity_outlook( 3 | economiccomplexity_output$balassa_index, 4 | economiccomplexity_output$proximity$proximity_product, 5 | economiccomplexity_output$complexity_measures$complexity_index_product 6 | ) 7 | 8 | expect_is(co, "list") 9 | expect_equal(length(co$complexity_outlook_index), 226) 10 | expect_equal(nrow(co$complexity_outlook_gain), 226) 11 | expect_equal(ncol(co$complexity_outlook_gain), 785) 12 | }) 13 | 14 | test_that("complexity_outlook fails with NULL data", { 15 | expect_error( 16 | complexity_outlook( 17 | NULL, 18 | economiccomplexity_output$proximity$proximity_product, 19 | economiccomplexity_output$complexity_measures$complexity_index_product 20 | ) 21 | ) 22 | 23 | expect_error( 24 | complexity_outlook( 25 | economiccomplexity_output$balassa_index, 26 | NULL, 27 | economiccomplexity_output$complexity_measures$complexity_index_product 28 | ) 29 | ) 30 | 31 | expect_error( 32 | complexity_outlook( 33 | economiccomplexity_output$balassa_index, 34 | economiccomplexity_output$proximity$proximity_product, 35 | NULL 36 | ) 37 | ) 38 | }) 39 | -------------------------------------------------------------------------------- /tests/testthat/test-productivity_levels.R: -------------------------------------------------------------------------------- 1 | test_that("productivity_levels works with data frame + data frame", { 2 | pl <- expect_warning( 3 | productivity_levels( 4 | world_trade_avg_1998_to_2000, 5 | world_gdp_avg_1998_to_2000 6 | ) 7 | ) 8 | 9 | expect_is(pl, "list") 10 | expect_equal(length(pl$productivity_level_country), 185) 11 | expect_equal(length(pl$productivity_level_product), 785) 12 | }) 13 | 14 | test_that("productivity_levels works with a data frame + named vector", { 15 | wt <- world_trade_avg_1998_to_2000 16 | wt$country <- as.factor(wt$country) 17 | wt$product <- as.factor(wt$product) 18 | 19 | wt <- dataframe_to_matrix(wt, 20 | country = "country", product = "product", 21 | value = "value" 22 | ) 23 | 24 | pl <- expect_warning( 25 | productivity_levels( 26 | world_trade_avg_1998_to_2000, 27 | world_gdp_avg_1998_to_2000 28 | ) 29 | ) 30 | 31 | pl2 <- expect_warning( 32 | productivity_levels( 33 | wt, 34 | world_gdp_avg_1998_to_2000 35 | ) 36 | ) 37 | 38 | expect_is(pl2, "list") 39 | expect_equal(pl$productivity_level_country, pl2$productivity_level_country) 40 | expect_equal(pl$productivity_level_product, pl2$productivity_level_product) 41 | expect_equal(length(pl$productivity_level_country), 185) 42 | expect_equal(length(pl$productivity_level_product), 785) 43 | }) 44 | 45 | test_that("productivity_levels fails with NULL data", { 46 | expect_error( 47 | productivity_levels( 48 | NULL, 49 | world_gdp_avg_1998_to_2000 50 | ) 51 | ) 52 | 53 | expect_error( 54 | productivity_levels( 55 | world_trade_avg_1998_to_2000, 56 | NULL 57 | ) 58 | ) 59 | }) 60 | -------------------------------------------------------------------------------- /tests/testthat/test-projections.R: -------------------------------------------------------------------------------- 1 | test_that("projection returns a simplified network with adecuate parameters", { 2 | # this intentionally simplifies very little and removes few links 3 | net <- projections( 4 | proximity_country = economiccomplexity_output$proximity$proximity_country, 5 | proximity_product = economiccomplexity_output$proximity$proximity_product, 6 | tolerance = 0.25, 7 | avg_links = 100 8 | ) 9 | 10 | expect_is(net, "list") 11 | expect_equal(length(E(net$network_country)), 2780) 12 | expect_equal(length(E(net$network_product)), 1339) 13 | }) 14 | 15 | test_that("projection returns the spanning tree with extreme parameters", { 16 | # dim(world_trade_avg_1998_to_2000) is 226 x 785 17 | # the spanning trees, by definition, shall contain 225 and 784 links each 18 | net <- expect_warning( 19 | projections( 20 | proximity_country = economiccomplexity_output$proximity$proximity_country, 21 | proximity_product = economiccomplexity_output$proximity$proximity_product, 22 | tolerance = 1, 23 | avg_links = 1 24 | ) 25 | ) 26 | 27 | expect_is(net, "list") 28 | expect_equal(length(E(net$network_country)), 225) 29 | expect_equal(length(E(net$network_product)), 784) 30 | }) 31 | 32 | test_that("projection returns country projection only", { 33 | # just spanning tree for speed 34 | net <- expect_warning( 35 | projections( 36 | proximity_country = economiccomplexity_output$proximity$proximity_country, 37 | proximity_product = economiccomplexity_output$proximity$proximity_product, 38 | tolerance = 1, 39 | avg_links = 1, 40 | compute = "country" 41 | ) 42 | ) 43 | 44 | expect_is(net, "list") 45 | expect_equal(length(E(net$network_country)), 225) 46 | expect_equal(net$network_product, NULL) 47 | }) 48 | 49 | test_that("projection returns product projection only", { 50 | # just spanning tree for speed 51 | net <- expect_warning( 52 | projections( 53 | proximity_country = economiccomplexity_output$proximity$proximity_country, 54 | proximity_product = economiccomplexity_output$proximity$proximity_product, 55 | tolerance = 1, 56 | avg_links = 1, 57 | compute = "product" 58 | ) 59 | ) 60 | 61 | expect_is(net, "list") 62 | expect_equal(net$network_country, NULL) 63 | expect_equal(length(E(net$network_product)), 784) 64 | }) 65 | 66 | test_that("projection fails with proximity_country/proximity_product", { 67 | expect_error( 68 | projections( 69 | proximity_country = NULL, 70 | proximity_product = economiccomplexity_output$proximity$proximity_product 71 | ) 72 | ) 73 | 74 | expect_error( 75 | projections( 76 | proximity_country = economiccomplexity_output$proximity$proximity_country, 77 | proximity_product = NULL 78 | ) 79 | ) 80 | }) 81 | 82 | test_that("projection fails with NULL avg_links", { 83 | expect_error( 84 | projections( 85 | proximity_country = economiccomplexity_output$proximity$proximity_country, 86 | proximity_product = economiccomplexity_output$proximity$proximity_product, 87 | avg_links = NULL 88 | ) 89 | ) 90 | }) 91 | 92 | test_that("projection fails with NULL compute ", { 93 | expect_error( 94 | projections( 95 | proximity_country = economiccomplexity_output$proximity$proximity_country, 96 | proximity_product = economiccomplexity_output$proximity$proximity_product, 97 | avg_links = 4, 98 | compute = NULL 99 | ) 100 | ) 101 | }) 102 | -------------------------------------------------------------------------------- /tests/testthat/test-proximity.R: -------------------------------------------------------------------------------- 1 | test_that("proximity results are aligned with the expected output", { 2 | pr <- proximity( 3 | balassa_index = economiccomplexity_output$balassa_index 4 | ) 5 | 6 | expect_is(pr, "list") 7 | expect_equal(nrow(pr$proximity_country), 226) 8 | expect_equal(nrow(pr$proximity_product), 785) 9 | expect_gte(min(pr$proximity_country), 0) 10 | expect_lte(max(pr$proximity_country), 1) 11 | expect_gte(min(pr$proximity_product), 0) 12 | expect_lte(max(pr$proximity_product), 1) 13 | }) 14 | 15 | test_that("proximity returns country proximity only", { 16 | pr <- proximity( 17 | balassa_index = economiccomplexity_output$balassa_index, 18 | compute = "country" 19 | ) 20 | 21 | expect_is(pr, "list") 22 | expect_equal(nrow(pr$proximity_country), 226) 23 | expect_equal(nrow(pr$proximity_product), NULL) 24 | expect_gte(min(pr$proximity_country), 0) 25 | expect_lte(max(pr$proximity_country), 1) 26 | }) 27 | 28 | test_that("proximity returns product proximity only", { 29 | pr <- proximity( 30 | balassa_index = economiccomplexity_output$balassa_index, 31 | compute = "product" 32 | ) 33 | 34 | expect_is(pr, "list") 35 | expect_equal(nrow(pr$proximity_country), NULL) 36 | expect_equal(nrow(pr$proximity_product), 785) 37 | expect_gte(min(pr$proximity_product), 0) 38 | expect_lte(max(pr$proximity_product), 1) 39 | }) 40 | 41 | test_that("proximity fails with NULL balassa_index", { 42 | expect_error( 43 | proximity( 44 | balassa_index = NULL 45 | ) 46 | ) 47 | }) 48 | 49 | test_that("proximity fails with NULL compute", { 50 | expect_error( 51 | proximity( 52 | balassa_index = economiccomplexity_output$balassa_index, 53 | compute = NULL 54 | ) 55 | ) 56 | }) 57 | --------------------------------------------------------------------------------