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

Improve population error #453

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: naomi
Title: Naomi Model for Subnational HIV Estimates
Version: 2.10.1
Version: 2.10.2
Authors@R:
person(given = "Jeff",
family = "Eaton",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# naomi 2.10.2

* Improve error generated when user fits model at admin level where no population data exists.

# naomi 2.10.1

* Patch error in reading `anc_already_art` from Spectrum PJNZ file (was errantly
Expand Down
4 changes: 4 additions & 0 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ naomi_model_frame <- function(area_merged,
## of a Spectrum file and then calibrated. Currently no way to know if areas
## comparise only part of a Spectrum file, so can't address.

if (!all(mf_areas[["area_id"]] %in% unique(population_agesex$area_id))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the error message is about the area level selected, why is the conditional here referring to the area IDs (not the area level)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't area level available in the population data to easier to check that these intersect and then pull that in if they don't for the error message if needed

stop(t_("MISSING_POPULATION_LEVEL"))
}

pop_subset <- dplyr::filter(population_agesex, area_id %in% mf_areas[["area_id"]])
pop_t1 <- interpolate_population_agesex(pop_subset, calendar_quarter1)
pop_t2 <- interpolate_population_agesex(pop_subset, calendar_quarter2)
Expand Down
5 changes: 3 additions & 2 deletions inst/traduire/en-translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"PROGRESS_CALIBRATE": "Calibrating outputs - {{elapsed}} elapsed",
"PROGRESS_CALIBRATE_SAVE_OUTPUT": "Saving outputs - {{elapsed}} elapsed",
"PROGRESS_CALIBRATE_GENERATE_REPORT": "Generating report - {{elapsed}} elapsed",
"NO_ART_DATA_FOR_QUARTER": "No ART data found for quarter {{calendar_quarter}}.\nSet 'Include ART data' to 'No' if you intend to include no ART data.",
"NO_ART_DATA_FOR_QUARTER": "No ART data found for quarter {{calendar_quarter}}.\nIf you do not intend to include ART data set 'Include ART data' to 'No'.",
"ANC_ON_ART_GREATER_THAN_TOTAL_POSITIVE": "ANC testing on ART greater than ANC testing total positive.",
"ANC_DATA_MISSING_FOR_YEAR": "ANC testing data not found for year {{missing_year}}.",
"ANC_DATA_MISSING_FOR_YEAR_PLURAL": "ANC testing data not found for years {{missing_year}}.",
Expand Down Expand Up @@ -275,5 +275,6 @@
"DOWNLOAD_COMPARISON_DESCRIPTION": "Naomi comparison report uploaded from Naomi web app",
"DOWNLOAD_AGYW_DESCRIPTION": "Naomi AGYW tool uploaded from Naomi web app",
"NUMBER_ON_ART": "Number on ART",
"NUMBER_ON_ART_DESC": "Number on ART description"
"NUMBER_ON_ART_DESC": "Number on ART description",
"MISSING_POPULATION_LEVEL": "Population data not available for admin level selected for model projections. Please review model options selection to ensure that area level selection is correct."
}
3 changes: 2 additions & 1 deletion inst/traduire/fr-translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,6 @@
"DOWNLOAD_SUMMARY_DESCRIPTION": "Rapport de synthèse Naomi téléchargé depuis l'application web Naomi",
"DOWNLOAD_COMPARISON_DESCRIPTION": "Rapport de comparaison Naomi téléchargé à partir de l'application web Naomi",
"NUMBER_ON_ART": "Nombre de personnes sous TARV",
"NUMBER_ON_ART_DESC": "Number on ART description"
"NUMBER_ON_ART_DESC": "Number on ART description",
"MISSING_POPULATION_LEVEL": "Les données de population ne sont pas disponibles pour le niveau admin sélectionné pour les projections du modèle. Veuillez revoir la sélection des options du modèle pour vous assurer que la sélection du niveau de la zone est correcte."
}
3 changes: 2 additions & 1 deletion inst/traduire/pt-translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,6 @@
"DOWNLOAD_SUMMARY_DESCRIPTION": "Relatório de síntese da Naomi carregado da aplicação web Naomi",
"DOWNLOAD_COMPARISON_DESCRIPTION": "Relatório de comparação Naomi carregado a partir da aplicação web Naomi",
"NUMBER_ON_ART": "Nombre de personnes sous TARV",
"NUMBER_ON_ART_DESC": "Number on ART description"
"NUMBER_ON_ART_DESC": "Number on ART description",
"MISSING_POPULATION_LEVEL": "Os dados da população não estão disponíveis para o nível administrativo selecionado para as projecções do modelo. Rever a seleção das opções do modelo para garantir que a seleção do nível de área está correta."
}
31 changes: 25 additions & 6 deletions tests/testthat/test-04-model-frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test_that("artnum_mf() returns expected number of records", {

test_that("artnum_mf() throws errors for invalid inputs", {
expect_error(artnum_mf("CY1924Q4", demo_art_number, a_naomi_mf),
"No ART data found for quarter CY1924Q4.\nSet 'Include ART data' to 'No' if you intend to include no ART data.")
"No ART data found for quarter CY1924Q4.\nIf you do not intend to include ART data set 'Include ART data' to 'No'.")
expect_error(artnum_mf("CY2016Q1", demo_art_number, "jibberish"))
expect_error(artnum_mf(c("CY2016Q1", "CY2016Q2"), demo_art_number, "jibberish"))
})
Expand All @@ -53,7 +53,26 @@ test_that("artnum_mf() works with single quarter ART data", {
})


test_that("Informative error displayed when model run to admin level higher/lower than population data supplied", {
x <- expect_error(
naomi_model_frame(a_area_merged,
demo_population_agesex,
a_spec,
scope = "MWI",
level = 3,
calendar_quarter1 = "CY2016Q1",
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3"))

expect_equal(
x$message,
paste("Population data not available for admin level selected",
"for model projections. Please review model options",
"selection to ensure that area level selection is correct.")
)
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could the error message here quote the area level and area level label selected?

"Population data not available for selected area level 3 (District). Pleas review model options"

Also I'm think I would remove the "for model projections". We usually use "projections" to refer to the T3/T4/T5 projection, but here this area level selection pertains to everything.


test_that("population calibration options", {

Expand Down Expand Up @@ -85,7 +104,7 @@ test_that("population calibration options", {
mf_none$mf_model$population_t2 +
mf_none$mf_model$population_t3 +
mf_none$mf_model$population_t4 +
mf_none$mf_model$population_t5
mf_none$mf_model$population_t5
),
sum(mf_none$spectrum_calibration$population_raw))

Expand All @@ -102,7 +121,7 @@ test_that("population calibration options", {
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
calendar_quarter5 = "CY2023Q3",
spectrum_population_calibration = "national")

expect_false(sum(mf_nat$spectrum_calibration$population_raw) ==
Expand Down Expand Up @@ -132,7 +151,7 @@ test_that("population calibration options", {
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
calendar_quarter5 = "CY2023Q3",
spectrum_population_calibration = "subnational")

expect_false(sum(mf_subnat$spectrum_calibration$population_raw) ==
Expand Down Expand Up @@ -162,7 +181,7 @@ test_that("population calibration options", {
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
calendar_quarter5 = "CY2023Q3",
spectrum_population_calibration = "jibberish"),
"spectrum_calibration_option \"jibberish\" not found."
)
Expand Down Expand Up @@ -319,7 +338,7 @@ test_that("naomi_model_frame() interpolated population depends on quarter specif
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
calendar_quarter5 = "CY2023Q3",
spectrum_population_calibration = "subnational")


Expand Down
Loading