knitr::opts_chunk$set(echo = TRUE)

Background

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.

library(growthstandards)

dplyr method

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)
    )
  )

Base R method

Using the provided cpp data we have created two data sets based on the 'agedays' variable.

cpp_lt2 <- subset(cpp, agedays < 730)
cpp_gt2 <- subset(cpp, agedays >= 730)

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)

cpp_gt2$whz <- who_value2zscore(
  x = cpp_gt2$htcm, y = cpp_gt2$wtkg, x_var = "htcm", y_var = "wtkg", 
  sex = cpp_gt2$sex)

Finally, we can combine the data back into one data set with the additional 'whz' column.

cpp_whz <- rbind(cpp_lt2, cpp_gt2)
cpp_whz <- cpp_whz[order(cpp_whz$subjid, cpp_whz$agedays), ]


ki-tools/growthstandards documentation built on Jan. 4, 2024, 2:04 a.m.