-
Notifications
You must be signed in to change notification settings - Fork 7
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
target_market_share function generates wrong "projected" scenario #288
Comments
I'm guessing this was intended for https://github.com/2DegreesInvesting/r2dii.analysis? Maybe @maurolepore can transfer it there? |
Thanks @KapitanKombajn and @cjyetman |
@KapitanKombajn thanks a lot for reporting this issue. The main maintainer of this package (@jdhoffa) is likely busy but I could help if you are kind enough to reword your comment to clarify (a) what output you expected, and (b) what output you got instead. I would also be super helpful if you could convert your example in a reprex. Here is a template you could adapt (and maybe paste inside library(dplyr, warn.conflicts = FALSE)
library(r2dii.data)
library(r2dii.match)
library(r2dii.analysis)
# TODO: Adapt to fake the problematic input
single_company <- 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,
"L162", 1, "EUR", 2, "EUR", "UP1", "ultimate_parent", 1, "automotive", "shaanxi auto", "automotive"
)
# TODO: Adapt to fake the problematic input
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
)
# TODO: Adapt to fake the problematic input
scenario <- tibble::tribble(
~scenario, ~sector, ~technology, ~region, ~year, ~tmsr, ~smsp, ~scenario_source,
"sds", "automotive", "ice", "global", 2025, 0.5, -0.08, "demo_2020"
)
# TODO: Adapt to fake the problematic input
regions <- tibble::tribble(
~region, ~isos, ~source,
"global", "bf", "demo_2020"
)
out <- target_market_share(
ald = ald,
scenario = scenario,
region_isos = regions,
# With this arguments
data = single_company,
by_company = TRUE,
weight_production = FALSE
)
# TODO: Complete
# I expected the output to be ...
# Instead the output is ...
out
#> # A tibble: 3 x 11
#> sector technology year region scenario_source name_ald sector_weighted_p…
#> <chr> <chr> <dbl> <chr> <chr> <chr> <dbl>
#> 1 automot… ice 2025 global demo_2020 shaanxi a… 1
#> 2 automot… ice 2025 global demo_2020 shaanxi a… 1
#> 3 automot… ice 2025 global demo_2020 corporate… NA
#> # … with 4 more variables: technology_weighted_production <dbl>, metric <chr>,
#> # production <dbl>, technology_share <dbl> Created on 2021-04-29 by the reprex package (v2.0.0) |
Hi @maurolepore, sorry for not being clear enough. Here's my rewritten example: library(r2dii.data)
library(r2dii.match)
library(r2dii.analysis)
library(dplyr, warn.conflicts = FALSE)
library(tidyverse)
#test datasets
your_loanbook <- loanbook_demo
your_ald <- ald_demo
matched <- match_name(loanbook_demo, ald_demo) %>%
prioritize()
#select only one company to ease presentation
matched <- matched[matched$name_direct_loantaker=='Toyota Motor Corporation',]
#calculate results
market_share_targets_company<- matched %>%
target_market_share(
ald = ald_demo,
scenario = scenario_demo_2020,
region_isos = region_isos_demo,
by_company = TRUE,
weight_production = FALSE
)
tech_mix_data <- market_share_targets_company %>%
filter(
sector == "automotive",
region == "global",
metric == "projected",
scenario_source =='demo_2020'
)
#recalculation of technology_share
tmp<-aggregate(tech_mix_data$production, by=list(year=tech_mix_data$year), sum)
colnames(tmp)<-c("year", "total_production")
tech_mix_data_corrected<- merge(tech_mix_data,tmp)
tech_mix_data_corrected$technology_share_expected<- tech_mix_data_corrected$production/tech_mix_data_corrected$total_production
#graph of the original data (technology share is wrong starting from year 2021)
ggplot(
data = tech_mix_data_corrected,
mapping = aes(
x = year,
y = technology_share,
fill = technology
)
) +
geom_col(position='fill')+
geom_text(aes(label=round(technology_share,2)), position="stack") +
labs(x = "Production metric", y = "Technology Share [%]") #graph of the corrected data
ggplot(
data = tech_mix_data_corrected,
mapping = aes(
x = year,
y = technology_share_expected,
fill = technology
)
) +
geom_col(position='fill')+
geom_text(aes(label=round(technology_share_expected,2)), position="stack") +
labs(x = "Production metric", y = "Technology Share [%]") Created on 2021-04-30 by the reprex package (v2.0.0) |
Hi, I just wanted to ask if this fix is live already or not yet? I just reran the above reprex but unfortunatelly it still generates wrong results. |
We have not released the update to CRAN yet, we are aiming to fix another bug before we release it. |
Got it. Thanks! |
FYI the package is now uploaded to CRAN and you should see the changes! |
Hi,
I believe, function target_market_share generates wrong technology_share values for „projected” metric, when the following conditions are met:
In such situation, the technology_share for each technology is the same (for example, if in ALD dataset, a company has some capacity in 4 technologies within a given sector in year t, its capacity in year t+1 will be 25% for each technology, no matter what the starting share was in year t).
Example code (based on documentation), where each out of 3 technologies has 0.33 share:
The text was updated successfully, but these errors were encountered: