Skip to content

Commit

Permalink
Make age upper bound check for WFA exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkschumacher committed Jan 23, 2025
1 parent 4e6a764 commit 89ce7fd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# anthroplus (development version)

* Increased the upper age limit to 229 months exclusive
from 228 months inclusive.
from 228 months inclusive. Also the upper age limit of 120 months
for WFA is now exlusive.

# anthroplus 1.0.0

Expand Down
4 changes: 2 additions & 2 deletions R/prevalence.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ anthroplus_prevalence <- function(sex,
name = "WA", column = "wfa",
with_cutoffs = TRUE, with_auxiliary_zscore_column = TRUE,
auxiliary_zscore_condition = function(dataframe) {
# for wfa the age limit is 120 and thus below 228.
# for wfa the age limit is 120 and thus below 229
# we need to make sure z-scores are only set to -3.1 if the age is
# in range
dataframe[["age_in_months"]] <= WFA_UPPER_AGE_LIMIT &
dataframe[["age_in_months"]] < WFA_UPPER_AGE_LIMIT &
dataframe[["oedema"]] %in% "y"
}
),
Expand Down
8 changes: 2 additions & 6 deletions R/zscores.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ zscore_weight_for_age <- function(sex, age_in_months, oedema,
zscore_indicator(sex, age_in_months, weight,
wfa_growth_standards,
age_upper_bound = WFA_UPPER_AGE_LIMIT,
age_comparison_fun = `<=`,
zscore_fun = anthro_api_compute_zscore_adjusted
)
}
Expand All @@ -156,7 +155,6 @@ zscore_height_for_age <- function(sex, age_in_months,
zscore_indicator(sex, age_in_months, height,
hfa_growth_standards,
age_upper_bound = 229,
age_comparison_fun = `<`,
zscore_fun = anthro_api_compute_zscore
)
}
Expand All @@ -168,7 +166,6 @@ zscore_bmi_for_age <- function(sex, age_in_months, oedema,
zscore_indicator(sex, age_in_months, bmi,
bfa_growth_standards,
age_upper_bound = 229,
age_comparison_fun = `<`,
zscore_fun = anthro_api_compute_zscore_adjusted
)
}
Expand All @@ -178,8 +175,7 @@ zscore_indicator <- function(sex,
measure,
growth_standards,
age_upper_bound,
zscore_fun,
age_comparison_fun = `<=`) {
zscore_fun) {
low_age <- trunc(age_in_months)
upp_age <- trunc(age_in_months + 1)
diff_age <- age_in_months - low_age
Expand Down Expand Up @@ -219,7 +215,7 @@ zscore_indicator <- function(sex,
}
zscores <- zscore_fun(measure, m, l, s)
has_invalid_valid_age <- is.na(age_in_months) |
!(age_in_months >= 60 & age_comparison_fun(age_in_months, age_upper_bound))
!(age_in_months >= 60 & age_in_months < age_upper_bound)
zscores[has_invalid_valid_age] <- NA_real_
zscores
}
6 changes: 3 additions & 3 deletions tests/testthat/test-zscores.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ test_that("input validations work as expected", {
})

test_that("oedema = y implies NA for weight-for-age and bmi-for-age", {
res1 <- anthroplus_zscores(1, 120,
res1 <- anthroplus_zscores(1, 119,
oedema = 1, height_in_cm = 60, weight_in_kg = 30
)
res2 <- anthroplus_zscores(1, 120,
res2 <- anthroplus_zscores(1, 119,
oedema = 2, height_in_cm = 60, weight_in_kg = 30
)
expect_true(is.na(res1$zwfa))
Expand All @@ -117,7 +117,7 @@ test_that("oedema = y implies NA for weight-for-age and bmi-for-age", {

test_that("age upper bounds are exclusive", {
res <- anthroplus_zscores(
1, c(120, 228.5, 120.1, 229),
1, c(119.9, 228.5, 120, 229),
height_in_cm = 60,
weight_in_kg = 30
)
Expand Down

0 comments on commit 89ce7fd

Please sign in to comment.