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

Add cmeasure to zscore output df #21

Merged
merged 1 commit into from
Dec 14, 2019
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
implementations and in particularly relevant to data points with
age exactly 24 months. Previously this was converted to 730 days and with
this release it is converted to 731 days.
* The cleaned `measure` variable is now part of the output data.frame of
`anthro_zscores`.
* Removed `covr` from suggests dependencies
* Fixed a typo in the docs

Expand Down
19 changes: 12 additions & 7 deletions R/z-score.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ anthro_zscores <- function(sex,
sex <- standardize_sex_var(sex)

# clean measure
measure <- tolower(trimws(measure))
measure[!(is.na(measure) | measure %in% c("l", "h"))] <- NA_character_
cmeasure <- tolower(trimws(measure))
cmeasure[!(is.na(cmeasure) | cmeasure %in% c("l", "h"))] <- NA_character_

# clean oedema, we set all oedema not being "y" to "n"
oedema <- standardize_oedema_var(oedema)
Expand All @@ -229,25 +229,30 @@ anthro_zscores <- function(sex,

# we consider a height measure for children younger than 9 months as
# implausible
measure_implausible <- measure == "h" & age_in_months < 9
measure[measure_implausible] <- NA_character_
measure_implausible <- !is.na(cmeasure) &
!is.na(age_in_months) &
cmeasure == "h" &
age_in_months < 9
cmeasure[measure_implausible] <- NA_character_

clenhei <- adjust_lenhei(age_in_days, measure, lenhei)
clenhei <- adjust_lenhei(age_in_days, cmeasure, lenhei)

cbmi <- weight / ((clenhei / 100)^2)
cbind(
clenhei,
cbmi,
cmeasure,
anthro_zscore_length_for_age(clenhei, age_in_days, sex),
anthro_zscore_weight_for_age(weight, age_in_days, sex, oedema),
anthro_zscore_weight_for_lenhei(
weight, clenhei, measure, age_in_days,
weight, clenhei, cmeasure, age_in_days,
sex, oedema
),
anthro_zscore_bmi_for_age(cbmi, age_in_days, sex, oedema),
anthro_zscore_head_circumference_for_age(headc, age_in_days, sex),
anthro_zscore_arm_circumference_for_age(armc, age_in_days, sex),
anthro_zscore_triceps_skinfold_for_age(triskin, age_in_days, sex),
anthro_zscore_subscapular_skinfold_for_age(subskin, age_in_days, sex)
anthro_zscore_subscapular_skinfold_for_age(subskin, age_in_days, sex),
stringsAsFactors = FALSE
)
}
3 changes: 2 additions & 1 deletion tests/testthat/test-zscores.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ test_that("young children with measured standing will not be adjusted", {
)
expect_equal(res$clenhei, c(60, 60.7))
expect_equal(res$zlen, c(-4.81, -5.02), tolerance = 0.01)
expect_equal(res$cmeasure, c(NA_character_, "h"))
})

test_that("zcores are only computed for children younger or equal to 60 months", {
Expand All @@ -198,7 +199,7 @@ test_that("zcores are only computed for children younger or equal to 60 months",
weight = 60,
measure = "h"
)
expect_true(all(is.na(res[2, -1:-2])))
expect_true(all(is.na(res[2, -1:-3])))
})

test_that("height measurements are used for age 24 months", {
Expand Down