-
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
SDA: first year of scenario should determine start of analysis #439
Comments
Seems like it may be a little more complicated than just changing that line, but i am having a look now. |
Ok actually I don't think this requires any action. Notice that in the following reprex, all target values start at the start of the scenario, while all "measured" values (ie. corporate economy and projected values) begin at the first value available. To me this is expected behaviour: 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.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_abcd, ~sector_abcd,
"L162", 1, "EUR", 2, "EUR", "UP1", "ultimate_parent", 1, "automotive", "shaanxi auto", "cement"
)
abcd <- tibble::tribble(
~name_company, ~sector, ~technology, ~year, ~production, ~emission_factor, ~plant_location, ~is_ultimate_owner,
"shaanxi auto", "cement", "ice", 2024, 1, 1, "BF", TRUE,
"shaanxi auto", "cement", "ice", 2025, 1, 1, "BF", TRUE
)
scenario <- tibble::tribble(
~scenario, ~sector, ~region, ~year, ~emission_factor, ~emission_factor_unit, ~scenario_source,
"b2ds", "cement", "global", 2025, 0.5, "tons of CO2 per ton of cement", "demo_2020",
"b2ds", "cement", "global", 2050, 0.2, "tons of CO2 per ton of cement", "demo_2020"
)
out <- target_sda(
matched,
abcd,
scenario,
region_isos = r2dii.analysis:::region_isos_stable
)
out_actual_data <- filter(out, !grepl("target", emission_factor_metric))
min(out_actual_data$year)
#> [1] 2024
out_targets <- filter(out, grepl("target", emission_factor_metric))
min(out_targets$year)
#> [1] 2025 Created on 2023-07-19 with reprex v2.0.2 |
In any case, I have opened #440 to prove in a test that the expected behavior is maintained. |
r2dii.analysis/R/target_sda.R
Line 366 in cd3611c
For the
target_sda()
function the linked line shows that the scenario data is right joined onto the abcd. This means that in case the abcd has values starting in a year earlier than the first scenario year, this year will not be dropped from the analysis and the scenario thus does not determine the start year. Applying an inner join should fix this.For comparison, in
target_market_share()
the following join is used and thus the first year of the scenario data determines the start year:r2dii.analysis/R/join_abcd_scenario.R
Line 65 in cd3611c
Reprex:
The text was updated successfully, but these errors were encountered: