Skip to content

Commit 1fbba90

Browse files
Merge pull request #5 from WorldHealthOrganization/month60
Add the ability to analyze observations with age = 60 months
2 parents fd5098e + 6be800e commit 1fbba90

15 files changed

+91
-46
lines changed

.github/workflows/R-CMD-check.yaml

+9-12
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
33
on:
44
push:
5-
branches: [main, master]
5+
branches: [main]
66
pull_request:
7-
branches: [main, master]
7+
branches: [main]
88

99
name: R-CMD-check
1010

@@ -29,18 +29,15 @@ jobs:
2929
R_KEEP_PKG_SOURCE: yes
3030

3131
steps:
32-
- uses: actions/checkout@v2
33-
34-
- uses: r-lib/actions/setup-pandoc@v1
35-
36-
- uses: r-lib/actions/setup-r@v1
32+
- uses: actions/checkout@v4
33+
- uses: r-lib/actions/setup-pandoc@v2
34+
- uses: r-lib/actions/setup-r@v2
3735
with:
3836
r-version: ${{ matrix.config.r }}
3937
http-user-agent: ${{ matrix.config.http-user-agent }}
4038
use-public-rspm: true
41-
42-
- uses: r-lib/actions/setup-r-dependencies@v1
39+
- uses: r-lib/actions/setup-r-dependencies@v2
4340
with:
44-
extra-packages: rcmdcheck
45-
46-
- uses: r-lib/actions/check-r-package@v1
41+
extra-packages: any::rcmdcheck
42+
needs: check
43+
- uses: r-lib/actions/check-r-package@v2

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Description: Provides WHO 2007 References for School-age Children and
1818
License: GPL (>= 3)
1919
Encoding: UTF-8
2020
Roxygen: list(markdown = TRUE)
21-
RoxygenNote: 7.1.2
21+
RoxygenNote: 7.3.2
2222
Depends:
2323
R (>= 3.5.0)
2424
Imports:

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# anthroplus (development version)
22

3+
* The package now supports observations with age >= 60 months. Previously there
4+
was a cutoff at 61 months excluding observations with 60 months.
5+
36
# anthroplus 0.9.0
47

58
* Initial release

R/prevalence.R

