Skip to content

Using useeior

Ben Young edited this page Mar 5, 2022 · 28 revisions

Reviewing an example or reading the Help pages embedded in the package are the best ways to learn how to use useeior. An example script covering a basic use for useeior can be found in examples. As an R package, useeior provides standard Help pages for all functions.

Basic usage of useeior is demonstrated in README. Additional functions that calculate, validate, export, visualize model are available for assisting further applications. More advanced uses include creating a new model by customizing a model configuration file or disaggregating the model.

Calculate, Validate, Export, Visualize Model

Once a model is built, useeior provides a number of functions that take the model object. The following table lists these functions. Read more about any of these functions by searching their names using the help menu inside your R editor.

Function Name General Purpose
adjustResultMatrixPrice Result Calculation and Analysis
calculateEEIOModel Result Calculation and Analysis
calculateFlowContributiontoImpact Result Calculation and Analysis
calculateSectorContributiontoImpact Result Calculation and Analysis
calculateSectorPurchasedbySectorSourcedImpact Result Calculation and Analysis
calculateMarginSectorImpacts Result Calculation and Analysis
aggregateResultMatrix Result Calculation and Analysis
aggregateResultMatrixbyRow Result Calculation and Analysis
normalizeResultMatrixByTotalImpacts Result Calculation and Analysis
compareOutputandLeontiefXDemand Validation
compareEandLCIResult Validation
compareCommodityOutputandDomesticUseplusProductionDemand Validation
compareCommodityOutputXMarketShareandIndustryOutputwithCPITransformation Validation
generateModelIdentifier Export
writeModelforAPI Export
writeModelMatrices Export
writeModeltoXLSX Export
heatmapSatelliteTableCoverage Visualization
barplotIndicatorScoresbySector Visualization
barplotFloworImpactFractionbyRegion Visualization
heatmapSectorRanking Visualization
plotMatrixCoefficient Visualization
compareFlowTotals Comparison

Advanced Uses

Changing Model Parameters

Model specifications can be modified by adjusting parameters within the appropriate model config file (.yml) located in inst/extdata/modelspecs. See the details on all fields in the ModelSpecifications.md. Static source files for satellite tables and indicators must be stored locally or can be downloaded from a remote source like the EPA Data Commons. See Data Storage for more details.

Disaggregation

USEEIO is designed to enable a reproducible, automated approach to disaggregating sectors in EEIO models. Disaggregation specifications are included within the package for selected sectors. When a disaggregation is applied, a single sector is divided into two or more sectors enabling a greater level of detail in the model. Current disaggregation specs include:

Further details on disaggregation methods can be found in Disaggregation of Sectors

Building Customized Models

To build a customized model, a model config file (.yml) and related aggregation/disaggregation config file (.yml) as well as data files must be prepared following the format of config files (.yml) and data files (.csv) located in inst/extdata/modelspecs, inst/extdata/aggspecs, and inst/extdata/disaggspecs.

Once all the files are properly created and stored in the same folder, build the customized model use:

model <- buildModel(modelname, configpaths)

where modelname is the name of the model config .yml file, and configpaths is a string vector of config file paths, for example:

configpaths <- file.path(user-specified-dir, # replace this with your desired directory
                         c("USEEIOv2.1.yml",
                           "ElectricityDisaggregationDetail.yml",
                           "ElectricityAggregationDetail.yml",
                           "WasteDisaggregationDetail.yml"))

Note that user-specified-dir should be replaced by actual folder directory.

Custom Demand Vectors

Custom demand vectors can be used for calculating results beyond those included by default in the DemandVectorFunctionRegistry. These vectors can be created in code:

y <- setNames(c(245000, 140000), c("1111A0/US", "211000/US"))
y <- formatDemandVector(y, model$L)

Or by pointing to a csv file:

file_path <- 'path-to-file/demand.csv'
y <- extractAndFormatDemandVector(file_path, "MyDemand", model)

where the csv file takes the following format:

Code MyDemand
1111A0/US 245000
211000/US 140000

The demand vector y can now be used in other calculation functions:

impact_result <- calculateSectorPurchasedbySectorSourcedImpact(y, model, "Greenhouse Gases")
result <- calculateEEIOModel(model, perspective = "DIRECT", demand = y)