| Title: | International Trade Intensity, Openness and Diversification Measures |
|---|---|
| Description: | Calculates commonly used indicators for empirical international trade analysis from user-supplied data. Measures include trade openness, bilateral export and import intensity, the Herfindahl-Hirschman concentration index, normalized and entropy-based diversification, structural diversification relative to a benchmark, export similarity, trade complementarity, revealed comparative advantage, and intra-industry trade. Functions are vectorized where appropriate, validate economically meaningful inputs, and require no external data service. The definition of trade openness follows the World Bank indicator metadata <https://data.worldbank.org/indicator/NE.TRD.GNFS.ZS>. Methodological background for several trade indicators is provided by the World Bank's World Integrated Trade Solution <https://wits.worldbank.org/wits/wits/witshelp/Content/Utilities/e1.trade_indicators.htm> and the World Trade Organization (2012, ISBN:9789287038128). |
| Authors: | Chiranjit Mazumder [aut, cre], Renjini V. R. [aut] |
| Maintainer: | Chiranjit Mazumder <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-09-21 21:20:54 UTC |
| Source: | https://github.com/cran/tradeIndices |
Dependency-light functions for trade intensity, openness, concentration, diversification, similarity, complementarity, revealed comparative advantage, and intra-industry trade.
The package accepts user-supplied trade values and performs no automatic data download. See vignette("trade-indicators", package = "tradeIndices") for a worked agricultural-trade example.
Chiranjit Mazumder [email protected] and Renjini V. R.
trade_openness, trade_intensity, trade_diversification
Calculates the Grubel-Lloyd index for individual products or an aggregate weighted across products.
grubel_lloyd( exports, imports, aggregate = FALSE, scale = 100, na.rm = FALSE )grubel_lloyd( exports, imports, aggregate = FALSE, scale = 100, na.rm = FALSE )
exports |
Numeric vector of exports by product. |
imports |
Numeric vector of imports by product. |
aggregate |
Logical. If |
scale |
Positive numeric scaling factor. The default gives values from zero to 100. |
na.rm |
Logical. Should paired missing observations be removed for the aggregate index? |
The product-level index is
The aggregate form is
A numeric vector for product-level calculations or one numeric value for the aggregate index. Categories with zero exports and imports return NA_real_ at product level.
Grubel, H. G., and Lloyd, P. J. (1975). Intra-Industry Trade: The Theory and Measurement of International Trade in Differentiated Products. Macmillan. ISBN 978-0-333-17210-0.
exports <- c(rice = 40, wheat = 25, tea = 30) imports <- c(rice = 10, wheat = 20, tea = 28) grubel_lloyd(exports, imports) grubel_lloyd(exports, imports, aggregate = TRUE)exports <- c(rice = 40, wheat = 25, tea = 30) imports <- c(rice = 10, wheat = 20, tea = 28) grubel_lloyd(exports, imports) grubel_lloyd(exports, imports, aggregate = TRUE)
Calculates revealed comparative advantage as the reporter's product export share divided by the corresponding world product export share.
rca_balassa( country_product_exports, country_total_exports, world_product_exports, world_total_exports )rca_balassa( country_product_exports, country_total_exports, world_product_exports, world_total_exports )
country_product_exports |
Exports of each product by the country. |
country_total_exports |
Total exports of the country. |
world_product_exports |
World exports of each product. |
world_total_exports |
Total world exports. |
The Balassa index is
When world exports of a product are zero, the corresponding result is missing.
A numeric vector. Values greater than one indicate revealed comparative advantage.
Balassa, B. (1965). Trade liberalisation and revealed comparative advantage. The Manchester School, 33(2), 99–123. doi:10.1111/j.1467-9957.1965.tb00050.x.
rca_balassa( country_product_exports = c(40, 20, 10), country_total_exports = 100, world_product_exports = c(300, 500, 200), world_total_exports = 5000 )rca_balassa( country_product_exports = c(40, 20, 10), country_total_exports = 100, world_product_exports = c(300, 500, 200), world_total_exports = 5000 )
Calculates concentration or diversification from trade values distributed across products or trading partners.
trade_concentration( x, method = c("hhi", "normalized_hhi"), scale = 1, na.rm = FALSE ) trade_diversification( x, method = c( "one_minus_hhi", "normalized_hhi", "shannon", "effective_number" ), na.rm = FALSE )trade_concentration( x, method = c("hhi", "normalized_hhi"), scale = 1, na.rm = FALSE ) trade_diversification( x, method = c( "one_minus_hhi", "normalized_hhi", "shannon", "effective_number" ), na.rm = FALSE )
x |
Numeric vector of non-negative trade values across products or trading partners. |
method |
The concentration or diversification method. See Details. |
scale |
Positive numeric scaling factor. Use 10000 to express HHI on the conventional 0–10,000 scale. |
na.rm |
Logical. Should missing categories be removed? |
Let denote the trade share of category and the number of included categories. The HHI is . Normalized HHI is
The diversification alternatives are one minus HHI, one minus normalized HHI, normalized Shannon entropy, and the effective number of categories . The first three diversification measures lie between zero and one. Effective number lies between one and .
For comparisons across observations, use a consistent product or partner universe because the normalized measures depend on .
One numeric value. NA_real_ is returned when total trade is zero or when missing values are present and na.rm = FALSE.
World Bank (2010). Trade Indicators. https://wits.worldbank.org/wits/wits/witshelp/Content/Utilities/e1.trade_indicators.htm.
x <- c(rice = 45, wheat = 25, tea = 20, spices = 10) trade_concentration(x) trade_concentration(x, scale = 10000) trade_diversification(x) trade_diversification(x, method = "shannon") trade_diversification(x, method = "effective_number")x <- c(rice = 45, wheat = 25, tea = 20, spices = 10) trade_concentration(x) trade_concentration(x, scale = 10000) trade_diversification(x) trade_diversification(x, method = "shannon") trade_diversification(x, method = "effective_number")
Compares two product or partner compositions using shares calculated from non-negative trade values.
trade_diversification_index( country_exports, benchmark_exports, na.rm = FALSE ) export_similarity(exports_a, exports_b, scale = 100, na.rm = FALSE) trade_complementarity( country_exports, partner_imports, scale = 100, na.rm = FALSE )trade_diversification_index( country_exports, benchmark_exports, na.rm = FALSE ) export_similarity(exports_a, exports_b, scale = 100, na.rm = FALSE) trade_complementarity( country_exports, partner_imports, scale = 100, na.rm = FALSE )
country_exports |
Numeric vector of a country's exports by category. |
benchmark_exports |
Numeric vector of benchmark exports using the same categories. |
exports_a |
Numeric vector of exports for the first economy. |
exports_b |
Numeric vector of exports for the second economy. |
partner_imports |
Numeric vector of the partner's imports by category. |
scale |
Positive numeric scaling factor for similarity and complementarity. The default is 100. |
na.rm |
Logical. Should paired missing categories be removed? |
The structural trade-diversification index is
Zero indicates identical structures and one indicates no overlap. It is a dissimilarity-from-benchmark measure and should not be interpreted as an evenness measure.
Export similarity and trade complementarity use the complementary form
If both inputs are named, categories are aligned by name. If one input is named, both must be named.
One numeric value, or NA_real_ when a composition has zero total trade or contains missing values and na.rm = FALSE.
World Bank (2010). Trade Indicators. https://wits.worldbank.org/wits/wits/witshelp/Content/Utilities/e1.trade_indicators.htm.
country <- c(rice = 45, wheat = 25, tea = 20, spices = 10) world <- c(spices = 30, tea = 15, wheat = 35, rice = 20) trade_diversification_index(country, world) export_similarity(country, world) trade_complementarity(country, world)country <- c(rice = 45, wheat = 25, tea = 20, spices = 10) world <- c(spices = 30, tea = 15, wheat = 35, rice = 20) trade_diversification_index(country, world) export_similarity(country, world) trade_complementarity(country, world)
Calculates bilateral export or import intensity relative to a partner's share in world trade.
trade_intensity( bilateral_exports, reporter_exports, world_exports_to_partner, world_exports, adjustment = c("none", "exclude_reporter") ) import_intensity( bilateral_imports, reporter_imports, world_imports_from_partner, world_imports, adjustment = c("none", "exclude_reporter") )trade_intensity( bilateral_exports, reporter_exports, world_exports_to_partner, world_exports, adjustment = c("none", "exclude_reporter") ) import_intensity( bilateral_imports, reporter_imports, world_imports_from_partner, world_imports, adjustment = c("none", "exclude_reporter") )
bilateral_exports |
Exports from the reporter to the partner. |
reporter_exports |
Total exports of the reporter. |
world_exports_to_partner |
Total exports from the world to the partner. |
world_exports |
Total world exports. |
adjustment |
Either |
bilateral_imports |
Imports of the reporter from the partner. |
reporter_imports |
Total imports of the reporter. |
world_imports_from_partner |
Total imports by the world from the partner. |
world_imports |
Total world imports. |
The conventional export-intensity index is
The import-intensity index is
With adjustment = "exclude_reporter", the bilateral flow and reporter total are excluded from the reference partner and world totals, respectively.
Partner-reported imports may be used as mirror data for world exports to the partner, but differences in valuation, timing, and reporting can cause the two series to differ.
A numeric vector. A value greater than one indicates trade that is more intensive than the partner's reference share in world trade.
World Bank (2010). Trade Indicators. https://wits.worldbank.org/wits/wits/witshelp/Content/Utilities/e1.trade_indicators.htm.
World Trade Organization (2012). A Practical Guide to Trade Policy Analysis. ISBN 978-92-870-3812-8.
trade_intensity( bilateral_exports = 25, reporter_exports = 200, world_exports_to_partner = 400, world_exports = 5000 ) import_intensity( bilateral_imports = 18, reporter_imports = 160, world_imports_from_partner = 300, world_imports = 4800 )trade_intensity( bilateral_exports = 25, reporter_exports = 200, world_exports_to_partner = 400, world_exports = 5000 ) import_intensity( bilateral_imports = 18, reporter_imports = 160, world_imports_from_partner = 300, world_imports = 4800 )
Calculates exports plus imports as a share of gross domestic product.
trade_openness(exports, imports, gdp, scale = 100)trade_openness(exports, imports, gdp, scale = 100)
exports |
Numeric vector of exports. |
imports |
Numeric vector of imports. |
gdp |
Numeric vector of gross domestic product in the same monetary unit as trade. |
scale |
Positive numeric scaling factor. The default expresses the result as a percentage of GDP. |
The calculation is . Missing inputs produce missing outputs. Values are vectorized, and scalar inputs are recycled to the common input length.
A numeric vector of trade-openness values.
World Bank (2026). Trade (percentage of GDP). https://data.worldbank.org/indicator/NE.TRD.GNFS.ZS.
trade_openness( exports = c(120, 135, 150), imports = c(100, 115, 125), gdp = c(500, 540, 590) )trade_openness( exports = c(120, 135, 150), imports = c(100, 115, 125), gdp = c(500, 540, 590) )