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

feat: loanbook_demo drops columns that are not crucial to r2dii.analysis functions #257

Closed
jdhoffa opened this issue Sep 2, 2021 · 3 comments · Fixed by #374
Closed
Labels
ADO Add issue to ADO feature a feature request or enhancement priority upkeep maintenance, infrastructure, and similar

Comments

@jdhoffa
Copy link
Member

jdhoffa commented Sep 2, 2021

Relates to feedback from a bank.
Since our data preparation guidance is to prepare input data exactly as loanbook_demo, we should either:

  • Keep all columns that are currently in loanbook_demo, but indicate which are actually crucial to target_market_share and target_sda
    OR
  • Remove the non-crucial columns

AB#10167

@maurolepore
Copy link
Contributor

Note we have r2dii.match::crucial_lbk() but those are the minimum columns you need to run r2dii.match::match_name() -- it fails with prioritize() and thus with anything downstream.

Maybe we should modify crucial_lbk()?

library(dplyr, warn.conflicts = FALSE)
library(r2dii.data)
library(r2dii.match)

loanbook <- r2dii.data::loanbook_demo
ald <- r2dii.data::ald_demo

crucial_lbk()
#> [1] "id_ultimate_parent"                    
#> [2] "name_ultimate_parent"                  
#> [3] "id_direct_loantaker"                   
#> [4] "name_direct_loantaker"                 
#> [5] "sector_classification_system"          
#> [6] "sector_classification_direct_loantaker"

matched_crucial <- loanbook %>% 
  select(crucial_lbk()) %>% 
  match_name(ald)

try(prioritize(matched_crucial))
#> Error : Must have missing names:
#> `id_loan`

Created on 2021-09-02 by the reprex package (v2.0.1)

@jdhoffa jdhoffa added the feature a feature request or enhancement label Apr 14, 2023
@jdhoffa jdhoffa added upkeep maintenance, infrastructure, and similar ADO Add issue to ADO labels Feb 6, 2024
@jdhoffa jdhoffa self-assigned this Feb 6, 2024
@jdhoffa jdhoffa removed the ADO Add issue to ADO label Mar 6, 2024
@jdhoffa jdhoffa changed the title Reduce loanbook_demo to only columns that are absolutely crucial to r2dii.analysis functions feat: loanbook_demo drops columns that are not crucial to r2dii.analysis functions Mar 6, 2024
@jdhoffa jdhoffa added the ADO Add issue to ADO label Mar 6, 2024
@jdhoffa
Copy link
Member Author

jdhoffa commented Mar 20, 2024

Note that these seem to be the crucial columns:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(r2dii.data)
library(r2dii.match)
library(r2dii.analysis)
library(r2dii.plot)

loanbook <- dplyr::select(
  loanbook_demo,
  c(
    "id_loan",
    "id_direct_loantaker",
    "name_direct_loantaker",
    # "id_intermediate_parent_1",
    # "name_intermediate_parent_1",
    "id_ultimate_parent",
    "name_ultimate_parent",
    "loan_size_outstanding",
    "loan_size_outstanding_currency",
    "loan_size_credit_limit",
    "loan_size_credit_limit_currency",
    "sector_classification_system",
    # "sector_classification_input_type",
    "sector_classification_direct_loantaker",
    # "fi_type",
    # "flag_project_finance_loan",
    # "name_project",
    "lei_direct_loantaker", # optional, but may be used as a `join_id`
    "isin_direct_loantaker" # optional, but may be used as a `join_id`
    )
)

matched <- loanbook |> 
  match_name(abcd_demo) |> 
  prioritize()
  
matched |> 
  target_market_share(abcd_demo, scenario_demo_2020, region_isos_demo) |> 
  filter(sector == "power", region == "global", technology == "renewablescap") |> 
  prep_trajectory() |> 
  plot_trajectory()

matched |> 
  target_sda(
    abcd_demo, 
    co2_intensity_scenario_demo, 
    region_isos = region_isos_demo
    ) |> 
  filter(sector == "cement", region == "global") |> 
  prep_emission_intensity() |> 
  plot_emission_intensity()
#> Warning: Removing rows in abcd where `emission_factor` is NA

Created on 2024-03-20 with reprex v2.1.0

@jacobvjk
Copy link
Member

making this a priority so we can solve the connected issue #372 too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADO Add issue to ADO feature a feature request or enhancement priority upkeep maintenance, infrastructure, and similar
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants