| Title: | Input-Output Analysis |
|---|---|
| Description: | Provides a set of functions for input-output analysis. |
| Authors: | Mizuki Uchida [aut, cre] |
| Maintainer: | Mizuki Uchida <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-07-14 04:42:08 UTC |
| Source: | https://github.com/UchidaMizuki/econio |
Check input-output table axes
io_check_axes(data)io_check_axes(data)
data |
An input-output table. |
An econ_io_table object.
Check input-output table totals
io_check_totals(data, total_tolerance = .Machine$double.eps^0.5)io_check_totals(data, total_tolerance = .Machine$double.eps^0.5)
data |
An input-output table. |
total_tolerance |
A numeric. The tolerance for the total check. By
default, |
An econ_io_table object.
Ghosh inverse matrix
io_ghosh_inverse(data, open_economy = NULL)io_ghosh_inverse(data, open_economy = NULL)
data |
An |
open_economy |
A scalar logical. If |
An econ_io_table object of the Ghosh inverse matrix.
Calculate import coefficients for input-output tables. The calculation and interpretation differ based on the import type (competitive vs noncompetitive) and the specified axis.
io_import_coef(data, axis = c("input", "output"))io_import_coef(data, axis = c("input", "output"))
data |
An |
axis |
A scalar character. Either |
For noncompetitive import tables, imports are recorded as a separate
input row. When axis = "input", all coefficients are zero (imports are
not allocated to industries as inputs). When axis = "output", coefficients
represent the import share of regional demand: import / regional_demand
for same-region demand, zero for cross-region flows.
For competitive import tables, imports are recorded as a separate output
column. When axis = "input", coefficients represent the import share of
regional demand (negative values): -import / regional_demand for
same-region demand. When axis = "output", all coefficients are zero.
The axis parameter determines whether the coefficient varies by input industry (axis = "input") or output industry/final demand (axis = "output").
An econ_io_table object of import coefficients. The dimensions
depend on axis and the table type.
## Not run: # Noncompetitive import table io_import_coef(iotable_noncomp, axis = "input") # all zeros io_import_coef(iotable_noncomp, axis = "output") # import shares by output # Competitive import table io_import_coef(iotable_comp, axis = "input") # import shares by input io_import_coef(iotable_comp, axis = "output") # all zeros ## End(Not run)## Not run: # Noncompetitive import table io_import_coef(iotable_noncomp, axis = "input") # all zeros io_import_coef(iotable_noncomp, axis = "output") # import shares by output # Competitive import table io_import_coef(iotable_comp, axis = "input") # import shares by input io_import_coef(iotable_comp, axis = "output") # all zeros ## End(Not run)
Calculate the industry-by-industry input coefficient matrix, also known as the technical coefficient matrix or A matrix.
io_input_coef(data, open_economy = NULL)io_input_coef(data, open_economy = NULL)
data |
An |
open_economy |
A scalar logical. If |
Each element a[i, j] represents the amount of input from industry i
required to produce one unit of output from industry j. The coefficient
is calculated as the ratio of intermediate input to total input (gross
output).
For competitive import type tables, open_economy controls whether to
adjust the coefficients for import competition. When open_economy = TRUE,
the coefficients are adjusted to exclude imports: a[i, j] - m[i] * a[i, j]
where m[i] is the import coefficient for industry i in the same region.
This gives the domestic (non-import) input coefficient used in open economy
Leontief models. For noncompetitive import tables, open_economy must be
NULL as imports are already separated.
An econ_io_table object of input coefficients with dimensions
c("input", "output").
## Not run: # Noncompetitive import table io_input_coef(iotable_noncomp) # Competitive import table, closed economy io_input_coef(iotable_comp, open_economy = FALSE) # Competitive import table, open economy (domestic coefficients) io_input_coef(iotable_comp, open_economy = TRUE) ## End(Not run)## Not run: # Noncompetitive import table io_input_coef(iotable_noncomp) # Competitive import table, closed economy io_input_coef(iotable_comp, open_economy = FALSE) # Competitive import table, open economy (domestic coefficients) io_input_coef(iotable_comp, open_economy = TRUE) ## End(Not run)
Leontief inverse matrix
io_leontief_inverse(data, open_economy = NULL)io_leontief_inverse(data, open_economy = NULL)
data |
An |
open_economy |
A scalar logical. If |
An econ_io_table object of the Leontief inverse matrix.
Calculate the industry-by-industry output coefficient matrix, also known as the allocation coefficient matrix or B matrix, used in the Ghosh model.
io_output_coef(data, open_economy = NULL)io_output_coef(data, open_economy = NULL)
data |
An |
open_economy |
A scalar logical. If |
Each element b[i, j] represents the proportion of industry i's output
that is sold to industry j. The coefficient is calculated as the ratio
of intermediate output to total output (gross output).
For competitive import type tables, open_economy controls the denominator
calculation. When open_economy = TRUE, the denominator is adjusted to
total_output - (total_export - total_import) to represent domestic
production sold domestically. When open_economy = FALSE, the denominator
is simply total output. For noncompetitive import tables, open_economy
must be NULL.
An econ_io_table object of output coefficients with dimensions
c("input", "output").
## Not run: # Noncompetitive import table io_output_coef(iotable_noncomp) # Competitive import table, closed economy io_output_coef(iotable_comp, open_economy = FALSE) # Competitive import table, open economy io_output_coef(iotable_comp, open_economy = TRUE) ## End(Not run)## Not run: # Noncompetitive import table io_output_coef(iotable_noncomp) # Competitive import table, closed economy io_output_coef(iotable_comp, open_economy = FALSE) # Competitive import table, open economy io_output_coef(iotable_comp, open_economy = TRUE) ## End(Not run)
Reclassify an input-output table
io_reclass( data, input_region_data = NULL, input_sector_data = NULL, output_region_data = NULL, output_sector_data = NULL, from_col = "from", to_col = "to", weight_col = "weight", weight_tolerance = .Machine$double.eps^0.5, check_axes = TRUE )io_reclass( data, input_region_data = NULL, input_sector_data = NULL, output_region_data = NULL, output_sector_data = NULL, from_col = "from", to_col = "to", weight_col = "weight", weight_tolerance = .Machine$double.eps^0.5, check_axes = TRUE )
data |
An input-output table. |
input_region_data, input_sector_data, output_region_data, output_sector_data
|
Data frames used to reclassify the input and output regions and sectors.
If |
from_col, to_col, weight_col
|
Names of the columns in the
reclassification data. Defaults are |
weight_tolerance |
Tolerance for checking that weights sum to 1.
By default, |
check_axes |
A scalar logical. If |
A reclassified input-output table.
Get sector names
io_sector_name(x)io_sector_name(x)
x |
An |
A vector of sector names.
Get sector types
io_sector_type(x)io_sector_type(x)
x |
An |
A vector of sector types.
Methods for generics::tidy(), ggplot2::autolayer(), and
ggplot2::autoplot() that summarise an econ_io_table for visualization.
## S3 method for class 'econ_io_table' tidy(x, type, ...) ## S3 method for class 'econ_io_table' autolayer(object, type, ...) ## S3 method for class 'econ_io_table' autoplot(object, type, ...)## S3 method for class 'econ_io_table' tidy(x, type, ...) ## S3 method for class 'econ_io_table' autolayer(object, type, ...) ## S3 method for class 'econ_io_table' autoplot(object, type, ...)
x, object
|
An |
type |
A scalar character. The type of summary. Currently only
|
... |
Additional arguments passed to the underlying summary. For
|
Currently only type = "skyline" is supported, which produces a skyline
chart (a.k.a. an industry-by-industry diagram of production inducement).
For each industry the chart shows, as a stacked bar:
the width: the total production induced by final demand and exports, and
the height: the self-sufficiency rate and the import rate, expressed as a share of domestic final demand.
The skyline chart is only defined for competitive import type tables
(created with io_table_to_competitive_import() or
io_table_regional()/io_table_multiregional() with
competitive_import = TRUE).
tidy() returns the underlying data in a tidy tibble::tibble() (one row
per industry and rate type), suitable for custom plots.
autolayer() returns ggplot2 layers to add to an existing plot.
Pass geom = "rect" (default) for the skyline bars or geom = "segment"
for the self-sufficiency outline.
autoplot() returns a complete ggplot2 skyline chart.
tidy(): a tibble::tibble().
autolayer(): a list of ggplot2 layers.
autoplot(): a ggplot2::ggplot() object.
## Not run: # `iotable` is a competitive import type `econ_io_table`. library(ggplot2) # Tidy data for a custom plot. tidy(iotable, type = "skyline") # A complete skyline chart. autoplot(iotable, type = "skyline") # Or build one up from layers. ggplot() + autolayer(iotable, type = "skyline", geom = "rect") ## End(Not run)## Not run: # `iotable` is a competitive import type `econ_io_table`. library(ggplot2) # Tidy data for a custom plot. tidy(iotable, type = "skyline") # A complete skyline chart. autoplot(iotable, type = "skyline") # Or build one up from layers. ggplot() + autolayer(iotable, type = "skyline", geom = "rect") ## End(Not run)
io_spectral_embedding(data, dims = 1)io_spectral_embedding(data, dims = 1)
data |
An |
dims |
A scalar positive integer giving the number of embedding
dimensions (the number of smallest non-zero Laplacian eigenvectors to
return). By default, |
Embeds the industries of the domestic production network into a low-dimensional space by minimizing the graph Dirichlet energy
subject to h being orthonormal and orthogonal to the constant vector. The
minimizers are the eigenvectors of the symmetric graph Laplacian
associated with the smallest
non-zero eigenvalues, where u is the total weight (in plus out) of each
node. With dims = 1 this is the Fiedler vector.
Like io_trophic_level(), the table is first converted to a noncompetitive
import type table with io_table_to_noncompetitive_import() so that the
industry-by-industry block holds purely domestic intermediate transactions,
which are treated as the edge weights w[i, j].
The embedding is undirected: it uses only the symmetrized weights
W + Wt and therefore captures industry clusters but not the direction of
production. It is complementary to the directed io_trophic_level(); pairing
the two gives a map of the production network with a clustering coordinate
(this function) and a flow level (io_trophic_level()).
The sign of each eigenvector is arbitrary, so it is fixed deterministically by orienting each component to make its largest-magnitude entry positive.
A dibble. With dims = 1, one value per industry. With
dims > 1, an industry by component array.
## Not run: io_spectral_embedding(iotable) io_spectral_embedding(iotable, dims = 2) ## End(Not run)## Not run: io_spectral_embedding(iotable) io_spectral_embedding(iotable, dims = 2) ## End(Not run)
Sector-level summaries of how far each industry is from final demand (upstreamness) and from primary inputs (downstreamness), derived from the Ghosh and Leontief inverse matrices respectively.
io_upstreamness(data, open_economy = NULL, normalize = FALSE) io_downstreamness(data, open_economy = NULL, normalize = FALSE) io_streamness_length(data, open_economy = NULL, normalize = FALSE)io_upstreamness(data, open_economy = NULL, normalize = FALSE) io_downstreamness(data, open_economy = NULL, normalize = FALSE) io_streamness_length(data, open_economy = NULL, normalize = FALSE)
data |
An |
open_economy |
A scalar logical passed to |
normalize |
A scalar logical. If |
io_upstreamness() returns the row sums of the Ghosh inverse, i.e. the
total forward linkage (also called output upstreamness). A larger value
means the industry sells more of its output, directly and indirectly, to
other industries rather than to final demand.
io_downstreamness() returns the column sums of the Leontief inverse. This
is identical to the output multiplier (the simple, Type I multiplier)
and to the backward linkage (also called input downstreamness). A
larger value means a unit of final demand for the industry pulls more total
output, directly and indirectly, from the rest of the economy.
io_streamness_length() returns the sum of io_upstreamness() and
io_downstreamness(). Following Antràs and Chor (2018), this sum measures
the full length of the supply chain passing through the industry, i.e. the
total number of production stages from pure value added to final
consumption.
When normalize = TRUE the measure is rescaled so that its mean across
sectors equals 1. The normalized io_downstreamness() is the power of
dispersion (a backward-linkage index). The normalized io_upstreamness()
is the Ghosh-based forward-linkage index; note that this is not the same
as the classical sensitivity of dispersion, which is based on the row sums
of the Leontief (not Ghosh) inverse. When normalize = TRUE,
io_streamness_length() has a mean of 2 across sectors.
An econ_io_table object with one value per industry.
Antràs, P. and Chor, D. (2018). On the measurement of upstreamness and downstreamness in global value chains. NBER Working Paper No. 24185.
## Not run: # `iotable` is a competitive import type `econ_io_table`. io_upstreamness(iotable) io_downstreamness(iotable) # equals the output multiplier io_downstreamness(iotable, normalize = TRUE) # power of dispersion io_streamness_length(iotable) # total number of production stages ## End(Not run)## Not run: # `iotable` is a competitive import type `econ_io_table`. io_upstreamness(iotable) io_downstreamness(iotable) # equals the output multiplier io_downstreamness(iotable, normalize = TRUE) # power of dispersion io_streamness_length(iotable) # total number of production stages ## End(Not run)
io_streamness_position( data, open_economy = NULL, normalize = FALSE, type = c("difference", "relative", "log_ratio") )io_streamness_position( data, open_economy = NULL, normalize = FALSE, type = c("difference", "relative", "log_ratio") )
data |
An |
open_economy |
A scalar logical passed to |
normalize |
A scalar logical. If |
type |
One of |
Net position of each industry within the supply chain, derived from
io_upstreamness() (U) and io_downstreamness() (D). A positive
value indicates that the industry sits relatively further upstream
(closer to primary inputs); a negative value indicates it sits relatively
further downstream (closer to final demand).
type selects the combination:
"difference" (default): U - D.
"relative": (U - D) / (U + D), bounded in [-1, 1].
"log_ratio": log(U / D), scale-robust.
Unlike io_streamness_length(), this is not a single named index from a
specific paper; these are natural arithmetic complements to
io_upstreamness() and io_downstreamness(), provided as an experimental
convenience. The exact formulation(s) may change in future releases.
When normalize = TRUE, U and D are each rescaled to a mean of 1
before combining, so type = "difference" has a mean of 0 across
industries: a relative-position measure centered on the average.
An econ_io_table object with one value per industry.
## Not run: io_streamness_position(iotable) io_streamness_position(iotable, normalize = TRUE) # mean 0 across industries io_streamness_position(iotable, type = "relative") io_streamness_position(iotable, type = "log_ratio") ## End(Not run)## Not run: io_streamness_position(iotable) io_streamness_position(iotable, normalize = TRUE) # mean 0 across industries io_streamness_position(iotable, type = "relative") io_streamness_position(iotable, type = "log_ratio") ## End(Not run)
Create a multi-regional input-output table
io_table_multiregional( data, input_cols = c("input_region", "input_sector_type", "input_sector_name"), output_cols = c("output_region", "output_sector_type", "output_sector_name"), competitive_import = NULL, total_tolerance = .Machine$double.eps^0.5, check_axes = TRUE )io_table_multiregional( data, input_cols = c("input_region", "input_sector_type", "input_sector_name"), output_cols = c("output_region", "output_sector_type", "output_sector_name"), competitive_import = NULL, total_tolerance = .Machine$double.eps^0.5, check_axes = TRUE )
data |
A data frame. |
input_cols |
< |
output_cols |
< |
competitive_import |
A scalar logical. If |
total_tolerance |
A numeric. The tolerance for the total check. By
default, |
check_axes |
A scalar logical. If |
An econ_io_table object.
Create a regional input-output table
io_table_regional( data, input_cols = c("input_sector_type", "input_sector_name"), output_cols = c("output_sector_type", "output_sector_name"), competitive_import = NULL, total_tolerance = .Machine$double.eps^0.5, check_axes = TRUE )io_table_regional( data, input_cols = c("input_sector_type", "input_sector_name"), output_cols = c("output_sector_type", "output_sector_name"), competitive_import = NULL, total_tolerance = .Machine$double.eps^0.5, check_axes = TRUE )
data |
A data frame. |
input_cols |
< |
output_cols |
< |
competitive_import |
A scalar logical. If |
total_tolerance |
A numeric. The tolerance for the total check. By
default, |
check_axes |
A scalar logical. If |
An econ_io_table object.
Convert an input-output table to a competitive import type table
io_table_to_competitive_import( data, data_import = NULL, import_sector_name = NA_character_, import_total_tolerance = .Machine$double.eps^0.5 )io_table_to_competitive_import( data, data_import = NULL, import_sector_name = NA_character_, import_total_tolerance = .Machine$double.eps^0.5 )
data |
An input-output table. |
data_import |
An optional import table. By default, |
import_sector_name |
A name for the import sector. By default,
|
import_total_tolerance |
A numeric tolerance for checking import totals.
By default, |
A competitive import type input-output table.
Convert an input-output table to a noncompetitive import type table
io_table_to_noncompetitive_import( data, data_import = NULL, import_sector_name = NA_character_, import_total_tolerance = .Machine$double.eps^0.5 )io_table_to_noncompetitive_import( data, data_import = NULL, import_sector_name = NA_character_, import_total_tolerance = .Machine$double.eps^0.5 )
data |
An input-output table. |
data_import |
An optional import table. By default, |
import_sector_name |
A name for the import sector. By default,
|
import_total_tolerance |
A numeric tolerance for checking import totals.
By default, |
A noncompetitive import type input-output table.
Convert a multiregional input-output table to a regional input-output table
io_table_to_regional( data, export_sector_name = NA_character_, import_sector_name = NA_character_ )io_table_to_regional( data, export_sector_name = NA_character_, import_sector_name = NA_character_ )
data |
A multiregional input-output table. |
export_sector_name |
A name for the export sector. By default,
|
import_sector_name |
A name for the import sector. By default,
|
A list of regional input-output tables.
Get total input
io_total_input( data, input_sector_type = c("industry", "import", "value_added"), output_sector_type = "industry", same_region = FALSE )io_total_input( data, input_sector_type = c("industry", "import", "value_added"), output_sector_type = "industry", same_region = FALSE )
data |
An |
input_sector_type |
A character vector of input sector types. |
output_sector_type |
A character vector of output sector types. |
same_region |
A logical scalar. If |
An econ_io_table object of total input.
Get total output
io_total_output( data, input_sector_type = "industry", output_sector_type = c("industry", "final_demand", "export", "import"), same_region = FALSE )io_total_output( data, input_sector_type = "industry", output_sector_type = c("industry", "final_demand", "export", "import"), same_region = FALSE )
data |
An |
input_sector_type |
A character vector of input sector types. |
output_sector_type |
A character vector of output sector types. |
same_region |
A logical scalar. If |
An econ_io_table object of total output.
Network measures of where each industry sits in the domestic production hierarchy, following the directed-network trophic level of MacKay, Johnson and Sansom (2020).
io_trophic_level(data) io_trophic_incoherence(data)io_trophic_level(data) io_trophic_incoherence(data)
data |
An |
The table is first converted to a noncompetitive import type table with
io_table_to_noncompetitive_import() so that the industry-by-industry block
holds purely domestic intermediate transactions. These transactions are
treated as a weighted directed network w[i, j] (the flow from industry i
to industry j), and the trophic level h solves the Laplacian system
where u is the total weight (in plus out) of each node and v is its
imbalance (in minus out). The levels are shifted so that the minimum is 0.
Value-added and final-demand sectors are not nodes and do not receive a
trophic level, but they are not ignored: because the table balances, an
industry's imbalance equals (final demand + exports) - (value added + imports). Primary, value-added-heavy industries therefore receive low
trophic levels and final-demand-facing industries receive high ones (the
level increases with distance from primary inputs).
io_trophic_incoherence() returns the trophic incoherence
a scalar in [0, 1]-ish range that is 0 when the network is perfectly
coherent (every edge spans exactly one level) and larger when production
contains more cycles and feedback.
io_trophic_level(): a dibble with one trophic level per industry.
io_trophic_incoherence(): a scalar numeric.
MacKay, R. S., Johnson, S. and Sansom, B. (2020). How directed is a directed network? Royal Society Open Science, 7(9), 201138.
## Not run: io_trophic_level(iotable) io_trophic_incoherence(iotable) ## End(Not run)## Not run: io_trophic_level(iotable) io_trophic_incoherence(iotable) ## End(Not run)