2  Dependencies

This chapter outlines what is needed to run your first CGE model. Ideally all components would be open-source and maybe one day they will be, but for the moment there are still some minor hurdles to overcome. Before beginning to write model scripts in R with teems, users will need to gain access to a GTAP database and build the teems-solver. GEMPack users can skip the solver step although they will be missing out on a considerable degree of functionality both within the solution process itself as well as regarding post-model data availability.

For those skeptical of using R or under the impression that R is only for statistical analysis, we would invite you to investigate speed tests between the R data.table package (widely employed within teems) and comparable packages in Python and Julia. For all but the largest models, the time needed to prepare input files is trivial. The solver itself is written in C and uses highly performant Fortran libraries.

2.1 Data

Currently the only data for teems-compatible CGE model runs is available from the Global Trade Analysis Project (GTAP). Although the most recent databases are proprietary, GTAP has consistently open-accessed databases two versions out (GTAP 10 database as of the current GTAP 12 release). In order to access the freely available database, users will need to register with GTAP and download the “FlexAgg” format. For GTAP 10 this is accessible under the “GDyn Data Base” entry in the GTAP 10 “Satellite Data and Utilities” section here. For GTAP members that have purchased a database, the current teems version is capable of handling the “FlexAgg” format for GTAP Databases 9, 10, and 11. GTAP Data Base 12 will be added shortly.

2.2 R

R (>= 4.3.0) is required. Download and install the latest release for your platform from CRAN.

RStudio is the recommended IDE for working with teems scripts. It provides a script editor, integrated console, and a file browser that makes it straightforward to open, edit, and run the example scripts generated by ems_example().

2.3 teems-R package

The R package is currently in beta (v0.0.3) and open for testing. It requires R >= 4.3.0 and is installed via remotes:

remotes::install_github("teemsphere/teems-R@v0.0.3")

2.4 teems-solver

teems calls Docker to solve the constrained optimization problem using low-level C and Fortran routines. The solver build is available here: teems-solver. The latest solver build will always be compatible with the latest R package version.

2.4.1 Prerequisites

Two prerequisites beyond Docker are required before building:

  • Docker — install from docker.com. Linux users must also configure Docker to run without sudo.
  • HSL libraries — four sparse linear algebra libraries (MA48, MA51, HSL_MC66, HSL_MP48) must be obtained directly from HSL prior to building. These are available at no cost for academic use.

2.4.2 Build options

Two Docker build approaches are available. The expedited build (~5 min) is recommended for most users and uses a pre-built base image containing all open-source dependencies. The full build (~40 min) compiles everything from source.