Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

derive an M matrix for IEF models #317

Merged
merged 9 commits into from
Oct 30, 2024
4 changes: 2 additions & 2 deletions R/ExternalImportFactors.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ buildModelwithImportFactors <- function(model, configpaths = NULL) {
#' @param model, An EEIO model object with model specs and crosswalk table loaded
#' @return An M matrix of flows x sector
deriveMMatrix <- function(model) {
# logging::loginfo("Deriving M matrix (total emissions and resource use per dollar) ...")
logging::loginfo("Deriving M matrix (total emissions and resource use per dollar) ...")
q <- model$q
loc <- grepl(model$specs$ModelRegionAcronyms[1], model$FinalDemandMeta$Code_Loc)
bl-young marked this conversation as resolved.
Show resolved Hide resolved
import_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="Import" & loc, "Code_Loc"]
# derive total imports (m) from the Use table
U_m <- model$U - model$U_d
# Exclude imports col when calculating total imports
m <- head(rowSums(U_m[, !(colnames(U_m) %in% import_code)]), -3) # drop VA
m <- rowSums(U_m[model$Commodities$Code_Loc, !(colnames(U_m) %in% import_code)]) # drop VA

dr <- q / (q + m)
mr <- 1 - dr
Expand Down