# An Open-Source R Package for Building and Using US Environmentally-Extended Input-Output Models
## 2 Materials & Methods
### Model Validation  
A series of validation functions are available to validate that model calculation results were equivalent to known IO and EEIO identities. As model calculation results would not be expected to match exactly, due to rounding in original datasets, the margin of error is customizable to meet different restrictions, with a default setting of 1% error. Complete model validation checks were performed in ValidateModel.Rmd in the 'inst/doc/' folder. Knit ValidateModel_render.Rmd in the same folder to run all validation checks on selected models specified under the YAML header. This returns an.html and a.md file in the 'inst/doc/output/' folder containing validation results for each model. A full model validation is performed via verifying that national flow totals by sector used as inputs to the model can be recalculated using appropriate model components. model_val <- compareEandLCIResult(model, use_domestic = TRUE, tolerance = 0.01)  
This validation was performed using Equation (29). \[E=B\dot{\chi}L\dot{\psi} \tag{29}\]  
If model is a commodity model, \(E\) on the left side becomes \(E(c)\), which is the original flow by industry totals, \(E(i)\), put into a flow x commodity form. \(E(i)\), a national total of flow by industry per year, consisting of the concatenation of all the satellite tables described above, and is available for various years. \(E(c)\) is obtained from \(E(i)\) by multiplying its transpose by the commodity mix matrix, \(C_{m}\), and transposing the result (Equation (30)). \[E(c)=\left(C_{m}E(i)^{\prime}\right)^{\prime} \tag{30}\]  
\[C_{m}=V^{\prime}\dot{\alpha}^{-1} \tag{31}\]  
\(C_{m}\) is obtained from Equation (31), where \(V\prime\) is the transposed model make table, which is normalized by multiplying it by the diagonalized form of the inverse of model output, \(x\). Given the commodity model, the right side of Equation (29) is a slightly modified form of the matrix, calculated using the direct perspective, where \(B\) becomes \(B(i)\) representing the satellite matrix in industry form from Equation (10). As the original flow totals in \(E(i)\) may be in varying years, while the model IO data are all in the IO year (e.g. 2012 for USEEIO v2.0), to validate the model, \(B(i)\) requires an output adjustment via multiplication with \(\chi\), an output adjustment matrix. \(\chi\) is composed of \(x_{s}:x\) output ratios and in the same form, as well as rows and column identifiers, as \(B(c)\). The element-wise product of \(B(i)\) and \(\chi\) adjusts \(B(i)\) for the flow year differences, and effectively converts \(B(i)\) into a harmonized IO year form. Before being multiplied with the commodity-based \(L\hat{y}\) product, \(B(i)\) is further transformed using Equation (12) into commodity form, \(B(c)\), via the market shares matrix, \(V_{n}\), obtained from Equation (4). If _model_ is an industry model, \(E\) on the left side of Equation (29) becomes \(E(i)\), which is the original flow by industry totals, while \(B\) on the right side becomes \(B(i)\). As \(L\) and \(\hat{y}\) are also in industry form, they can directly times \(B(i)\) and \(\chi\), then the product is comparable against \(E(i)\) on the left side of Equation (29). Additional validations were performed to:  
* Check that economic output, industry output (if _model_ is an industry model), or commodity output (if model is a commodity model) can be recalculated by final demand multiplying the Leontief matrix in Equation (32) or Equation (33). \(\text{econ\_val}<\text{- compareOutputandLeontiefXDemand(model, tolerance = 0.01)}\) \[x=L\hat{y}\] (32) \[q=L\hat{y}\] (33)
* Check that a commodity model's final demand and commodity output can be recalculated by summing domestic use. q_val <- compareCommodityOutputandDomesticUseplusProductionDemand(model, tolerance = 0.01) \[q=y_{domestic,production}\] (34)
* Check that total commodity output can be recalculated by industry output via transformation of CPI ratios.