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
Merged

derive an M matrix for IEF models #317

merged 9 commits into from
Oct 30, 2024

Conversation

bl-young
Copy link
Collaborator

@bl-young bl-young commented Sep 6, 2024

When an M matrix is present an N matrix will also be constructed during the regular course of model build.

@bl-young bl-young linked an issue Sep 6, 2024 that may be closed by this pull request
@bl-young
Copy link
Collaborator Author

bl-young commented Sep 6, 2024

Leaving this as draft for now as it may require further discussion.

@bl-young
Copy link
Collaborator Author

bl-young commented Sep 6, 2024

A few notes about this approach:

  • Sectors for which have no final demand (e.g. "211") will have coefficients of 0 in the M matrix, even if values exist in M_m and M_d
  • I had assumed that for all sectors, the M value for any flow and sector would be somewhere in between the value for M_m and M_d, but this is not the case, perhaps this relates to the first point

Example:
M_d:
image

M_m:
image

derived M:
image

@bl-young
Copy link
Collaborator Author

bl-young commented Sep 6, 2024

  • I had assumed that for all sectors, the M value for any flow and sector would be somewhere in between the value for M_m and M_d, but this is not the case, perhaps this relates to the first point

And this is especially clear for the flows not available in the IEFs which are identical for M_m and M_d e.g. HFCs

@bl-young
Copy link
Collaborator Author

@WesIngwersen see the commit above which is using ratios from the domestic production demand vector relative to the import consumption demand vector, which I'm not sure is quite right still

@WesIngwersen
Copy link
Collaborator

WesIngwersen commented Sep 10, 2024

Yes i reviewed the approach and its still problematic, perhaps due to differences in the demand vectors as well as the negatives present which mess up ratios.

I propose more of a weighted average approach, using commodity output, q and the total imports m

$$dr = q/(q+m)$$

$$mr = 1 - dr$$

$$M = M_d \hat{dr} + M_m \hat{mr}$$

@WesIngwersen
Copy link
Collaborator

Have you made any scripts for testing this with different models?

@bl-young
Copy link
Collaborator Author

Have you made any scripts for testing this with different models?

The automated model builds include USEEIOv2.3-GHG and USEEIOv2.3-s-GHG, as well as a two region model (GA) with IEFs GAEEIOv1.1-GHG-19-IF. So all those models are able to build the M.

But no I haven't done an external script to do that explicitly - are there certain validations that we want to test after building the M this way?

@WesIngwersen
Copy link
Collaborator

Make sure each value is in between the respective value in M_m and M_d. To do this might need to get max and min matrices

@bl-young
Copy link
Collaborator Author

the detail model is failing for S00900 Rest of World Adjustment.
total imports for that sector are negative, so the ratios are dr > 1, and mr <0 for that sector, causing the error. Would it make sense to force that ratio to all domestic for that sector (dr = 1)

@WesIngwersen
Copy link
Collaborator

the detail model is failing for S00900 Rest of World Adjustment. total imports for that sector are negative, so the ratios are dr > 1, and mr <0 for that sector, causing the error. Would it make sense to force that ratio to all domestic for that sector (dr = 1)

That's OK, that should not be an issue - we always have exceptions with RoW adjustment since its an accounting correction row and meaningless for use in the model.

thanks I assume this check passes for some state models and the summary model?

@bl-young
Copy link
Collaborator Author

That's OK, that should not be an issue - we always have exceptions with RoW adjustment since its an accounting correction row and meaningless for use in the model.

ok I'll change this from a stop to a print statement or something like that as a form of validation, not a requirement

thanks I assume this check passes for some state models and the summary model?

I need to check - the other models may not have run on the action when the detail model failed, but yes I tested this with those models as well and it should work.

@bl-young
Copy link
Collaborator Author

Confirmed that the validation passes for summary model and 2R GA model, and prints the failures for the detail model:
image

@WesIngwersen
Copy link
Collaborator

OK I think we can proceed with updating N and related vars using this new M

@bl-young
Copy link
Collaborator Author

by building $M$ in this way, which is to say, right after $M_m$ and $M_d$, means that $N$ is produced automatically

useeior/R/BuildModel.R

Lines 72 to 83 in e232ca1

# Calculate total impacts per dollar (N), impact category x sector
if(!is.null(model$M)) {
logging::loginfo("Calculating N matrix (total environmental impacts per dollar)...")
model$N <- model$C %*% model$M
}
if(!is.null(model$M_m)) {
logging::loginfo("Calculating N_m matrix (total environmental impacts per dollar from imported activity)...")
model$N_m <- model$C %*% model$M_m
}
logging::loginfo("Calculating N_d matrix (total environmental impacts per dollar from domestic activity)...")
model$N_d <- model$C %*% model$M_d
}

@bl-young bl-young marked this pull request as ready for review September 13, 2024 13:32
@bl-young
Copy link
Collaborator Author

We will need to decide if this is going to be integrated with v1.6.1 (CBEI model release) or wait until v1.7

@bl-young bl-young added this to the v1.6.1 - CBEI milestone Oct 30, 2024
@bl-young
Copy link
Collaborator Author

Bring this in w/ v1.6.1 as it will be described in the CBEI report.

bl-young added a commit to USEPA/USEEIO-State that referenced this pull request Oct 30, 2024
@bl-young bl-young merged commit 4ace170 into develop Oct 30, 2024
6 checks passed
@bl-young bl-young deleted the issue_311 branch October 30, 2024 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create N and M matrices for v2.3 models
2 participants