Skip to content

Commit 12a2987

Browse files
committed
initial draft of dqi approach
1 parent b042a75 commit 12a2987

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

R/BuildModel.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ constructEEIOMatrices <- function(model, configpaths = NULL) {
3333
# Generate B matrix
3434
logging::loginfo("Building B matrix (direct emissions and resource use per dollar)...")
3535
model$B <- createBfromFlowDataandOutput(model)
36+
model$B_dqi <- createB_dqi(model)
3637
B_h <- standardizeandcastSatelliteTable(model$CbS, model, final_demand=TRUE)
3738
if(!is.null(B_h)) {
3839
model$B_h <- as.matrix(B_h)
@@ -48,6 +49,7 @@ constructEEIOMatrices <- function(model, configpaths = NULL) {
4849
# Add direct impact matrix
4950
logging::loginfo("Calculating D matrix (direct environmental impacts per dollar)...")
5051
model$D <- model$C %*% model$B
52+
model$D_dqi <- (model$C %*% (model$B * model$B_dqi)) / model$D
5153
}
5254

5355
model <- buildPriceMatrices(model)
@@ -61,6 +63,7 @@ constructEEIOMatrices <- function(model, configpaths = NULL) {
6163
# Calculate total emissions/resource use per dollar (M)
6264
logging::loginfo("Calculating M matrix (total emissions and resource use per dollar)...")
6365
model$M <- model$B %*% model$L
66+
model$M_dqi <- ((model$B * model$B_dqi) %*% model$L) / model$M
6467

6568
colnames(model$M) <- colnames(model$M)
6669
# Calculate M_d, the domestic emissions per dollar using domestic Leontief
@@ -73,6 +76,7 @@ constructEEIOMatrices <- function(model, configpaths = NULL) {
7376
if(!is.null(model$M)) {
7477
logging::loginfo("Calculating N matrix (total environmental impacts per dollar)...")
7578
model$N <- model$C %*% model$M
79+
model$N_dqi <- ((model$D * model$D_dqi) %*% model$L) / model$N
7680
}
7781
if(!is.null(model$M_m)) {
7882
logging::loginfo("Calculating N_m matrix (total environmental impacts per dollar from imported activity)...")

R/DataQualityFunctions.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,27 @@ scoreTemporalDQ <- function(data_year,target_year=NA, scoring_bounds) {
9393
score <- lookupDQBoundScore(age, "TemporalCorrelation", scoring_bounds)
9494
return(score)
9595
}
96+
97+
createB_dqi <- function(model) {
98+
# modeled from standardizeandcastSatelliteTable()
99+
df <- model$TbS
100+
df[, "Sector"] <- apply(df[, c("Sector", "Location")],
101+
1, FUN = joinStringswithSlashes)
102+
# Cast df into a flow x sector matrix
103+
df_cast <- reshape2::dcast(df, Flow ~ Sector, fun.aggregate = sum, value.var = "TemporalCorrelation")
104+
# Move Flow to rowname so matrix is all numbers
105+
rownames(df_cast) <- df_cast$Flow
106+
df_cast$Flow <- NULL
107+
df_cast[, setdiff(model$Industries$Code_Loc, colnames(df_cast))] <- 0
108+
# Adjust column order to be the same with V_n rownames
109+
df_cast <- df_cast[, model$Industries$Code_Loc]
110+
dqi <- as.matrix(df_cast)
111+
112+
# Need to Transform into a flow x commodity matrix using market shares matrix for commodity models
113+
# see createBfromFlowDataandOutput()
114+
115+
# array(combined_vector, dim = c(5, 5, 5))
116+
117+
118+
return(dqi)
119+
}

0 commit comments

Comments
 (0)