+13-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#' If not all parameter values have equal length, parameter values will be
2121
#' repeated to match the maximum length.
2222
#'
23-
#' Only cases with age_in_months between 61 (including) and 228 months
23+
#' Only cases with age_in_months between 60 (including) and 228 months
2424
#' (including) are used for the analysis. The rest will be ignored.
2525
#'
2626
#' @inheritParams anthroplus_zscores
@@ -88,7 +88,7 @@
8888
#'
8989
#' Note that weight-for-age results are NA for the groups "All" and the two
9090
#' "Sex" groups, as the indicator is only defined for age in months
91-
#' between 61 and 120.
91+
#' between 60 and 120.
9292
#'
9393
#' @examples
9494
#' set.seed(1)
@@ -132,18 +132,18 @@ anthroplus_prevalence <- function(sex,
132132
}
133133
old_rows <- nrow(input)
134134
input <- input[!is.na(input$age_in_months) &
135-
input$age_in_months >= 61 &
135+
input$age_in_months >= 60 &
136136
input$age_in_months <= 228, , drop = FALSE]
137137
if (nrow(input) == 0) {
138138
stop(
139-
"All age values are either NA or < 61 or > 228, which excludes all",
139+
"All age values are either NA or < 60 or > 228, which excludes all",
140140
" cases from the analysis.",
141141
call. = FALSE
142142
)
143143
} else if (nrow(input) < old_rows) {
144144
warning(
145145
old_rows - nrow(input),
146-
" row(s) with age NA or age < 61 months or > 228 months were excluded",
146+
" row(s) with age NA or age < 60 months or > 228 months were excluded",
147147
" from the computation."
148148
)
149149
}
@@ -246,8 +246,8 @@ cbind_year_month_columns <- function(prev_results) {
246246
"Total (15-19)", "Total (15-19)" # female/male 3
247247
),
248248
`Months` = c(
249-
"(61-228)",
250-
"(61-228)", "(61-228)",
249+
"(60-228)",
250+
"(60-228)", "(60-228)",
251251
paste0("(", gsub(" mo", "", prev_age_group_labels, fixed = TRUE), ")"),
252252
wider_labels,
253253
c(wider_labels[1], wider_labels[1]),
@@ -265,7 +265,7 @@ cbind_year_month_columns <- function(prev_results) {
265265
}
266266

267267
prev_age_group_labels <- c(
268-
"61-71 mo",
268+
"60-71 mo",
269269
"72-83 mo",
270270
"84-95 mo",
271271
"96-107 mo",
@@ -281,10 +281,11 @@ prev_age_group_labels <- c(
281281
"216-227 mo",
282282
"228-228 mo"
283283
)
284+
284285
prev_age_groups <- function(age_in_months) {
285286
stopifnot(is.numeric(age_in_months), all(age_in_months <= 228, na.rm = TRUE))
286287
cut_breaks <- c(
287-
61, 72, 84, 96, 108, 120, 132,
288+
60, 72, 84, 96, 108, 120, 132,
288289
144, 156, 168, 180, 192, 204, 216, 228, 229
289290
)
290291
cut(age_in_months,
@@ -295,13 +296,14 @@ prev_age_groups <- function(age_in_months) {
295296
}
296297

297298
prev_wider_age_group_labels <- c(
298-
"61-119 mo",
299+
"60-119 mo",
299300
"120-179 mo",
300301
"180-228 mo"
301302
)
303+
302304
prev_wider_age_groups <- function(age_in_months) {
303305
stopifnot(is.numeric(age_in_months), all(age_in_months <= 228, na.rm = TRUE))
304-
cut_breaks <- c(61, 120, 180, 229)
306+
cut_breaks <- c(60, 120, 180, 229)
305307
cut(age_in_months,
306308
breaks = cut_breaks,
307309
labels = prev_wider_age_group_labels,

R/sysdata.rda

66 Bytes
Binary file not shown.

R/zscores.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
#' @details
3131
#' The following age cutoffs are used:
3232
#' \itemize{
33-
#' \item{Height-for-age} age between 61 and 228 months inclusive
34-
#' \item{Weight-for-age} age between 61 and 120 months inclusive
35-
#' \item{BMI-for-age} age between 61 and 228 months inclusive
33+
#' \item{Height-for-age} age between 60 and 228 months inclusive
34+
#' \item{Weight-for-age} age between 60 and 120 months inclusive
35+
#' \item{BMI-for-age} age between 60 and 228 months inclusive
3636
#' }
3737
#'
3838
#' @return A data.frame with three types of columns. Columns starting with a
@@ -215,7 +215,7 @@ zscore_indicator <- function(sex,
215215
}
216216
zscores <- zscore_fun(measure, m, l, s)
217217
has_invalid_valid_age <- is.na(age_in_months) |
218-
!(age_in_months >= 61 & age_in_months <= age_upper_bound)
218+
!(age_in_months >= 60 & age_in_months <= age_upper_bound)
219219
zscores[has_invalid_valid_age] <- NA_real_
220220
zscores
221221
}

data-raw/growthstandards/bfawho2007.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sex age l m s
2+
1 60 -0.7151 15.2679 0.08366
23
1 61 -0.7387 15.2641 0.08390
34
1 62 -0.7621 15.2616 0.08414
45
1 63 -0.7856 15.2604 0.08439
@@ -168,6 +169,7 @@ sex age l m s
168169
1 227 -0.8578 22.1514 0.12939
169170
1 228 -0.8419 22.1883 0.12948
170171
1 229 -0.8419 22.1883 0.12948
172+
2 60 -0.8702 15.2453 0.09646
171173
2 61 -0.8886 15.2441 0.09692
172174
2 62 -0.9068 15.2434 0.09738
173175
2 63 -0.9248 15.2433 0.09783

data-raw/growthstandards/hfawho2007.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sex age l m s
2+
1 60 1 109.7265 0.04156
23
1 61 1 110.2647 0.04164
34
1 62 1 110.8006 0.04172
45
1 63 1 111.3338 0.04180
@@ -168,6 +169,7 @@ sex age l m s
168169
1 227 1 176.5211 0.04142
169170
1 228 1 176.5432 0.04134
170171
1 229 1 176.5432 0.04134
172+
2 60 1 109.0725 0.04346
171173
2 61 1 109.6016 0.04355
172174
2 62 1 110.1258 0.04364
173175
2 63 1 110.6451 0.04373

data-raw/growthstandards/package.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ check_df <- function(df) {
22
stopifnot(all(colnames(df) == c("sex", "age", "l", "m", "s")))
33
stopifnot(all(apply(df, 2, is.numeric)))
44
stopifnot(all(df[["sex"]] %in% c(1, 2)))
5-
stopifnot(all(df[["age"]] > 60))
5+
stopifnot(all(df[["age"]] >= 60))
66
}
77

88
bfa_growth_standards <- read.csv("data-raw/growthstandards/bfawho2007.txt", sep = "\t")

data-raw/growthstandards/wfawho2007.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sex age l m s
2+
1 60 -0.1922 18.3328 0.12947
23
1 61 -0.2026 18.5057 0.12988
34
1 62 -0.2130 18.6802 0.13028
45
1 63 -0.2234 18.8563 0.13067
@@ -60,6 +61,7 @@ sex age l m s
6061
1 119 -0.6752 30.8854 0.16213
6162
1 120 -0.6764 31.1586 0.16305
6263
1 121 -0.6764 31.1586 0.16305
64+
2 60 -0.4650 18.0823 0.14240
6365
2 61 -0.4681 18.2579 0.14295
6466
2 62 -0.4711 18.4329 0.14350
6567
2 63 -0.4742 18.6073 0.14404

data-raw/test-data.R

-8
This file was deleted.

man/anthroplus_prevalence.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/anthroplus_zscores.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-prevalence.R

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ test_that("strata are considered correctly", {
3232
check_with_survey(input, strata = strata)
3333
})
3434

35-
test_that("age only between 61 and 229 is considered", {
35+
test_that("age only between 60 and 229 is considered", {
3636
input <- readRDS("test_dataset_who2007.rds")
3737
input$agemons <- input$agemons * 2
38-
input_filtered <- input[input$agemons >= 61 & input$agemons <= 228, ]
38+
input_filtered <- input[input$agemons >= 60 & input$agemons <= 228, ]
3939
expect_warning(
4040
res1 <- anthroplus_prevalence(
4141
input$sex,
@@ -88,7 +88,7 @@ test_that("it fails if all values are filtered out", {
8888
expect_error(
8989
anthroplus_prevalence(
9090
1,
91-
60,
91+
59,
9292
"n",
9393
100,
9494
35,
@@ -212,3 +212,8 @@ test_that("age in months = 228 is part of the age group", {
212212
expect_false(is.na(prev_wider_age_groups(228)))
213213
expect_false(is.na(prev_age_groups(228)))
214214
})
215+
216+
test_that("age in months = 60 is part of the age group", {
217+
expect_false(is.na(prev_wider_age_groups(60)))
218+
expect_false(is.na(prev_age_groups(60)))
219+
})

tests/testthat/test-zscores.R

+41-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ test_that("zscore references match from previous implementation", {
2424
expect_equal(result$age_in_months, data$agemons)
2525
})
2626

27+
test_that("computes correct value for age ~ 60 months", {
28+
res <- anthroplus_zscores(
29+
sex = c(2, 2),
30+
age_in_months = c(60.32, 60.911701),
31+
height_in_cm = c(113.8, 113.6),
32+
weight_in_kg = c(18.7, 20.5)
33+
)
34+
expect_equal(res$zwfa, c(0.21, 0.79))
35+
expect_equal(res$fwfa, c(0, 0))
36+
expect_equal(res$zbfa, c(-0.58, 0.42))
37+
expect_equal(res$fbfa, c(0, 0))
38+
expect_equal(res$zhfa, c(0.96, 0.85))
39+
expect_equal(res$fhfa, c(0, 0))
40+
})
41+
2742
test_that("different sex encodings work", {
2843
expect_equal(
2944
anthroplus_zscores(1, 120, height_in_cm = 60, weight_in_kg = 30),
@@ -104,7 +119,7 @@ test_that("oedema = y implies NA for weight-for-age and bmi-for-age", {
104119
expect_false(is.na(res2$fbfa))
105120
})
106121

107-
test_that("Age upper bounds are inclusive", {
122+
test_that("age upper bounds are inclusive", {
108123
res <- anthroplus_zscores(
109124
1, c(120, 228, 120.1, 228.1),
110125
height_in_cm = 60,
@@ -114,3 +129,28 @@ test_that("Age upper bounds are inclusive", {
114129
expect_equal(is.na(res$zwfa), c(FALSE, TRUE, TRUE, TRUE))
115130
expect_equal(is.na(res$zbfa), c(FALSE, FALSE, FALSE, TRUE))
116131
})
132+
133+
test_that("age >= 60 months is supported", {
134+
res <- anthroplus_zscores(
135+
1, 60,
136+
height_in_cm = 60,
137+
weight_in_kg = 30
138+
)
139+
expect_false(is.na(res$zhfa))
140+
expect_false(is.na(res$zwfa))
141+
expect_false(is.na(res$zbfa))
142+
})
143+
144+
test_that("age < 60 months results in all NA scores and flags", {
145+
res <- anthroplus_zscores(
146+
1, 59,
147+
height_in_cm = 60,
148+
weight_in_kg = 30
149+
)
150+
expect_true(is.na(res$zhfa))
151+
expect_true(is.na(res$zwfa))
152+
expect_true(is.na(res$zbfa))
153+
expect_true(is.na(res$fhfa))
154+
expect_true(is.na(res$fwfa))
155+
expect_true(is.na(res$fbfa))
156+
})

0 commit comments

Comments
 (0)