Note that weight for height calculations use x_var
as ‘htcm’ or ‘lencm’ and that the current functions do not account for the age category of the coefficients tables by using the age variable in your data. You are expected to subset your data to the 0-2 age category and the use ‘lencm’ as your x_var
to get the appropriate calculations. Similarly, if you use ‘htcm’ as the x_var
then the 2-5 age category will be used for WHZ calculations.
With dplyr
the use of case_when()
we can calculate ‘whz’ using ‘agedays’ to create our two cases.
library(dplyr)
cpp %>%
mutate(
whz = case_when(
agedays < 730 ~ who_value2zscore(
x = htcm, y = wtkg, x_var = "lencm", y_var = "wtkg", sex = sex),
agedays >= 730 ~ who_value2zscore(
x = htcm, y = wtkg, x_var = "htcm", y_var = "wtkg", sex = sex)
)
)
Using the provided cpp
data we have created two data sets based on the ‘agedays’ variable.
Now we can use the specific functions to calculate the appropriate z-scores.
cpp_lt2$whz <- who_value2zscore(
x = cpp_lt2$htcm, y = cpp_lt2$wtkg, x_var = "lencm", y_var = "wtkg",
sex = cpp_lt2$sex)
## Observations with lencm value of 31, 35, 42, 43, 43 are outside the range of the standard. Setting to NA.
## Observations with lencm value of 44 are outside the range of the standard. Setting to NA.
cpp_gt2$whz <- who_value2zscore(
x = cpp_gt2$htcm, y = cpp_gt2$wtkg, x_var = "htcm", y_var = "wtkg",
sex = cpp_gt2$sex)
## Observations with htcm value of 125, 122, 122, 122, 123, 124, 124, 121, 122, 126, 121, 121, 126, 130, 121, 132, 127, 123, 122, 123, 123, 127, 127, 121, 126, 127, 122, 123, 125, 122, 127, 124, 121, 122, 125, 123, 127, 123, 124, 122, 122, 121, 130, 129, 127, 130, 122, 130, 127, 123, 121, 128, 150, 126, 123, 124, 123, 125, 122, 123, 131, 123, 121, 123, 122, 124, 123, 123, 133, 125, 121, 122, 127, 126, 122, 123, 122, 121, 123, 125, 123, 125, 121, 121, 124, 128, 122, 122, 125, 130, 122, 127, 128, 125, 121, 122, 121, 122, 125, 124, 123, 121, 128, 126 are outside the range of the standard. Setting to NA.
## Observations with htcm value of 125, 125, 125, 127, 128, 122, 130, 124, 125, 121, 123, 125, 123, 129, 123, 124, 129, 127, 126, 123, 123, 124, 121, 130, 123, 127, 124, 122, 123, 125, 123, 124, 125, 124, 123, 125, 121, 122, 126, 122, 125, 131, 124, 125, 121, 127, 132, 125, 123, 121, 122, 122, 123, 130, 123, 123, 126, 133, 122, 123, 122, 121, 132, 123, 126, 128, 124, 122, 126, 121, 123, 123, 122, 126, 132, 128, 127, 127, 125, 124, 122, 130, 124, 141, 125, 122, 126, 127, 123, 126, 126, 122, 136, 136, 129, 121, 121, 121, 122, 121, 121, 125, 126, 123, 125, 132, 121, 122, 128, 125 are outside the range of the standard. Setting to NA.
Finally, we can combine the data back into one data set with the additional ‘whz’ column.