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 3 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 warning generated when user fits model at admin level where no population data exists.
rtesra marked this conversation as resolved.
Show resolved Hide resolved

# naomi 2.10.1

* Patch error in reading `anc_already_art` from Spectrum PJNZ file (was errantly
Expand Down
6 changes: 6 additions & 0 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ 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(any( mf_areas[["area_id"]] %in% unique(population_agesex$area_id) == FALSE)){
rtesra marked this conversation as resolved.
Show resolved Hide resolved
stop(
rtesra marked this conversation as resolved.
Show resolved Hide resolved
"Population data not available for admin level selected for model projections.
Please review model options selection to ensure that area level selection is correct.")
}

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
29 changes: 24 additions & 5 deletions tests/testthat/test-04-model-frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
"Population data not available for admin level selected for model projections.\n 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