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

Corporate economy for plotting #269

Closed
georgeharris2deg opened this issue Jan 19, 2021 · 15 comments
Closed

Corporate economy for plotting #269

georgeharris2deg opened this issue Jan 19, 2021 · 15 comments
Assignees

Comments

@georgeharris2deg
Copy link

The corporate economy outputted by r2dii.analysis::target_market_share is unweighted.
Whereas the projected and targets are weighted (scaled) by the market share of the portfolio.

This is not incorrect in any way however it does cause issues when plotting the different components on the same axis.
i.e. the corporate economy, if plotted in an unweighted form, will be aligned with different scenarios between different portfolios of different sizes.

Hence the corporate economy should be weighted by the same factor as per the targets. i.e. the market share that the portfolio is exposed to.
This then means that the y axis can only ever be given as a proxy and will not be absolute values in any case.

Perhaps we can do both and add an additional value in the "metric column" eg "scaled_corporate_economy"
This way the user can plot appropriately and also assess the corporate economy in its absolute form if they wish.

As I write this I recall that this is almost defiantly what we had done in the past and that it was changed as I questioned it.
I think this is a problem of my own making and sincerely apologies for that.

thanks and let me know
George

@jdhoffa
Copy link
Member

jdhoffa commented Jan 19, 2021

Ya, so to compare against the portfolio/ targets, we would need to plot either the tfsr or mfsp of the corporate economy, depending on the technology. We would then either normalize the start value of the portfolio, or normalize it all to either 0 or 1.

We should discuss this and decide if this should occur in the r2dii.ggplot or if the data should be organized already in the output, I'm not certain either way.

AKA. It's not a weighting issue, it's an issue of the rate of change.

@georgeharris2deg
Copy link
Author

yep - agreed. thanks!

@jdhoffa jdhoffa added the bug an unexpected problem or unintended behavior label Feb 4, 2021
@jdhoffa jdhoffa self-assigned this Feb 4, 2021
@jdhoffa
Copy link
Member

jdhoffa commented Feb 9, 2021

This should occur in r2dii.analysis.
If weight_production = FALSE, then it should output what it usually does (the unweighted production for the corporate economy)
If weight_production = TRUE, we need to apply the tmsr and smsp to the corporate economy, and effectively calculate the trajectory of the corporate economy to plot.

@jdhoffa
Copy link
Member

jdhoffa commented May 14, 2021

Somewhat relates to #105

@jdhoffa
Copy link
Member

jdhoffa commented May 19, 2021

Ok so I did a first stab at a reprex to isolate this issue. It's a pretty length reprex, but what I have shown below is as follows.
Two simple loanbooks, that are each exposed only to a single company.
In the first lbk, the company builds out renewables relatively slowly. In the second lbk, the company builds out renewables quickly.

I then run target_market_share on both portfolios (with the same ALD, and thus the same corporate_economy).

What you will notice is that, in the first plot, the corporate_economy lays almost exactly on the "NPS" boundary, whereas in the second plot, the corporate_economy lays somewhere better than the "B2DS".

This is because we are calculating moving targets for the scenarios (in relation to the portfolio) and comparing it against a static corporate economy (just normalized).

This is what I EXPECT to see given the current methodology, however what I and @georgeharris2deg WANT to see if a methodology in which the corporate economy always lands in place in relation to the scenarios.

My proposed solution would be to calculate the tmsr or smsp of the ALD itself, and calculate it in target_market_share as though it were a target.

library(r2dii.data)
library(r2dii.match)
library(r2dii.analysis)
library(r2dii.plot.static)
library(tidyverse)

matched1 <- tibble::tribble(
  ~id_loan, ~loan_size_outstanding, ~loan_size_outstanding_currency, ~loan_size_credit_limit, ~loan_size_credit_limit_currency, ~id_2dii,            ~level, ~score, ~sector,        ~name_ald, ~sector_ald,
  "L1",                     1L,                           "EUR",                      1L,                            "EUR",    "UP1", "ultimate_parent",     1L, "power", "slow build out",     "power"
)

matched2 <- tibble::tribble(
  ~id_loan, ~loan_size_outstanding, ~loan_size_outstanding_currency, ~loan_size_credit_limit, ~loan_size_credit_limit_currency, ~id_2dii,            ~level, ~score, ~sector,        ~name_ald, ~sector_ald,
  "L1",                     1L,                           "EUR",                      1L,                            "EUR",    "UP1", "ultimate_parent",     1L, "power", "fast build out",     "power"
)

ald <- tibble::tribble(
  ~name_company, ~sector,     ~technology, ~year, ~production, ~emission_factor, ~plant_location, ~is_ultimate_owner,
  "slow build out", "power", "renewablescap", 2020L,           1000,               1L,            "DE",                TRUE,
  "slow build out", "power", "renewablescap", 2025L,         1100,               1L,            "DE",                TRUE,
  "fast build out", "power", "renewablescap", 2020L,           1000,               1L,            "DE",                TRUE,
  "fast build out", "power", "renewablescap", 2025L,        2000,               1L,            "DE",                TRUE
)

