Skip to content

Commit

Permalink
For models with external import factors,
Browse files Browse the repository at this point in the history
Dropped U_n_m and UseTransactions_m at end of model build

Removed model$DomesticFDWithITA object (not needed)

Corrected description of coupled model approach at the beginning of buildModelwithImportFactors function

Removed unneeded commented code
  • Loading branch information
jvendries committed Nov 17, 2023
1 parent f723333 commit 541ff85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
7 changes: 6 additions & 1 deletion R/BuildModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ constructEEIOMatrices <- function(model) {
mat_to_remove <- c("MakeTransactions", "UseTransactions", "DomesticUseTransactions",
"UseValueAdded", "FinalDemand", "DomesticFinalDemand",
"InternationalTradeAdjustment", "CommodityOutput", "IndustryOutput",
"U_n", "U_d_n")
"U_n", "U_d_n")
# Drop U_n_m, UseTransactions_m for models with external import factors
if(!is.null(model$specs$ExternalImportFactors)){
mat_to_remove <- c(mat_to_remove, "U_n_m", "UseTransactions_m")
}

if (model$specs$CommodityorIndustryType=="Industry") {
mat_to_remove <- c(mat_to_remove,
c("FinalDemandbyCommodity", "DomesticFinalDemandbyCommodity",
Expand Down
29 changes: 5 additions & 24 deletions R/IOFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ generateInternationalTradeAdjustmentVector <- function(Use, Import, model) {
#' @param model, An EEIO model object with model specs and crosswalk table loaded
#' @return A model object with explicit import components.
buildModelwithImportFactors <- function(model) {
# Deriving the economic component of the Swedish equation for import factors: f^(d+m) = S^d*L^d*y^d + Q^t*A^m*L^d*y^d + Q^t*y^m + f^h
# S and Q are the environmental intensity matrices, so getting rid of those components we would have the following (where x is the economic component of f)
# x^(d+m) = L^d*y^d + A^m*L^d*y^d + y^m + f^h
# Deriving the economic component of the Swedish equation for import factors: f^(d+m) = s^d*L^d*y^d + Q^t*A^m*L^d*y^d + Q^t*y^m + f^h
# s^d are the domestic direct environmental coefficients, and Q are the environmental import multipliers, s_m*L_m. Dropping s_d and s_m we get
# x^(d+m) = s^d*L^d*y^d + L^m*A^m*L^d*y^d + L^m*y^m + f^h
# Since f^h is not currently part of the useeior model calculations, we drop it:
# x^(d+m) = L^d*y^d + A^m*L^d*y^d + y^m
# x^(d+m) = L^d*y^d + L^m*A^m*L^d*y^d + L^m*y^m
# The resulting expression should be equivalent to the x = L*y such that
# x^(d+m) = x = L*y

Expand All @@ -253,10 +253,8 @@ buildModelwithImportFactors <- function(model) {
model$U_n_m <- normalizeIOTransactions(model$UseTransactions_m, model$IndustryOutput) #normalized imported Use

# Including InternationalTradeAdjustment in DomesticFinalDemand for import factors calculations
model$DomesticFDWithITA <- model$DomesticFinalDemand # TODO: Remove after testing calculation functions without this object

if(model$specs$IODataSource != "stateior") {
model$DomesticFDWithITA[,"F050/US"] <- model$InternationalTradeAdjustment

FD_col_index <- which(colnames(model$ImportMatrix) %in% model$FinalDemandMeta$Code_Loc)
model$ImportFinalDemand <- model$ImportMatrix[,FD_col_index]
}else{
Expand Down Expand Up @@ -285,23 +283,6 @@ buildModelwithImportFactors <- function(model) {

model$M_m <- M_m

# # Check that import values are the same as the original import data
# # Note that this check is not meant to be included in the code
# Import <- get(paste("Summary_Import", model$specs$IOYear, "BeforeRedef", sep = "_"))*1E6
# Import <- Import[,!names(Import) %in% c("T001", "T004")] # Remove t001 and t004 columns.
# Import <- Import[c(model$Industries$Code, model$FinalDemandMeta$Code)] # Reorder final demand columns to match final demand meta
# rownames(Import) <-rownames(model$UseTransactions_m)
# importColNames <- c(colnames(model$UseTransactions_m), colnames(model$DomesticFDWithITA))
# colnames(Import) <- importColNames
#
# useCheck <- model$UseTransactions_m - Import[,1:71]
# sum(sum(useCheck)) == 0 # should be TRUE as should all.equal(model$UseTransactions_m, Import[,1:71])
#
# importCheck <- model$ImportFinalDemand - Import[72:91]
# sum(sum(importCheck)) == 0 # should be TRUE as should all.equal(model$ImportFinalDemand, Import[,72:91])
#
# model$ImportMatrix <- Import #Temporary addition for validation checks

return(model)
}

Expand Down

0 comments on commit 541ff85

Please sign in to comment.