Title: | Input Output Analysis |
---|---|
Description: | Calculates fundamental IO matrices (Leontief, Wassily W. (1951) <doi:10.1038/scientificamerican1051-15>); within period analysis via various rankings and coefficients (Sonis and Hewings (2006) <doi:10.1080/09535319200000013>, Blair and Miller (2009) <ISBN:978-0-521-73902-3>, Antras et al (2012) <doi:10.3386/w17819>, Hummels, Ishii, and Yi (2001) <doi:10.1016/S0022-1996(00)00093-3>); across period analysis with impact analysis (Dietzenbacher, van der Linden, and Steenge (2006) <doi:10.1080/09535319300000017>, Sonis, Hewings, and Guo (2006) <doi:10.1080/09535319600000002>); and a variety of table operators. |
Authors: | John Wade [aut, cre], Ignacio Sarmiento-Barbieri [aut] |
Maintainer: | John Wade <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.3.4 |
Built: | 2025-02-21 03:44:38 UTC |
Source: | https://github.com/cran/ioanalysis |
agg.sector
takes specified regions and creates a "new" joint region. This produces a new InputOutput
object. Note the Leontief Inverse and Ghoshian Inverse are elements. All regions must have exactly the same sectors. See locate.mismatch
.
Caution: Inverting large matrices will take a long time. R does a computation roughly every 8e-10 second. The number of computations per matrix inversion is n^3 where n is the dimension of the square matrix. For n = 5000 it should take 100 seconds.
agg.region(io, regions, newname = "newname")
agg.region(io, regions, newname = "newname")
io |
An |
regions |
Character. Specific regions to be aggregated. Can either be a character that exactly matches the name of the region in |
newname |
Character. The name to give to the new aggregated region. |
Creates an aggregation matrix similar to that of agg.sector
. See Blair and Miller 2009 for more details.
A new InputOutput
object is created. See as.inputoutput
.
John J. P. Wade, Ignacio Sarmiento-Barbieri
Blair, P.D. and Miller, R.E. (2009). "Input-Output Analysis: Foundations and Extensions". Cambridge University Press
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. "PyIO. Input-Output Analysis with Python". REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
as.inputoutput
, locate.mismatch
, agg.region
data(toy.IO) class(toy.IO) agg.region(toy.IO, regions = c(1,2), newname = "Magic")
data(toy.IO) class(toy.IO) agg.region(toy.IO, regions = c(1,2), newname = "Magic")
agg.sector
takes specified sectors and creates a "new" joint sector. This produces a new InputOutput
object. Note the Leontief Inverse and Ghoshian Inverse are elements. There is deliberately no warning if the sector does not occur in all regions. See locate.mismatch
.
Caution: Inverting large matrices will take a long time. R does a computation roughly every 8e-10 second. The number of computations per matrix inversion is n^3 where n is the dimension of the square matrix. For n = 5000 it should take 100 seconds.
agg.sector(io, sectors, newname = "newname")
agg.sector(io, sectors, newname = "newname")
io |
An |
sectors |
Character. Specific sectors to be aggregated. Can either be a character that exactly matches the name of the sector in |
newname |
Character. The name to give to the new aggregated sector. |
Creates the aggregation matrix to pre (and/or post when appropriate) to aggregate the matrices in the InputOutput
object. Say you have 1 region with n sectors and you wish to aggregate sectors i and i+1. A diagonal matrix is converted into a n-1xn matrix where rows i and i+1 are additively combined together. This matrix is then used to create new aggregated tables. The "new" sector is then stored in location i. See Blair and Miller 2009 for more details.
A new InputOutput
object is created. See as.inputoutput
.
John J. P. Wade, Ignacio Sarmiento-Barbieri
Blair, P.D. and Miller, R.E. (2009). "Input-Output Analysis: Foundations and Extensions". Cambridge University Press
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. "PyIO. Input-Output Analysis with Python". REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
as.inputoutput
, locate.mismatch
, agg.region
data(toy.IO) class(toy.IO) newIO <- agg.sector(toy.IO, sectors = c(1,2), newname = "Party.Supplies")
data(toy.IO) class(toy.IO) newIO <- agg.sector(toy.IO, sectors = c(1,2), newname = "Party.Supplies")
Creates a list of class InputOutput
for easier use of the other functions within ioanalysis
.
The Leontief inverse and Ghoshian inverse are calculated.
A little work now to save a bunch of work in the future.
For most functions in the package, this is a prerequisite.
At a minimum, Z
, X
, and RS_label
must be provided.
See Usage
for details.
Caution: Inverting large matrices will take a long time. R does a computation roughly every 8e-10 second. The number of computations per matrix inversion is n^3 where n is the dimension of the square matrix. For n = 5000 it should take 100 seconds.
as.inputoutput(Z, RS_label, f, f_label, E, E_label, X, V, V_label, M, M_label, fV, fV_label, P, P_label, A, B, L, G)
as.inputoutput(Z, RS_label, f, f_label, E, E_label, X, V, V_label, M, M_label, fV, fV_label, P, P_label, A, B, L, G)
Let n = #sectors*#regions, l = # of labels, m = arbitrary length, r = #regions
Z |
Required. A nxn matrix of intermediate transactions between sectors and regions. It should be in units of currency, kg, etc. |
RS_label |
Required. A nx2 "column" matrix of the regions in column 1 and sector in column 2. Other functions use those locations to correctly identify elements in the matices. If there is only one region, it still needs to be specified in column 1. |
f |
Not required. A nxm matrix of final demand. Exports SHOULD NOT be included in this matrix. Instead, put exports in the |
f_label |
Not required. A 2xn "row" matrix of the region and accounts to help identify the elements of |
E |
Not required. A nxr matrix of exports. Multiple columns per region is accepted. |
E_label |
Not required. A 2xn "row" matrix of the region and type of export to help identify the elements of |
X |
Required. A 1xn vector of total production for each sector across all regions. |
V |
Not required. A nxm matrix of value added. Imports SHOULD NOT be included in this matrix. Instead, put exports in the |
V_label |
Not required. A mx1 "column" matrix where the only column is the type of value added. This helps identify the rows of value added. |
M |
Not required. A mxn matrix of import. Multiple types of imports is accepted. |
M_label |
Not required. A mx1 "column" matrix to identify the rows of imports. |
fV |
Not Required. The matrix of final demand's value added |
fV_label |
Not Required. Column matrix to identify the row elements of |
P |
Not Required. The matrix of intermediate transactions in physical units |
P_label |
Not Required. A nx2 matrix to identify the regions and sectors of |
A |
Not required. A nxn matrix of technical input coefficients. If not provided, |
B |
Not required. A nxn matrix of technical output coefficients. If not provided, |
L |
Not required. The Leontief inverse. If not provided, |
G |
Not required. The Ghoshian inverse. If not provided, |
If the A
matrix is not provided, it is calculated as follows:
If the B
matrix is not provided, it is calculated as follows:
If the L
matrix is not provided, it is calculated as follows:
If the G
matrix is not provided, it is calculated as follows:
as.inputouput
retuns an object of class "InputOutput"
. Once created, it is sufficient to provide this object in all further functions in the ioanalysis
package.
Z |
Intermediate Transactions Matrix |
RS_label |
Column matrix of labels for the region and sectors used to identify elements in |
f |
Final Demand |
f_label |
Row matrix of labels for accounts for |
E |
Exports |
E_label |
Row matrix of labels for exports by sector and region for |
X |
Total Production |
V |
Value added |
V_label |
Column matrix of labels for types of value added for |
M |
Imports |
M_label |
Colum matrix of labels for type of imports for |
fV |
The matrix of final demand's value added |
fV_label |
Column matrix to identify the row elements of |
A |
Technical Input Coefficients |
B |
Technical Input Coefficients |
L |
Leontief inverse |
G |
Ghoshian inverse |
Currently, there is no use for an intermediate transaction matrix in physical units (P). If you wish to carry this with the matrix then you can create the InputOutput
object and add to it by using io$P <- P
.
John J. P. wade
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. PyIO. Input-Output Analysis with Python. REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
# In toy,FullIOTable it is a full matrix of characters: a pseudo worst case scenario data(toy.FullIOTable) Z <- matrix(as.numeric(toy.FullIOTable[3:12, 3:12]), ncol = 10) f <- matrix(as.numeric(toy.FullIOTable[3:12, c(13:15, 17:19)]), nrow = dim(Z)[1]) E <- matrix(as.numeric(toy.FullIOTable[3:12, c(16, 20)]), nrow = 10) X <- matrix(as.numeric(toy.FullIOTable[3:12, 21]), ncol = 1) V <- matrix(as.numeric(toy.FullIOTable[13:15, 3:12]), ncol = 10) M <- as.numeric(toy.FullIOTable[16, 3:12]) fV <- matrix(as.numeric(toy.FullIOTable[15:16, c(13:15,17:19)]), nrow = 2) # Note toy.FullIOTable is a matrix of characters: non-numeric toy.IO <- as.inputoutput(Z = Z, RS_label = toy.FullIOTable[3:12, 1:2], f = f, f_label = toy.FullIOTable[1:2, c(13:15, 17:19)], E = E, E_label = toy.FullIOTable[1:2, c(16, 20)], X = X, V = V, V_label = toy.FullIOTable[13:15, 2], M = M, M_label = toy.FullIOTable[16,2], fV = fV, fV_label = toy.FullIOTable[15:16, 2]) # Notice we do not need to supply the matrix of technical coefficients (A)
# In toy,FullIOTable it is a full matrix of characters: a pseudo worst case scenario data(toy.FullIOTable) Z <- matrix(as.numeric(toy.FullIOTable[3:12, 3:12]), ncol = 10) f <- matrix(as.numeric(toy.FullIOTable[3:12, c(13:15, 17:19)]), nrow = dim(Z)[1]) E <- matrix(as.numeric(toy.FullIOTable[3:12, c(16, 20)]), nrow = 10) X <- matrix(as.numeric(toy.FullIOTable[3:12, 21]), ncol = 1) V <- matrix(as.numeric(toy.FullIOTable[13:15, 3:12]), ncol = 10) M <- as.numeric(toy.FullIOTable[16, 3:12]) fV <- matrix(as.numeric(toy.FullIOTable[15:16, c(13:15,17:19)]), nrow = 2) # Note toy.FullIOTable is a matrix of characters: non-numeric toy.IO <- as.inputoutput(Z = Z, RS_label = toy.FullIOTable[3:12, 1:2], f = f, f_label = toy.FullIOTable[1:2, c(13:15, 17:19)], E = E, E_label = toy.FullIOTable[1:2, c(16, 20)], X = X, V = V, V_label = toy.FullIOTable[13:15, 2], M = M, M_label = toy.FullIOTable[16,2], fV = fV, fV_label = toy.FullIOTable[15:16, 2]) # Notice we do not need to supply the matrix of technical coefficients (A)
Produces a logical answer to the question do all regions have the same sectors.
check.RS(io)
check.RS(io)
io |
An |
Uses the RS_label
to determine if all regions have the same sectors
Produces either TRUE
or FALSE
John J. P. Wade
data(toy.IO) class(toy.IO) check.RS(toy.IO)
data(toy.IO) class(toy.IO) check.RS(toy.IO)
This is a user interface, answering prompts to significantly simplify choosing sectors and regions in large models. You can either search through the regions and sectors using keywords, partial phrases, or partial words. There is alternatively an option to select across the comprehensive list of all regions and then sectors. Once selections are made, you can view and edit the list once selections are made. Outputs a matrix to be input into other functions to help identify desired region-sector combinations.
easy.select(io)
easy.select(io)
io |
An |
easy.select
calls upon the RS_label
object in io
to sort through regions and sectors. The regions should be in the first column and sectors should be in the second.
EasySelect |
A numeric vector of class |
John J. P. Wade
Uses the matrix of technical input coefficients (A
) to calculate either the matrix of import coefficients or the matrix of export coefficients. It does require that all regions have the same sectors. This can be verified using check.RS
This function is intended to be a helper function for vs
export.coef(io, region)
export.coef(io, region)
io |
An |
region |
Integer. Specific region to be used. The number of the region in the order it appears in |
Adds appropriate blocks of the matrix of technical input coefficients to calculate the matrix of import/export coefficients. If there is an export matrix or an import matrix as a part of the InputOutput
object, the results in the generated matrix may be biased.
Produces a nxn matrix, where n is the number of sectors.
John J. P. Wade
check.RS
, locate.mismatch
, upstream
, vs
data(toy.IO) class(toy.IO) import.coef(toy.IO, 1)
data(toy.IO) class(toy.IO) import.coef(toy.IO, 1)
Uses values of the intermediate transaction matrix (Z
) and when applicable final demand (f
), and either exports (E
) or imports (M
) to calculate the total exports or imports for each region sector combination.
This function is intended to be a helper function for upstream
and vs
.
export.total(io) import.total(io)
export.total(io) import.total(io)
io |
An |
Produces a nameless vector of total exports.
John J. P. Wade
data(toy.IO) class(toy.IO) export.total(toy.IO) import.total(toy.IO)
data(toy.IO) class(toy.IO) export.total(toy.IO) import.total(toy.IO)
Computes the hypothetical extraction as outlined in Dietzenbacher et al. (1993) and as outlined in Blar and Miller (2009).
Caution: Inverting large matrices will take a long time. Each individual hypothetical extraction requires the inversion of a matrix. R does a computation roughly every 8e-10 second. The number of computations per matrix inversion is n^3 where n is the dimension of the square matrix. For n = 5000 it should take 100 seconds.
extraction(io, ES = NULL, regions = 1, sectors = 1, type = "backward.total", aggregate = FALSE, simultaneous = FALSE, normalize = FALSE)
extraction(io, ES = NULL, regions = 1, sectors = 1, type = "backward.total", aggregate = FALSE, simultaneous = FALSE, normalize = FALSE)
io |
An |
ES |
An |
regions |
Character or Integer. Specific regions to be used. Can either be a character that exactly matches the name of the region in |
sectors |
Character or Integer. Specific sectors to be used. Can either be a character that exactly matches the name of the sector in |
type |
Character. Any combination of |
aggregate |
|
simultaneous |
|
normalize |
|
type
(1) backward
- Calculates the impact of hypothetically extracting the jth region/sector using the formula
where is the matrix of technical input coefficients with the jth column replaced by zeros
(2)forward
- Calculates the impact of hypothetically extracting the jth region/sector using the formula
where is the matrix of technical output coefficients with the jth row replaced by zeros
(3) backward.total
- Calculates the impact of hypothetically extracting the jth region/sector using the formula
where is the matrix of technical input coefficients with the jth column and jth row replaced by zeros except for the diagonal element.
(4) forward.total
- Calculates the impact of hypothetically extracting the jth region/sector using the formula
where is the matrix of technical output coefficients with the jth column and jth row replaced by zeros except for the diagonal element.
aggregate
If TRUE
multiplies the impact vector by a vector of ones to received the summed value of the impact from hypothetical extraction.
normalize
If TRUE
each component in the impact vector is divided by the total output of that sector/region combination.
Produces a list over regions of a list over type of extraction. If there is only one region and one type, then a matrix is returned. For example, items can be called by using extraction$region$type
.
John J. P. Wade, Ignacio Sarmiento-Barbieri
Dietzenbacher Erik & van der Linden Jan A. & Steenge Alben E. (1993). The Regional Extraction Method: EC Input-Output Comparisons. Economic Systems Research. Vol. 5, Iss. 2, 1993
Blair, P.D. and Miller, R.E. (2009). "Input-Output Analysis: Foundations and Extensions". Cambridge University Press
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. "PyIO. Input-Output Analysis with Python". REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
as.inputoutput
, easy.select
, linkages
, key.sector
data(toy.IO) class(toy.IO) E1 <- extraction(toy.IO) # Using an EasySelect object data(toy.IO) class(toy.IO) E2 <- extraction(toy.IO, toy.ES) E2$Hogwarts # Using more options E3 <- extraction(toy.IO, regions = c(1,2), sectors = c("Wii", "Minions"), type = c("backward", "backward.total"), aggregate = TRUE) E3$Hogwarts$backward.total # Multiple regions and types E4 <- extraction(toy.IO, type = c("forward","forward.total"), normalize = TRUE) E4$Hogwarts$forward.total
data(toy.IO) class(toy.IO) E1 <- extraction(toy.IO) # Using an EasySelect object data(toy.IO) class(toy.IO) E2 <- extraction(toy.IO, toy.ES) E2$Hogwarts # Using more options E3 <- extraction(toy.IO, regions = c(1,2), sectors = c("Wii", "Minions"), type = c("backward", "backward.total"), aggregate = TRUE) E3$Hogwarts$backward.total # Multiple regions and types E4 <- extraction(toy.IO, type = c("forward","forward.total"), normalize = TRUE) E4$Hogwarts$forward.total
Calculates the field of influence. Can handle first to nth order field of influence. Uses the method as Sonis & Hewings 1992. This is a recursive technique, so computation time depends on the size of the data and order of field of influence.
NOTE: If you want to examine a % productivity shock to a specific region-sector, see inverse.important
.
f.influence(io, i , j)
f.influence(io, i , j)
io |
An |
i |
Numeric. The row component(s) of the coefficient(s) of interest |
j |
Numeric. The column component(S) of the coefficient(s) of interest |
First Order Field of Influence - This is simply the product of the jth column of the Leontief inverse multiplied by the ith row of the Leontief inverse. In matrix notation:
where denotes the field of influence, and i and j are scalars
Nth Order Field of Influence - This is a recursive function used to calculate higher order fields of influence. The order cannot exceed the size of the Intermediate Transaction Matrix (Z). I.e. if Z is 20x20, you can only calculate up to the 19th order. The formula is as follows:
where F is the field of influence, k is order of influence, l_ij is the ith row and jth column element of the Leontief Inverse and -s indicates the sth element has been removed.
Returns a matrix of the Field of Influence
John J. P. Wade, Ignacio Sarmiento-Barbieri
Sonis, Michael & Hewings, Geoffrey J.D. (1992), "Coefficient Chang in Input-Output Models: Theory and Applications," Economic Systems Research, 4:2, 143-158 (https://doi.org/10.1080/09535319200000013)
Blair, P.D. and Miller, R.E. (2009). "Input-Output Analysis: Foundations and Extensions". Cambridge University Press
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. "PyIO. Input-Output Analysis with Python". REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
data(toy.IO) class(toy.IO) # First order field of influence on L[3,2] i <- 3 j <- 2 f.influence(toy.IO, i, j) # Second order field of influence on L[3,2], L[4,5], L[6, 3], and L[1,10] i <- c(3, 4, 6, 1) j <- c(2, 5, 3, 10) f.influence(toy.IO, i, j)
data(toy.IO) class(toy.IO) # First order field of influence on L[3,2] i <- 3 j <- 2 f.influence(toy.IO, i, j) # Second order field of influence on L[3,2], L[4,5], L[6, 3], and L[1,10] i <- c(3, 4, 6, 1) j <- c(2, 5, 3, 10) f.influence(toy.IO, i, j)
Calculates the total field of influence for the input-output system using f.influence
f.influence.total(io)
f.influence.total(io)
io |
An |
The total field of influence calculates the sum of all first order field of influences:
where
such that is the jth column of the Leontief inverse and
is the ith row of the Leontief inverse.
Returns a matrix of the total field of influence.
If the input-output system is large, then the computation can become cumbersome. Consequently, a progress bar will be printed if the algorithm determines it to be relevant.
John J. P. Wade
data(toy.IO) class(toy.IO) fit = f.influence.total(toy.IO)
data(toy.IO) class(toy.IO) fit = f.influence.total(toy.IO)
Calculates the complete hierarchical feedback loop as described in Sonis et al. (1995). A feed back loop is complete if it contains all region-sector pairs. Much like a sudoku puzzle, there may only be one identified cell in each row and one identified cell in each column per loop. The loops are hierarchical in the sense that first loop maximizes the intermediate transactions given the aforementioned constraints.
There are TWO functions for RAM concerns. A singular function storing all feedback loop matrices grows at rate n^3. Alternatively, constructing feedback loop matrices one at a time translates to the output of feedback.loop
growth rate of roughly 2n^2.
Note: A feedback loop solves the Linear Programming Assignment problem.
Warning: Computation time depends on size of the system. A progress bar is printed.
feedback.loop(io, agg.sectors, agg.regions, n.loops) feedback.loop.matrix(fl, loop)
feedback.loop(io, agg.sectors, agg.regions, n.loops) feedback.loop.matrix(fl, loop)
io |
An object of class |
agg.sectors |
An option to aggregate the sectors to compare regions only. Default is |
agg.regions |
An option to aggregate the regions to compare sectors only. Default is |
n.loops |
The number of loops you wish to calculate. The default is |
fl |
An object of class |
loop |
The loop from which you want the selector matrix. |
The feedback loop solves the following optimization problem:
such that:
where is the intermediate transaction matrix from
io
, is a selctor matrix of the cells in
,
is a constraint matrix to ensure only one cell per column is selected,
is a constraint matrix to ensure only one cell per row is selected, and constraint
ensures the values in the selector matrix are either one or zero.
After each loop, the selected cells are set to an extremely negative number to prevent selection in the next loop.
See the documentation on http://www.real.illinois.edu/ for more details and interpretation of the loops.
Produces a nested list: fl
fl |
Contains |
value |
Contains a vector of the total value of intermediate transactions for each loop. |
loop_i |
Contains a list over each loop's subloops. Retrieve by calling |
John J. P. Wade, Xiuli Liu
Sonis, M., Hewings, G. J., & Gazel, R (1995). The structure of multi-regional trade flows: hierarchy, feedbacks and spatial linkages. The Annals of Regional Science, 29(4) 409-430.
########################## # The base feedback loop # ########################## data(toy.IO) class(toy.IO) fbl = feedback.loop(toy.IO) fbl$loop_1 fl_3 = feedback.loop.matrix(fbl, 3) heatmap.io(fl_3, RS_label = toy.IO$RS_label) fbl$value fbl$per = fbl$value / sum(fbl$value) * 100 obj = data.frame(x = 1:length(fbl$per), y = fbl$per) ggplot(obj, aes(x = x, y = y)) + geom_line() + geom_point() + labs(x = 'Loop', y = 'Percent', title = 'Proportion of Total Intermediate Transactions per Loop') ############################### # An aggregated feedback loop # ############################### fbl_agg = feedback.loop(toy.IO, agg.regions = TRUE) io_agg = agg.region(toy.IO, regions = 'all', newname = 'magic') fl_agg_1 = feedback.loop.matrix(fbl_agg, loop = 1) heatmap.io(fl_agg_1, RS_label = io_agg$RS_label)
########################## # The base feedback loop # ########################## data(toy.IO) class(toy.IO) fbl = feedback.loop(toy.IO) fbl$loop_1 fl_3 = feedback.loop.matrix(fbl, 3) heatmap.io(fl_3, RS_label = toy.IO$RS_label) fbl$value fbl$per = fbl$value / sum(fbl$value) * 100 obj = data.frame(x = 1:length(fbl$per), y = fbl$per) ggplot(obj, aes(x = x, y = y)) + geom_line() + geom_point() + labs(x = 'Loop', y = 'Percent', title = 'Proportion of Total Intermediate Transactions per Loop') ############################### # An aggregated feedback loop # ############################### fbl_agg = feedback.loop(toy.IO, agg.regions = TRUE) io_agg = agg.region(toy.IO, regions = 'all', newname = 'magic') fl_agg_1 = feedback.loop.matrix(fbl_agg, loop = 1) heatmap.io(fl_agg_1, RS_label = io_agg$RS_label)
Computes the Ghoshian (ouput) inverse. ghosh.inv
has inputs to invert a subset of all regions if desired. If not using an InputOutput
object from as.inputoutput
, the functionality is limited. See example for more details.
Caution: Inverting large matrices will take a long time. R does a computation roughly every 8e-10 second. The number of computations per matrix inversion is n^3 where n is the dimension of the square matrix. For n = 5000 it should take 100 seconds.
ghosh.inv(Z = NULL, X, B, RS_label, regions)
ghosh.inv(Z = NULL, X, B, RS_label, regions)
Z |
Either an object class of |
X |
Vector. Total production vector. Not required if Z is an object with |
B |
Matrix. Matrix of technical output coefficients. |
RS_label |
Matrix. A nx2 column matrix of labels for regions and sectors. The first column must be regions and the second column must be sectors. This is used to match with the intermediate transaction matrix. |
regions |
Character or Integer. Specific regions to be used. Can either be a character that exactly matches the name of the region in |
The Ghoshian inverse is derived from the input-output table A=[a_ij] where
where z_ij is the input from i required in the production of j. X_i is the corresponding input in each row. The Leontief inverse is then computed as
Observe we result with the following system
Therefore, the element is interpreted as the ratio of sector i's value added contributing to the total production of sector j.
Returns a matrix with the Ghoshian Inverse
Ignacio Sarmiento-Barbieri, John J. P. Wade
Ghosh, A. (1958). "Input-output Approach in an Allocation System," Econometrica, New Series, Vol. 25, No. 97 (Feb., 1958), pp. 58-64.
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. PyIO. Input-Output Analysis with Python. REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
# Using an "InputOutput" object data(toy.IO) class(toy.IO) G1 <- ghosh.inv(toy.IO, region = "Narnia") # Otherwise Z <- toy.IO$Z X <- toy.IO$X G3 <- ghosh.inv(Z, X)
# Using an "InputOutput" object data(toy.IO) class(toy.IO) G1 <- ghosh.inv(toy.IO, region = "Narnia") # Otherwise Z <- toy.IO$Z X <- toy.IO$X G3 <- ghosh.inv(Z, X)
A visualization tool for matrices belonging to an input-output system.
heatmap.io(obj, RS_label = NULL, regions_x = 'all', sectors_x = 'all', regions_y = 'all', sectors_y = 'all', ES_x = NULL, ES_y = NULL, FUN = NULL, low = NULL, high = NULL, min = NA, max = NA)
heatmap.io(obj, RS_label = NULL, regions_x = 'all', sectors_x = 'all', regions_y = 'all', sectors_y = 'all', ES_x = NULL, ES_y = NULL, FUN = NULL, low = NULL, high = NULL, min = NA, max = NA)
obj |
The object you wish to create a heat map for that corresponds to the RS_label |
RS_label |
The RS_label located in an |
regions_x |
The regions you wish to plot on the x-axis. This can either be the numerical order the regions occur or the name of the regions. The default is |
sectors_x |
The sectors you wish to plot on the x-axis. This can either be the numerical order the sectors occur or the name of the sectors. The default is |
regions_y |
The regions you wish to plot on the y-axis. This can either be the numerical order the regions occur or the name of the regions. The default is |
sectors_y |
The sectors you wish to plot on the y-axis. This can either be the numerical order the sectors occur or the name of the sectors. The default is |
ES_x |
Instead of specifying regions and sectors individually, you can use an |
ES_y |
See ES_x |
FUN |
The transformation of the elements in |
low |
The color of the low values. Default is |
high |
The color of the high values. Default is |
min |
The minimum value for the color legend. Default of NA == min(obj). Both min and max must be provided to change default. |
max |
The maximum value for the color legend. Default of NA == max(obj). Both min and max must be provided to change default. |
heatmap.io
uses ggplot2::geom_tiles() to create the visualization of the object.
The coloring follows the temperatures of stars!
John J. P. Wade
data(toy.IO) class(toy.IO) RS_label = toy.IO$RS_label obj = toy.IO$L heatmap.io(obj, RS_label, FUN = log, max = 3) cuberoot = function(x){x^(1/3)} heatmap.io(obj, RS_label, FUN = cuberoot) # Total field of influence fit = f.influence.total(toy.IO) heatmap.io(fit, RS_label, sectors_x = c(1,3,4,5), regions_y = c(2), sectors = 1:3) data(toy.ES) ES2 = matrix(c(1,5,6,8,9)) class(ES2) = 'EasySelect' heatmap.io(fit, RS_label, ES_x = toy.ES, ES_y = ES2, low = '#00fcef', high = 'blueviolet')
data(toy.IO) class(toy.IO) RS_label = toy.IO$RS_label obj = toy.IO$L heatmap.io(obj, RS_label, FUN = log, max = 3) cuberoot = function(x){x^(1/3)} heatmap.io(obj, RS_label, FUN = cuberoot) # Total field of influence fit = f.influence.total(toy.IO) heatmap.io(fit, RS_label, sectors_x = c(1,3,4,5), regions_y = c(2), sectors = 1:3) data(toy.ES) ES2 = matrix(c(1,5,6,8,9)) class(ES2) = 'EasySelect' heatmap.io(fit, RS_label, ES_x = toy.ES, ES_y = ES2, low = '#00fcef', high = 'blueviolet')
Produces a three dimensional histogram from plot3d
hist3d.io(obj, alpha = 1, phi = 65, theta = 45, limits, colors = ramp.col(c('yellow', 'violet', 'blue')))
hist3d.io(obj, alpha = 1, phi = 65, theta = 45, limits, colors = ramp.col(c('yellow', 'violet', 'blue')))
obj |
The nxm matrix to be plotted |
alpha |
The transparency of bars where 1 is opaque and 0 is complete transparency. Default is 1 |
phi |
Colatitude rotation (shaking head left and right) |
theta |
Colatitude rotation (nodding up and down) |
limits |
The lower and upper bound for color limits |
colors |
A |
Uses hist3D
from the package plot3d
to generate a 3D plot
data(toy.IO) obj = toy.IO$Z[1:5, 1:5] hist3d.io(obj, alpha = 0.7)
data(toy.IO) obj = toy.IO$Z[1:5, 1:5] hist3d.io(obj, alpha = 0.7)
Calculates the inverse-important coefficients as in Blair and Miller (2009)
inverse.important(io, i, j, delta.aij)
inverse.important(io, i, j, delta.aij)
io |
An |
i |
Integer. The row component of the change in the matrix of technical input coefficients |
j |
Integer. The column component of the change in the matrix of technical input coefficients |
delta.aij |
Integer. By how much aij should change by |
The inverse-important coefficients is the change in the Leontief matrix due to a specified change in one element of the matrix of technical input coefficients (A). This uses the formula:
where F_1(X,Y) is the first order field of influence.
Returns the change in the Leontief matrix due the change in one element of the matrix of technical input coefficients. To find the new Leontief inverse induced by this change, use io$L + inverse.important().
John J. P. Wade, Ignacio Sarmiento-Barbieri
Blair, P.D. and Miller, R.E. (2009). "Input-Output Analysis: Foundations and Extensions". Cambridge University Press
data(toy.IO) class(toy.IO) i <- 3 j <- 4 delta.aij <- 0.5 II <- inverse.important(toy.IO, i, j, delta.aij)
data(toy.IO) class(toy.IO) i <- 3 j <- 4 delta.aij <- 0.5 II <- inverse.important(toy.IO, i, j, delta.aij)
A collection of input-output table analytical functions used to analyze InputOutput
objects. See as.inputoutput
for details.
For a list of available functions, see help(package = "ioanalysis")
John J. P. Wade
For detailed documentation and .R files see https://github.com/joolman/ioanalysis
Uses backward and forward linkages
to identify key sectors in the system. Can calculate total and direct linkages. If the data is multiregional, intraregional and interregional linkages can be calculated. Can also be used on a specified subset of all regions.
key.sector(io, ES = NULL, crit = 1, regions = "all", sectors = "all", type = c("direct"), intra.inter = FALSE)
key.sector(io, ES = NULL, crit = 1, regions = "all", sectors = "all", type = c("direct"), intra.inter = FALSE)
io |
An object of class |
ES |
An object of class |
crit |
Integer. The value to compare linkages above or below to classify sectors. Default is 1. |
regions |
Character or Integer. Specific regions to be used. Can either be a character that exactly matches the name of the region in |
sectors |
Character or Integer. Specific sectors to be used. Can either be a character that exactly matches the name of the sector in |
type |
Character. Identifying the type of backward and forward linkages to be calculated. Options are |
intra.inter |
Logical. Only applies to multiregional systems. Determines whether or not to calculate intraregional and interregional backward and forward linkages in addition to aggregate linkages. |
Uses the (various) specified backward and forward linkages
to calculate a key to identify dependence using the specified critical value.
I
BL < crit, FL < crit - Generally independent
II
BL < crit, FL > crit - Dependent on interindustry demand
III
BL > crit, FL > crit - Generally dependent
IV
BL > crit, FL < crit - Dependent on interindustry supply
If there is only one region, key sector binds to the output from linkages
to make a table. Otherwise, it produces a list of key sector codes for each country using the names of regions provided. See Examples for more details.
John J. P. Wade, Ignacio Sarmiento-Barbieri
Blair, P.D. and Miller, R.E. (2009). "Input-Output Analysis: Foundations and Extensions". Cambridge University Press
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. "PyIO. Input-Output Analysis with Python". REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
data(toy.IO) class(toy.IO) key1 <- key.sector(toy.IO) key1$Narnia # A more detailed example # Using critical value of 2 because this is randomly generated data and better # illustrates functionality key2 <- key.sector(toy.IO, intra.inter = TRUE, type = c("direct"), crit = 2) key2 key3 <- key.sector(toy.IO, regions = c(1:2), sectors = c(1:3,5)) key3
data(toy.IO) class(toy.IO) key1 <- key.sector(toy.IO) key1$Narnia # A more detailed example # Using critical value of 2 because this is randomly generated data and better # illustrates functionality key2 <- key.sector(toy.IO, intra.inter = TRUE, type = c("direct"), crit = 2) key2 key3 <- key.sector(toy.IO, regions = c(1:2), sectors = c(1:3,5)) key3
Computes the Leontief (input) inverse. leontief.inv
has inputs to invert a subset of all regions if desired. If not using an InputOutput
object from as.inputoutput
, the functionality is limited. See example for more details.
Note: if you have a non InputOutput
object and you wish to use only a subset of all regions, you must supply the intermediate transaction matrix (Z
) and total production matrix (X
). Otherwise use L <- Z %*% diag(c(1/X))
Caution: Inverting large matrices will take a long time. R does a computation roughly every 8e-10 second. The number of computations per matrix inversion is n^3 where n is the dimension of the square matrix. For n = 5000 it should take 100 seconds.
leontief.inv(Z = NULL, X, A, RS_label, regions)
leontief.inv(Z = NULL, X, A, RS_label, regions)
Z |
Either an object class of |
X |
vector. Total production vector. Not required if Z is an object with |
A |
Matrix. Technical Matrix of Input Coefficients. If provided and the data is large, the computations will be noticeably sped up. |
RS_label |
Matrix. A nx2 column matrix of labels for regions and sectors. The first column must be regions and the second column must be sectors. This is used to match with the intermediate transaction matrix. |
regions |
Character or Integer. Specific regions to be used. Can either be a character that exactly matches the name of the region in |
The Leontief inverse is derived from the input-output table A=[a_ij] where
where z_ij is the input from i required in the production of j. X_j is the corresponding input in each column. The Leontief inverse is then computed as
Observe we result with the following system
Therefore, element is interpreted as the ratio of final demand for sector j contributing to the total production in sector i.
Returns a matrix with the Leontief Inverse.
Ignacio Sarmiento-Barbieri, John J. P. Wade
Leontief, Wassily W. (1951). "Input-Output Economics." Scientific American, Vol. 185, No. 4 (October 1951), pp. 15-21.
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. PyIO. Input-Output Analysis with Python. REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
# Using an "InputOutput" object data(toy.IO) class(toy.IO) L1 <- leontief.inv(toy.IO, region = "Narnia") # Otherwise Z <- toy.IO$Z X <- toy.IO$X L2 <- leontief.inv(Z, X)
# Using an "InputOutput" object data(toy.IO) class(toy.IO) L1 <- leontief.inv(toy.IO, region = "Narnia") # Otherwise Z <- toy.IO$Z X <- toy.IO$X L2 <- leontief.inv(Z, X)
Calculates backward and forward linkages with an option to normalize values. Can calculate total and direct linkages. If the data is multiregional, intraregional and interregional linkages can be calculated. Can also be used on a specified subset of all regions.
linkages(io, ES = NULL, regions = "all", sectors = "all", type = c("total"), normalize = FALSE, intra.inter = FALSE)
linkages(io, ES = NULL, regions = "all", sectors = "all", type = c("total"), normalize = FALSE, intra.inter = FALSE)
io |
An object of class |
ES |
An object of class |
regions |
Character or Integer. Specific regions to be used. Can either be a character that exactly matches the name of the region in |
sectors |
Character or Integer. Specific sectors to be used. Can either be a character that exactly matches the name of the sector in |
type |
Character. Identifying the type of backward and forward linkages to be calculated. Options are |
normalize |
Logical. Identifying whether or not to calculate normalized or raw linkages. Default is |
intra.inter |
Logical. Only applies to multiregional systems. Determines whether or not to calculate intraregional and interregional backward and forward linkages in addition to aggregate linkages. |
There are arguments for type
of linkages, normalized
linkages, and intra.inter
linkages. Let (r) denote the dimension of the block in the transaction matrix of the region of interest and (s) denote the dimension of the rest. If there are (n) sectors and (m) regions then r = n and s = (m - 1)*s
type
: For the following types, if normalize = TRUE
then the calculation takes the specified form below. Otherwise if normalize = FALSE
then the denominator is removed:
"total"
caclculates the total backward and forward linkages. For backward linkages, this is the column sum of the Leontief inverse.
For forward linkages, this is the row sum of the Goshian inverse.
"direct"
calculates the direct backward and forward linkages. For backward linkages, this is the column sum of the input matrix of technical coefficients (A):
For forward linkages, this is the row sum of the output matrix of technical coefficients (B):
intra.inter
: This calculates the intraregional, interregional and aggregate backward and forward linkages. If intra.inter = FALSE
, then only calculates the aggregate. If normalize = FALSE
then the aggregate linkage is equivalent to the sum of the intraregional and interregional linkages. If normalize = TRUE
, then this is not the case. Note that normalizing adds the denominator to the following equations. Using matrix notation we have
Returns a data.frame
. The following are assigned to the column names to help identify which column is belongs to which. The first element of the column label is the region of interest, grabbed from RS_label
.
.BL |
Backward linkages |
.FL |
Forward linkages |
.intra |
Intraregional linkages |
.inter |
Interregional linkages |
.agg |
Aggregate linkages |
.tot |
Total linkages |
.dir |
Direct linkages |
John J. P. Wade, Ignacio Sarmiento-Barbieri
Blair, P.D. and Miller, R.E. (2009). "Input-Output Analysis: Foundations and Extensions". Cambridge University Press
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. "PyIO. Input-Output Analysis with Python". REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
leontief.inv
, ghosh.inv
, key.sector
data(toy.IO) class(toy.IO) link1 <- linkages(toy.IO) link1$Hogwarts data(toy.ES) class(toy.ES) link2 <- linkages(toy.IO, toy.ES) link2 # More detailed link3 <- linkages(toy.IO, regions = "Narnia", sectors = c("Wii","Pizza"), type = c("total", "direct"), normalize = FALSE, intra.inter = TRUE) link3 link4 <- linkages(toy.IO, regions = 1:2, sectors = c(1:3,5)) link4
data(toy.IO) class(toy.IO) link1 <- linkages(toy.IO) link1$Hogwarts data(toy.ES) class(toy.ES) link2 <- linkages(toy.IO, toy.ES) link2 # More detailed link3 <- linkages(toy.IO, regions = "Narnia", sectors = c("Wii","Pizza"), type = c("total", "direct"), normalize = FALSE, intra.inter = TRUE) link3 link4 <- linkages(toy.IO, regions = 1:2, sectors = c(1:3,5)) link4
locate.mismatch
finds which sectors are not found in all regions. If a sector is not in all regions a report is generated to indicate which regions have that sector, which regions don't have that sector, and where this sector is in the repository.
locate.mismatch(io)
locate.mismatch(io)
io |
An object of class |
locate.mismatch
begins by identifying all sectors. Then if a sector is not in every region, the function identifies which regions have the sector, which regions don't have the sector, and where this sector is located. If it is important to have all regions having the same sectors, the location output can be used in agg.sector
. For a full list of sectors, use easy.select
.
Produces a list of sectors. Each sector has a list of location
, regionswith
, and regionswithout
. For example to find the regions that have a mismatched sector, use
(mismatch.object)$sector$regionswith
John J. P. Wade
as.inputoutput
, agg.sector
, easy.select
data(toy.IO) class(toy.IO) # No mismatches MM1 <- locate.mismatch(toy.IO) # Making toy.IO have mismatches toy.IO$RS_label <- rbind(toy.IO$RS_label, c("Valhalla", "Wii"), c("Valhalla", "Pizza"), c("Valhalla", "Pizza"), c("Valhalla", "Minions")) MM2 <- locate.mismatch(toy.IO) MM2$Lightsabers
data(toy.IO) class(toy.IO) # No mismatches MM1 <- locate.mismatch(toy.IO) # Making toy.IO have mismatches toy.IO$RS_label <- rbind(toy.IO$RS_label, c("Valhalla", "Wii"), c("Valhalla", "Pizza"), c("Valhalla", "Pizza"), c("Valhalla", "Minions")) MM2 <- locate.mismatch(toy.IO) MM2$Lightsabers
Uses simple linear quotient technique to update the matrix of technical input coefficients (A
)
lq(io)
lq(io)
io |
An |
Uses the simple linear quotient technique as follows:
where is the total production,
is the total production for region r,
is the production for region r sector i, and
is the total production for the ith sector.
Then lq is converted such that if , then
. Then lq is converted into a diagonal matrix of values less than or equal to 1, which gives us our final results
Produces the forecast of the matrix of technical input coefficients (A
) using the Slq technique.
John J. P. Wade
Blair, P.D. and Miller, R.E. (2009). "Input-Output Analysis: Foundations and Extensions". Cambridge University Press
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. "PyIO. Input-Output Analysis with Python". REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
data(toy.IO) class(toy.IO) Anew <- lq(toy.IO)
data(toy.IO) class(toy.IO) Anew <- lq(toy.IO)
mpm
calculates the multiplier product matrix using an InputOutput
object calculated from as.inputoutput
. The method is described below.
mpm(io)
mpm(io)
io |
An |
Let be the Leontief inverse. Then the multiplier product matrix
is calculated as follows:
where such that
is a column matrix of ones,
is a column matrix of row sums, and
is a row matrix of column sums.
M |
Multiplier Product Matrix |
John J. P. Wade
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. "PyIO. Input-Output Analysis with Python". REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
data(toy.IO) class(toy.IO) M <- mpm(toy.IO)
data(toy.IO) class(toy.IO) M <- mpm(toy.IO)
multipliers
is currently able to calculate four different multipliers: output
, input
, income
, and employment
. See details for formulas.
multipliers(io, ES, regions = "all", sectors = "all", multipliers, wage.row, employ.closed.row, employ.physical.row)
multipliers(io, ES, regions = "all", sectors = "all", multipliers, wage.row, employ.closed.row, employ.physical.row)
io |
An |
ES |
An |
regions |
Character or Integer. Specific regions to be used. Can either be a character that exactly matches the name of the region in |
sectors |
Character or Integer. Specific sectors to be used. Can either be a character that exactly matches the name of the sector in |
multipliers |
Character. Any combination of the following: |
wage.row |
Integer. The row(s) in Value Added where wages is stored. See |
employ.closed.row |
Integer. The row(s) in the intermediate transaction matrix ( |
employ.physical.row |
character or Integer. The row(s) in the phtsical matrix ( |
There are four different multipliers able to be calculated:
(1) output
- Output multipliers are calculated as the sum over rows from the Leontief matrix:
where is the ith row and jth column element of the Leontief matrix.
(2)input
- Input multipliers are calculated as the sum over columns from the Ghoshian matrix:
where is the ith row and jth column element of the Ghoshian matrix
(3) wage
- Income multipliers are calculated using value add due to employee compensation or wages. Multiple types of wages are supported. Wages are standardized and multiplied by the Leontief matrix:
where is the wage divided by the total production for that region-sector combination, and
is the ith row and jth column element of the Leontief matrix.
(4) employment
- Employment multipliers are calculated using the employment row in the matrix of technical input coefficients (A
):
where is the row(s) corresponding to labor at the ith column, and
is the ith row and jth column element of the Leontief matrix.
Produces a list over regions of multilpliers.
John J. P. Wade, Ignacio Sarmiento-Barbieri
Blair, P.D. and Miller, R.E. (2009). "Input-Output Analysis: Foundations and Extensions". Cambridge University Press
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. "PyIO. Input-Output Analysis with Python". REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
as.inputoutput
, key.sector
, linkages
, output.decomposition
data(toy.IO) class(toy.IO) M1 <- multipliers(toy.IO, multipliers = "wage", wage.row = 1) M2 <- multipliers(toy.IO, multipliers = "employment.closed", employ.closed.row = "Minions") data(toy.ES) class(toy.ES) M3 <- multipliers(toy.IO, toy.ES, multipliers = c("input", "output"))
data(toy.IO) class(toy.IO) M1 <- multipliers(toy.IO, multipliers = "wage", wage.row = 1) M2 <- multipliers(toy.IO, multipliers = "employment.closed", employ.closed.row = "Minions") data(toy.ES) class(toy.ES) M3 <- multipliers(toy.IO, toy.ES, multipliers = c("input", "output"))
Performs decomposition of output changes given two periods of data. You can decompose by origin over internal, external, or total and you can additionally decompose by changes due to final demand, technical change, or total. This follows the technique of Sonis et al (1996).
output.decomposition(io1, io2, origin = "all", cause = "all")
output.decomposition(io1, io2, origin = "all", cause = "all")
io1 |
The first period |
io2 |
An |
origin |
Character. Choosing to decompose changes to the sectors due to |
cause |
Character. Choosing to decompose changes to the sectors due to changes in |
A superscript of indicates changes due to final demand,
indicates changes due to the Leontief inverse, and no superscript indicates total. A subscript of
indicates changes in output originating internally of the sectors,
indicates externally, and no subscript indicates total.
is the Leontief inverse and
is aggregated final demand. Analysis is over changes from period 1 to period 2. The values are calculated as follows:
Originating: Total
Originating: Internal
Originating: External
The function always outputs a named row of some variant of delta.X
. A prefix indicates the changes origin where total is blank. A suffix indicates the cause of the change where total is also blank.
int |
A prefix for internal |
ext |
A prefix for external |
f |
A suffix for final demand |
L |
A suffix for technical or Leontief |
John J. P. Wade, Ignacio Sarmiento-Barbieri
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. PyIO. Input-Output Analysis with Python. REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
Sonis, Michael & Geoffrey JD Hewings, & Jiemin Guo. Sources of structural change in input-output systems: a field of influence approach. Economic Systems Research 8, no. 1 (1996): 15-32.
data(toy.IO) data(toy.IO2) class(toy.IO) class(toy.IO) == class(toy.IO2) OD1 <- output.decomposition(toy.IO, toy.IO2) OD1$Hogwarts OD2 <- output.decomposition(toy.IO, toy.IO2, origin = "external", cause = c("finaldemand","leontief")) OD2
data(toy.IO) data(toy.IO2) class(toy.IO) class(toy.IO) == class(toy.IO2) OD1 <- output.decomposition(toy.IO, toy.IO2) OD1$Hogwarts OD2 <- output.decomposition(toy.IO, toy.IO2, origin = "external", cause = c("finaldemand","leontief")) OD2
Uses the ras technique to update the matrix of technical input coefficients A
. You must have knowledge of or forecasts for the following three objects: (1) row sums u1
of A
, (2) column sums v1
of A
, and (3) total production x1
.
ras(io, x1, u1, v1, tol, maxiter, verbose = FALSE)
ras(io, x1, u1, v1, tol, maxiter, verbose = FALSE)
io |
An |
x1 |
Vector. The forecast for future total production of each region-sector combination, matching the |
u1 |
Vector. The forecast for future row sums of the matrix of technical input coefficients in |
v1 |
Vector. The forecast for future column sums of the matrix of technical input coefficients in |
tol |
Numeric. The tolerance for convergence. Default: |
maxiter |
Numeric. The maximum number of iterations to try for convergence. Defualt: 10000 |
verbose |
Logical. If |
Uses the ras iterative technique for updating the matrix of technical input coefficients. This takes the form:
where ,
, and
u1
. Similarly ,
.
Each iteration calculates the full object; that is, 2 steps are caluclated per iteration.
See Blair and Miller (2009) for more details.
Produces the forecast of the matrix of technical input coefficients given the forecasted row sums, column sums, and total production.
John J. P. Wade
Blair, P.D. and Miller, R.E. (2009). "Input-Output Analysis: Foundations and Extensions". Cambridge University Press
data(toy.IO) class(toy.IO) set.seed(117) growth <- 1 + 0.1 * runif(10) sort(growth) X <- toy.IO$X X1 <- X * growth U <- rowSums(toy.IO$Z) U1 <- U * growth V <- colSums(toy.IO$Z) V1 <- V * growth ras <- ras(toy.IO, X1, U1, V1, maxiter = 10, verbose = TRUE)
data(toy.IO) class(toy.IO) set.seed(117) growth <- 1 + 0.1 * runif(10) sort(growth) X <- toy.IO$X X1 <- X * growth U <- rowSums(toy.IO$Z) U1 <- U * growth V <- colSums(toy.IO$Z) V1 <- V * growth ras <- ras(toy.IO, X1, U1, V1, maxiter = 10, verbose = TRUE)
rsp
uses the RSP technique to update the matrix of technical input coefficients A
from an InputOutput
object created from as.inputoutput
. The function calls upon import.total
and export.total
to calculate the imports and exports.
rsp(io)
rsp(io)
io |
An |
The new matrix of technical coefficients is calculated as follows:
where is a diagonal matrix with each diagonal componenet calculated as
Anew |
The updated matrix of technical input coefficients |
John J. P. Wade
Nazara, Suahasil & Guo, Dong & Hewings, Geoffrey J.D., & Dridi, Chokri, 2003. "PyIO. Input-Output Analysis with Python". REAL Discussion Paper 03-t-23. University of Illinois at Urbana-Champaign. (http://www.real.illinois.edu/d-paper/03/03-t-23.pdf)
data(toy.IO) class(toy.IO) Anew <- rsp(toy.IO)
data(toy.IO) class(toy.IO) Anew <- rsp(toy.IO)
EasySelect
An object of EasySelect
class created from easy.select
.
data("toy.ES")
data("toy.ES")
A character matrix with three columns and 5 rows with class EasySelect
. The first row indicates which rows/columns of toy.IO
are of interest. The second and third column are the regions and sectors that respectively match the the first column.
data(toy.ES) class(toy.ES)
data(toy.ES) class(toy.ES)
This data is designed to be a small dimension worst case scenario. The numbers are saved as a string and there are many NA
s floating around. The data itself was randomly generated.
data("toy.FullIOTable")
data("toy.FullIOTable")
An input output matrix with two regions, five sectors, four national accounts categories (including exports), four values added (including imports), and total production.
toy,FullIOTable was created using the following code where toy.FullIOTable
was created using the seed of 117
and toy.FullIOTable2
was created using the seed 112358
See also toy.IO
, as.inputoutput
set.seed(117) # Creating the T (transaction) matrix T11 <- matrix(sample(1:100, 25), ncol = 5, nrow = 5) T12 <- matrix(sample(1:100, 25), ncol = 5, nrow = 5) T21 <- matrix(sample(1:100, 25), ncol = 5, nrow = 5) T22 <- matrix(sample(1:100, 25), ncol = 5, nrow = 5) Trd <- rbind(cbind(T11,T12),cbind(T21,T22)) # Creating Labels region <- c(rep("Hogwarts",5),rep("Narnia",5)) sector <- c("Pizza","Wii","Spaceships","Lightsabers","Minions") sector <- c(sector,sector) id <- rbind(region,sector) blank <- matrix(NA, ncol = 2, nrow = 2) Trd <- rbind( cbind(blank, id), cbind(t(id), Trd)) # Creating value added matrix V <- matrix(sample(100:300, 30), ncol = 10, nrow = 3) label <- matrix(c("Employee Compensation", "Proprietor Income", "Indirect Business Tax"), ncol = 1) blank <- matrix(NA, ncol = 1, nrow = 3) V <- cbind(blank, label, V) # Creating final demand matrix f <- matrix(sample(1:300, 80), ncol = 8, nrow = 10) label <- c("Household", "Government", "Investment", " Exports") label <- matrix(c(label, label), nrow = 1) id <- rbind(region[c(1:4,6:9)], label) f <- rbind(id, f) # Creating total production one.10 <- matrix(rep(1, 10), ncol = 1) one.8 <- matrix(rep(1, 8), ncol = 1) X <- matrix(as.numeric(Trd[3:12, 3:12]), nrow = 10)%*%one.10 + matrix(as.numeric(f[3:12,]), nrow = 10)%*%one.8 label <- matrix(c(NA,"Total")) X <- rbind(label, X) # Creating imports (in this case it is a residual) M <- matrix(NA, nrow = 1, ncol = 12) one.3 <- matrix(rep(1, 3), ncol = 1) M[1, 3:12] <- t(one.10)%*%matrix(as.numeric(Trd[3:12, 3:12]), nrow = 10) + t(one.3)%*%matrix(as.numeric(V[,3:12]), nrow = 3) M[1, 2] <- "Imports" # Putting this beast together blank <- matrix(NA, nrow=5, ncol = 9) holder <- cbind(f, X) holder <- rbind(holder, blank) hold <- rbind(Trd, V, M, t(X)) toy.FullIOTable <- cbind(hold, holder) # Creating an FV matrix a <- matrix(round(80*runif(12)), nrow = 2, ncol = 6) toy.FullIOTable[15:16, c(13:15, 17:19)] <- a
set.seed(117) # Creating the T (transaction) matrix T11 <- matrix(sample(1:100, 25), ncol = 5, nrow = 5) T12 <- matrix(sample(1:100, 25), ncol = 5, nrow = 5) T21 <- matrix(sample(1:100, 25), ncol = 5, nrow = 5) T22 <- matrix(sample(1:100, 25), ncol = 5, nrow = 5) Trd <- rbind(cbind(T11,T12),cbind(T21,T22)) # Creating Labels region <- c(rep("Hogwarts",5),rep("Narnia",5)) sector <- c("Pizza","Wii","Spaceships","Lightsabers","Minions") sector <- c(sector,sector) id <- rbind(region,sector) blank <- matrix(NA, ncol = 2, nrow = 2) Trd <- rbind( cbind(blank, id), cbind(t(id), Trd)) # Creating value added matrix V <- matrix(sample(100:300, 30), ncol = 10, nrow = 3) label <- matrix(c("Employee Compensation", "Proprietor Income", "Indirect Business Tax"), ncol = 1) blank <- matrix(NA, ncol = 1, nrow = 3) V <- cbind(blank, label, V) # Creating final demand matrix f <- matrix(sample(1:300, 80), ncol = 8, nrow = 10) label <- c("Household", "Government", "Investment", " Exports") label <- matrix(c(label, label), nrow = 1) id <- rbind(region[c(1:4,6:9)], label) f <- rbind(id, f) # Creating total production one.10 <- matrix(rep(1, 10), ncol = 1) one.8 <- matrix(rep(1, 8), ncol = 1) X <- matrix(as.numeric(Trd[3:12, 3:12]), nrow = 10)%*%one.10 + matrix(as.numeric(f[3:12,]), nrow = 10)%*%one.8 label <- matrix(c(NA,"Total")) X <- rbind(label, X) # Creating imports (in this case it is a residual) M <- matrix(NA, nrow = 1, ncol = 12) one.3 <- matrix(rep(1, 3), ncol = 1) M[1, 3:12] <- t(one.10)%*%matrix(as.numeric(Trd[3:12, 3:12]), nrow = 10) + t(one.3)%*%matrix(as.numeric(V[,3:12]), nrow = 3) M[1, 2] <- "Imports" # Putting this beast together blank <- matrix(NA, nrow=5, ncol = 9) holder <- cbind(f, X) holder <- rbind(holder, blank) hold <- rbind(Trd, V, M, t(X)) toy.FullIOTable <- cbind(hold, holder) # Creating an FV matrix a <- matrix(round(80*runif(12)), nrow = 2, ncol = 6) toy.FullIOTable[15:16, c(13:15, 17:19)] <- a
InputOutput
An object of InputOutput
class created from toy.FullIOTable
using as.inputoutput
.
data("toy.IO")
data("toy.IO")
toy.IO is a list with 14 elements: 7 matrices and 7 labels.
Z |
Intermediate Transactions |
RS_label |
Column matrix of labels for region and sector |
f |
Final Demand |
f_label |
Row matrix of labels for accounts for |
E |
Exports |
E_label |
Row matrix of labels for exports by sector and region for |
X |
Total Production |
V |
Value added |
V_label |
Column matrix of labels for types of value added for |
M |
Imports |
M_label |
Colum matrix of labels for type of imports for |
A |
Technical Coefficients |
L |
Leontief Inverse |
data(toy.IO) class(toy.IO)
data(toy.IO) class(toy.IO)
Measures upstreamness as in Antras et al. (2012), equation (9) page 5. The value is weakly bounded below by one, where a value close to one indicates it is near its final use on average and a higher value indicates it is further away from final use on average.
upstream(io, ES, regions = "all", sectors = "all")
upstream(io, ES, regions = "all", sectors = "all")
io |
An |
ES |
An |
regions |
Character or Integer. Specific regions to be used. Can either be a character that exactly matches the name of the region in |
sectors |
Character or Integer. Specific sectors to be used. Can either be a character that exactly matches the name of the sector in |
The upstreamness is calculated as follows, where, A is the matrix of technical input coefficients, X is total production, E is exports, and M is imports.
Produces a list over regions of each region's sectors upstreamness measure.
If the import (M) and/or export (E) is a matrix (i.e. not a nx1 vector) they are summed across region-sector combinations.
John J. P. Wade, Ignacio Sarmiento-Barbieri
Pol Antras & Davin Chor & Thibault Fally & Russell Hillberry, 2012. Measuring the Upstreamness of Production and Trade Flows. NBER Working Papers 17819, National Bureau of Economic Research, Inc.
data(toy.IO) class(toy.IO) u1 <- upstream(toy.IO) u1$Hogwarts
data(toy.IO) class(toy.IO) u1 <- upstream(toy.IO) u1$Hogwarts
Calculates the vertical specialization share of total exports of each sector as described by Hummels et al. (2001), equation 3. Creates a value between zero and one to indicate relative specialization. For each region, a Leontief inverse is calculated. You need a multi-region input-output dataset for vs
to be relevant.
Caution: Inverting large matrices will take a long time. Each individual hypothetical extraction requires the inversion of a matrix. R does a computation roughly every 8e-10 second. The number of computations per matrix inversion is n^3 where n is the dimension of the square matrix. For n = 5000 it should take 100 seconds.
vs(io, ES, regions = "all", sectors = "all")
vs(io, ES, regions = "all", sectors = "all")
io |
An |
ES |
An |
regions |
Character or Integer. Specific regions to be used. Can either be a character that exactly matches the name of the region in |
sectors |
Character or Integer. Specific sectors to be used. Can either be a character that exactly matches the name of the sector in |
The vertical specialization share of total exports is calculated as follows:
where is the total exports for region r,
is the matrix of technical import coefficients,
is the domestic Leontief inverse calculated from the domestic matrix of technical coefficients i.e.
not the full
matrix, and
is the vector of total exports.
Creates a region list of vs share of total exports.
John J. P. Wade, Ignacio Sarmiento-Barbieri
Hummels, David & Ishii, Jun & Yi, Kei-Mu, 2001. The nature and growth of vertical specialization in world trade. Journal of International Economics, Elsevier, vol. 54(1), pages 75-96, June.
import.coef
, export.total
, check.RS
, leontief.inv
data(toy.IO) class(toy.IO) (vs1 <- vs(toy.IO, regions = "all")) vs1$Hogwarts sum(vs1$Hogwarts) data(toy.ES) class(toy.ES) vs2 <- vs(toy.IO, toy.ES) vs2
data(toy.IO) class(toy.IO) (vs1 <- vs(toy.IO, regions = "all")) vs1$Hogwarts sum(vs1$Hogwarts) data(toy.ES) class(toy.ES) vs2 <- vs(toy.IO, toy.ES) vs2