scenario <- tibble::tribble(
  ~scenario, ~sector,     ~technology,  ~region, ~year, ~tmsr, ~smsp, ~scenario_source,
  "nps", "power", "renewablescap", "global", 2020L,    1L,     0,      "demo_2020",
  "nps", "power", "renewablescap", "global", 2025L,    2L,   0.1,      "demo_2020",
  "sds", "power", "renewablescap", "global", 2020L,    1L,     0,      "demo_2020",
  "sds", "power", "renewablescap", "global", 2025L,    3L,   0.2,      "demo_2020",
  "b2ds", "power", "renewablescap", "global", 2020L,    1L,     0,      "demo_2020",
  "b2ds", "power", "renewablescap", "global", 2025L,    4L,   0.3,      "demo_2020"
)

out1 <- target_market_share(
  matched1, 
  ald, 
  scenario, 
  region_isos_demo
)

out2 <- target_market_share(
  matched2, 
  ald, 
  scenario, 
  region_isos_demo
)

# process data for plotting
plot_out1 <- process_input_data(out1)
plot_out2 <- process_input_data(out2)

out1_trajectory <- prepare_for_trajectory_chart(
  plot_out1,
  sector_filter = "power",
  technology_filter = "renewablescap",
  region_filter = "global",
  scenario_source_filter = "demo_2020",
  value_name = "production",
  end_year_filter = 2025,
  normalize_to_start_year = TRUE
)

out2_trajectory <- prepare_for_trajectory_chart(
  plot_out2,
  sector_filter = "power",
  technology_filter = "renewablescap",
  region_filter = "global",
  scenario_source_filter = "demo_2020",
  value_name = "production",
  end_year_filter = 2025,
  normalize_to_start_year = TRUE
)

scenario_specs <- tibble(
  scenario = c("b2ds", "sds", "nps", "worse"),
  color = c("#9CAB7C", "#FFFFCC", "#FDE291", "#E07B73"),
  label = c("B2DS", "SDS", "NPS", "worse")
)

main_line_metric <- tibble(
  metric = "projected",
  label = "Portfolio"
)

additional_line_metrics <- tibble(
  metric = "corporate_economy",
  label = "Corporate Economy"
)

plot_trajectory(
  out1_trajectory,
  scenario_specs_good_to_bad = scenario_specs,
  main_line_metric = main_line_metric,
  additional_line_metrics = additional_line_metrics
) +
  labs(
    title = "Production trajectory",
    subtitle = "Renewables Capacity technology in the Power, sector",
    x = "Year",
    y = "Production rate (normalized to 2020)"
  )
#> Error in plot_trajectory(out1_trajectory, scenario_specs_good_to_bad = scenario_specs, : non-numeric argument to binary operator

plot_trajectory(
  out2_trajectory,
  scenario_specs_good_to_bad = scenario_specs,
  main_line_metric = main_line_metric,
  additional_line_metrics = additional_line_metrics
) +
  labs(
    title = "Production trajectory",
    subtitle = "Renewables Capacity technology in the Power, sector",
    x = "Year",
    y = "Production rate (normalized to 2020)"
  )
#> Error in plot_trajectory(out2_trajectory, scenario_specs_good_to_bad = scenario_specs, : non-numeric argument to binary operator

Created on 2021-05-19 by the reprex package (v2.0.0)

@jdhoffa jdhoffa added enhancement and removed bug an unexpected problem or unintended behavior labels May 19, 2021
@jdhoffa
Copy link
Member

jdhoffa commented May 19, 2021

I have replaced the "bug" label with an "enhancement" label, as this would actually be a shift in the methodology itself.

@jdhoffa
Copy link
Member

jdhoffa commented May 20, 2021

Also as far as acceptance criteria goes, I think this update should include a new Article on the pkgdown site.

@jdhoffa
Copy link
Member

jdhoffa commented May 26, 2021

IMPORTANT: The reprex above does not actually highlight the issue.
Due to a bug in r2dii.plot.static, the labels for "Corporate Economy" and "Projected" are swapped, causing terrible confusion.

The "Corporate Economy" in this case starts at 1 and ends at 1.55 in both plots, as expected.

@maurolepore
Copy link
Contributor

Due to a bug in r2dii.plot.static, the labels for "Corporate Economy" and "Projected" are swapped, causing terrible confusion.

@jdhoffa do we need to report the bug in r2dii.plot.static? It seems a pretty important fix. (cc' @MonikaFu)

@jdhoffa
Copy link
Member

jdhoffa commented May 26, 2021

Yes we do! Sorry, I was meaning to make a reprex and got distracted. Will do so quickly now

@jdhoffa
Copy link
Member

jdhoffa commented Jun 22, 2021

From #316

The corporate economy is not plotted consistently between different scenarios when the portfolio changes.
This is not the case for brown technologies.
attached is an excel that proves this
to be discussed with @Antoine-Lalechere @georgeharris2deg @MonikaFu @jdhoffa

corp.econ_.gren.tech.issue.xlsx

@maurolepore
Copy link
Contributor

@jdhoffa and @MonikaFu is this something we need to fix here, in r2dii.plot or both?

@MonikaFu
Copy link

it needs to be fixed here. That is why we removed related issue from r2dii.plot. The plots will plot anything that comes out of analysis.

@jdhoffa
Copy link
Member

jdhoffa commented Jun 22, 2021

Agreed! And relates (in a way) to #312

@jdhoffa
Copy link
Member

jdhoffa commented Mar 30, 2022

Closed by #383

@jdhoffa jdhoffa closed this as completed Mar 30, 2022
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

No branches or pull requests

4 participants