# An Open-Source R Package for Building and Using US Environmentally-Extended Input-Output Models
## 2 Materials & Methods
### Model Calculation  
Model matrices can be used to calculate life cycle inventory (LCI) and life cycle impact assessment (LCIA) results given a user-specified perspective, demand vector (from _DemandVectors_ in the model object or a user-provided vector), and a selected requirements matrix (complete or domestic). result <- calculateEEIOModel(model, perspective = \"DIRECT\", demand = \"Production\", use_domestic_requirements = FALSE)  
The return result list contains two matrices: either \(LCI_{d}\) and \(LCIA_{d}\), where \(d\) indicates the \"DIRECT\" perspective, or \(LCI_{f}\) and \(LCIA_{f}\), where \(f\) indicates the \"FINAL\" perspective. The direct perspective calculation associates the total impact with the sectors that produce the given flows (e.g., direct emissions, waste generation, or resource use), while the final perspective calculation associates the total impacts with the final consumption sectors that drives that impact. The direct perspective LCI, i.e., the _direct_ flows matrix, is calculated with Equation (23). \[LCI_{d}=B\hat{s} \tag{23}\]  
where \(s\), a scaling vector, is the product of \(L\) and the given final demand vector, \(y\), as shown in Equation (24). \[s=Ly \tag{24}\]  
A similar approach is used to calculate the _direct_ impacts with the direct perspective Equation (25). \[LCIA_{d}=D\hat{s} \tag{25}\]  
The _direct_ + _indirect_ flows matrix with the final perspective, \(LCI_{f}\) is calculated with Equation (26). \[LCI_{f}=M\hat{y} \tag{26}\]  
The _direct_ + _indirect_ impacts are calculated as in Equation (26), but use \(U\) in place of \(M\), as shown in Equation (27). \[LCIA_{f}=N\hat{y} \tag{27}\]  
To calculate any domestic result, the \(L_{d}\) and a demand vector derived from \(y_{d}\) are used. The difference between any full result calculation and the domestic calculation can be used to derive rest of world region results, as in Equation (28). \[LCIA_{d,RoW}=LCIA-LCIA_{d,U\hat{s}} \tag{28}\]  
where \(LCIA_{d,RoW}\) is the contribution from rest of world, and \(LCIA_{d,U\hat{s}}\) is the contribution from the US. To calculate a flow's contribution to total impacts of an indicator in a sector, divide the product of the flow's total impact, in \(M\) or \(M\_d\), and its indicator factor, in \(C\), by the sum of total impacts in the sector. flow_impact <- calculateFlowContributiontol impact(model, sector, indicator, domestic = FALSE)  
To calculate a sector's contribution to total impacts of an indicator, divide the product of the sector's total requirements, in \(L\) or \(L\_d\), and the indicator's direct impact by flow, in \(D\), by the sum of total impacts of the indicator. sector_impact <- calculateSectorContributiontol impact(model, sector, indicator, domestic = FALSE)  
To calculate the total impact of an indicator passed from one sector to another through purchase, the diagonalized form of the indicator's direct impact, \(D\), is multiplied by the product of total requirements, \(L\), and the diagonalized form of the demand vector, \(y\)\(y\) can be a calculated demand vector in _model_ or a user-specified vector that has the same dimension with any model demand vector. _sector2 sector_impact_ is a matrix of total impacts in the form of sector purchased x sector sourced, where negative values are interpreted as reduced impacts. sector2 sector_impact <- calculateSectorPurchasedbySectorSourcedImpact(y, model, indicator)  
Margin impacts are calculated via multiplying the normalized impact of margin sector (i.e., retail, wholesale, and transportation sectors) on each commodity by the total impact coefficients (amount per dollar in producer price) of each commodity. As a result, margin impacts are delivered in by-flow and by-indicator forms based on the model \(M\) and \(N\) matrices. margin_impact <- calculateMarginSectorImpacts(model)  
Any sector x flow matrix can be normalized by the total of respective flow (column sum) for usage in further applications.