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

Bug in target_market_share(..., by_company = TRUE, weight_production = FALSE) persists if multiple levels exist in input data #249

Closed
jdhoffa opened this issue Dec 10, 2020 · 0 comments · Fixed by #250
Labels
bug an unexpected problem or unintended behavior

Comments

@jdhoffa
Copy link
Member

jdhoffa commented Dec 10, 2020

The bug wherein the unweighted company results are not equal to the actual company production in the ALD persists. It seems to be duplicating if there are non-unique values of level in the input data, which should not be the case, see reprex below:

Relates to #239
Thanks @georgeharris2deg


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.analysis)

matched <- 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,
  1,                      1,                           "EUR",                       2,                            "EUR",    "UP1", "direct_loantaker",      1, "automotive", "shaanxi auto", "automotive",
  2,                      1,                           "EUR",                       2,                            "EUR",    "UP1",  "ultimate_parent",      1, "automotive", "shaanxi auto", "automotive"
)

ald <- tibble::tribble(
  ~name_company,      ~sector, ~technology, ~year, ~production, ~emission_factor, ~plant_location, ~is_ultimate_owner,
  "shaanxi auto", "automotive",       "ice",  2025,           1,                1,            "BF",               TRUE
)

scenario <- tibble::tribble(
  ~scenario,      ~sector, ~technology,  ~region, ~year, ~tmsr, ~smsp, ~scenario_source,
  "sds", "automotive",       "ice", "global",  2025,   0.5, -0.08,      "demo_2020"
)

out <- target_market_share(
  matched, 
  ald, 
  scenario,
  r2dii.data::region_isos_demo,
  by_company = TRUE, 
  weight_production = FALSE
  )


# I would expect these values to be equal:
ald$production
#> [1] 1

filter(out, metric == "projected") %>% 
  pull(production)
#> [1] 2

Created on 2020-12-10 by the reprex package (v0.3.0)

@maurolepore maurolepore added the bug an unexpected problem or unintended behavior label Dec 10, 2020
maurolepore pushed a commit that referenced this issue Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants