Skip to content

ctry-specific model#5

Open
klau506 wants to merge 20 commits into
mainfrom
rhap_FEimprovement
Open

ctry-specific model#5
klau506 wants to merge 20 commits into
mainfrom
rhap_FEimprovement

Conversation

@klau506

@klau506 klau506 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Objective: FE model improvement considering each model separately. The idea is to loop across all countries (indicated by the user, "All" by default) to fit and use for prediction ctry-specific models. The predicted vs actual values plot is awasome. The RMSE values are around 0.1 everywhere
FE_all_ctries_new.pdf

@klau506
klau506 requested a review from jonsampedro July 15, 2026 09:42

@jonsampedro jonsampedro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casi todo son comentarios menores, pero el tema del HIA_Adder es incrrecto y hay que quitralo... comentamos!

@@ -1,49 +1,74 @@
name: build

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Algo le pasa a esta acción que no la pasa (Ubuntu)

@@ -1,26 +1,21 @@
name: test_coverage

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo mismo, da algún error esta acción

Comment thread R/calc_hap_impacts.R
years_in_prj <- listYears(prj)
years_in_prj <- years_in_prj[!is.na(years_in_prj)]
years_in_prj <- setdiff(years_in_prj, NA)
base_year <- dplyr::if_else(2021 %in% years_in_prj, 2021, 2015)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Con esto se supone que funciona para GCAM (>7.0) que tenga o BY 2021 o 2015, no? Igual poner una nota?

Comment thread R/calc_hap_impacts.R Outdated
Comment thread R/calc_hap_impacts.R Outdated
Comment thread R/calc_hap_impacts.R Outdated
Comment thread R/calc_hap_impacts.R
# Get model to subtract coefficients and predict
fit_model_output_c <- fit_model(HIA_var = HIA_var, countries = c)
# Safe check for non-complete country datasets
if (is.null(fit_model_output_c) || length(fit_model_output_c) == 0) next

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se salta el país que no tiene datos para hacer el modelo no? Por curiosidad, podemos ver si esto pasa en muchos sitios con el actual panel data?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pasa en
[1] "Bahamas"
[1] "Belize"
[1] "Bhutan"
[1] "Brunei Darussalam"
[1] "Eritrea"
[1] "Fiji"
[1] "Grenada"
[1] "Guyana"
[1] "Kiribati"
[1] "Maldives"
[1] "Papua New Guinea"
[1] "Solomon Islands"
[1] "Somalia"
[1] "Sudan"
[1] "Suriname"
[1] "Tonga"
[1] "Vanuatu"

les faltan datos de gdp

Comment thread R/calc_hap_impacts.R
output_fin_c <- output_c %>%
dplyr::mutate(pred_var = paste0("pred_log_", HIA_var, "_per_100K")) %>%
gcamdata::left_join_error_no_match(
rhap::hia_adder %>%

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto es lo que creo que hay que cambiar: el hia_ader era un ajuste que se hacía con el modelo global (que ya no usamos):

bias.adder = deaths observadas en 2020 - estimadas en 2020 con el modelo global

Luego se lo sumabamos aquí por mejorar la estimación, pero al usar el fit_model por cada país esto solo va a distrsionar los resultados. creo que hay que uquitar esta parte, borrar este input de hia_adder del data del paquete y ver si queremos usar un bias.adder en nuestras proyecciones, pero en todo caso un adder calculado en cada pais con el modelo del pais!

Comment thread R/calc_hap_impacts.R
pred_var = gsub("log_", "", pred_var)
) %>%
dplyr::mutate(
pred_value_per_100K_adj = pred_value_per_100K + bias.adder,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto hay que quitar!

Comment thread R/calc_hap_impacts.R
# Restrict data to selected countries
if (countries != 'All') output_gr <- output_gr %>% dplyr::filter(country_name %in% countries)

output.panel.gr <- plm::pdata.frame(output_gr, index = c("country_name", "year"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No puedo ver si en el "by group" stá el hia adder pero no sería correcto tampoco aquí

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.73239% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.32%. Comparing base (eb224b8) to head (805a3ba).

Files with missing lines Patch % Lines
R/calc_hap_impacts.R 87.32% 27 Missing ⚠️
R/utils.R 83.33% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #5      +/-   ##
==========================================
- Coverage   87.36%   87.32%   -0.04%     
==========================================
  Files           7        8       +1     
  Lines        1171     1341     +170     
==========================================
+ Hits         1023     1171     +148     
- Misses        148      170      +22     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Successfully merging this pull request may close these issues.

2 participants