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 csex to output df #25

Merged
merged 1 commit into from
Dec 23, 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
18 changes: 9 additions & 9 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# 0.9.1.9000
# anthro 0.9.1.9000

* age in days is now rounded half to even (e.g. 730.5 days = 731) before joining
* Age in days is now rounded half to even (e.g. 730.5 days = 731) before joining
the data with the reference values. This is in line with previous
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
implementations and in particularly relevant for data points with
age exactly 24 months. Previously the example above was converted to 730 days and with
this release it is converted to 731 days (#17).
* The cleaned `measure` and `sex` variables are now part of the output
data.frame of `anthro_zscores` (#20, #24).
* Removed `covr` from suggests dependencies.
* Fixed a typo in the docs (#15).

# anthro 0.9.1

Expand Down
19 changes: 10 additions & 9 deletions R/z-score.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ anthro_zscores <- function(sex,
oedema <- rep_len(oedema, length.out = max_len)

# clean sex
sex <- standardize_sex_var(sex)
csex <- standardize_sex_var(sex)

# clean measure
cmeasure <- tolower(trimws(measure))
Expand All @@ -242,17 +242,18 @@ anthro_zscores <- function(sex,
clenhei,
cbmi,
cmeasure,
anthro_zscore_length_for_age(clenhei, age_in_days, sex),
anthro_zscore_weight_for_age(weight, age_in_days, sex, oedema),
csex,
anthro_zscore_length_for_age(clenhei, age_in_days, csex),
anthro_zscore_weight_for_age(weight, age_in_days, csex, oedema),
anthro_zscore_weight_for_lenhei(
weight, clenhei, cmeasure, age_in_days,
sex, oedema
csex, 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_bmi_for_age(cbmi, age_in_days, csex, oedema),
anthro_zscore_head_circumference_for_age(headc, age_in_days, csex),
anthro_zscore_arm_circumference_for_age(armc, age_in_days, csex),
anthro_zscore_triceps_skinfold_for_age(triskin, age_in_days, csex),
anthro_zscore_subscapular_skinfold_for_age(subskin, age_in_days, csex),
stringsAsFactors = FALSE
)
}
14 changes: 13 additions & 1 deletion tests/testthat/test-zscores.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,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:-3])))
expect_true(all(is.na(res[2, -1:-4])))
})

test_that("height measurements are used for age 24 months", {
Expand All @@ -211,3 +211,15 @@ test_that("height measurements are used for age 24 months", {
)
expect_equivalent(res$zlen, -2.55)
})

test_that("cleaned sex variable is part of the output data.frame", {
res <- anthro_zscores(
sex = c(1, 2, "m", "f", NA_character_),
age = 20,
is_age_in_month = TRUE,
lenhei = 60,
weight = 20,
measure = "h"
)
expect_equal(res$csex, c(1L, 2L, 1L, 2L, NA_integer_))
})