| Type: | Package |
| Title: | International Trade Intensity, Openness and Diversification Measures |
| Version: | 0.1.0 |
| 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). |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.1.0) |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0) |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-09-11 05:38:56 UTC; majum |
| Author: | Chiranjit Mazumder [aut, cre], Renjini V. R. [aut] |
| Maintainer: | Chiranjit Mazumder <majumder.chira@icar.org.in> |
| Repository: | CRAN |
| Date/Publication: | 2026-09-21 18:00:02 UTC |
tradeIndices: International Trade Indicators
Description
Dependency-light functions for trade intensity, openness, concentration, diversification, similarity, complementarity, revealed comparative advantage, and intra-industry trade.
Details
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.
Author(s)
Chiranjit Mazumder majumder.chira@icar.org.in and Renjini V. R.
See Also
trade_openness, trade_intensity, trade_diversification
Grubel-Lloyd Intra-Industry Trade Index
Description
Calculates the Grubel-Lloyd index for individual products or an aggregate weighted across products.
Usage
grubel_lloyd(
exports,
imports,
aggregate = FALSE,
scale = 100,
na.rm = FALSE
)
Arguments
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? |
Details
The product-level index is
scale [1 - |X_k-M_k|/(X_k+M_k)].
The aggregate form is
scale [1 - \sum_k |X_k-M_k|/\sum_k(X_k+M_k)].
Value
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.
References
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.
Examples
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)
Balassa Revealed Comparative Advantage
Description
Calculates revealed comparative advantage as the reporter's product export share divided by the corresponding world product export share.
Usage
rca_balassa(
country_product_exports,
country_total_exports,
world_product_exports,
world_total_exports
)
Arguments
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. |
Details
The Balassa index is
(X_{ik}/X_i)/(X_{wk}/X_w).
When world exports of a product are zero, the corresponding result is missing.
Value
A numeric vector. Values greater than one indicate revealed comparative advantage.
References
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.
Examples
rca_balassa(
country_product_exports = c(40, 20, 10),
country_total_exports = 100,
world_product_exports = c(300, 500, 200),
world_total_exports = 5000
)
Trade Concentration and Diversification
Description
Calculates concentration or diversification from trade values distributed across products or trading partners.
Usage
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
)
Arguments
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? |
Details
Let p_k denote the trade share of category k and n the number of included categories. The HHI is \sum p_k^2. Normalized HHI is
(HHI - 1/n)/(1 - 1/n).
The diversification alternatives are one minus HHI, one minus normalized HHI, normalized Shannon entropy, and the effective number of categories \exp(-\sum p_k \log p_k). The first three diversification measures lie between zero and one. Effective number lies between one and n.
For comparisons across observations, use a consistent product or partner universe because the normalized measures depend on n.
Value
One numeric value. NA_real_ is returned when total trade is zero or when missing values are present and na.rm = FALSE.
References
World Bank (2010). Trade Indicators. https://wits.worldbank.org/wits/wits/witshelp/Content/Utilities/e1.trade_indicators.htm.
Examples
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")
Structural Trade Indices
Description
Compares two product or partner compositions using shares calculated from non-negative trade values.
Usage
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
)
Arguments
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? |
Details
The structural trade-diversification index is
0.5 \sum_k |p_{ik} - p_{bk}|.
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
scale (1 - 0.5 \sum_k |p_{1k} - p_{2k}|).
If both inputs are named, categories are aligned by name. If one input is named, both must be named.
Value
One numeric value, or NA_real_ when a composition has zero total trade or contains missing values and na.rm = FALSE.
References
World Bank (2010). Trade Indicators. https://wits.worldbank.org/wits/wits/witshelp/Content/Utilities/e1.trade_indicators.htm.
Examples
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)
Bilateral Trade Intensity
Description
Calculates bilateral export or import intensity relative to a partner's share in world trade.
Usage
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")
)
Arguments
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. |
Details
The conventional export-intensity index is
(X_{ij}/X_i)/(M_j/M_w).
The import-intensity index is
(M_{ij}/M_i)/(X_j/X_w).
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.
Value
A numeric vector. A value greater than one indicates trade that is more intensive than the partner's reference share in world trade.
References
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.
Examples
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 Openness
Description
Calculates exports plus imports as a share of gross domestic product.
Usage
trade_openness(exports, imports, gdp, scale = 100)
Arguments
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. |
Details
The calculation is scale (X + M) / GDP. Missing inputs produce missing outputs. Values are vectorized, and scalar inputs are recycled to the common input length.
Value
A numeric vector of trade-openness values.
References
World Bank (2026). Trade (percentage of GDP). https://data.worldbank.org/indicator/NE.TRD.GNFS.ZS.
Examples
trade_openness(
exports = c(120, 135, 150),
imports = c(100, 115, 125),
gdp = c(500, 540, 590)
)