This function transforms growth data in the wide matrix to Z-scores using the selector method implemented in set_refcodes(). It is the inverse of transform2y().

transform2z(
  data,
  ynames = c("hgt", "wgt", "hdc", "wfh", "bmi", "dsc"),
  pkg = "nlreferences",
  verbose = FALSE,
  ...
)

Arguments

data

Data frame with appropriate variables, at least sex and age. The names of the measurements can be one or more of: hgt, wgt, hdc, wfh, bmi and dsc.

ynames

Character vector containing the measurements to convert. Specify this to limit the number of conversions. If not specified, the function calculates Z-scores for all measurements.

pkg

Name of the package that stores the growth references. By default, transform2z searches the nlreferences package.

verbose

Set to TRUE to turn on warnings and messages, which is useful for tracking down problem related to missing data or to the availability of references.

...

Arguments passed down to centile::y2z(), e.g. rule = c(1, 2) to calculate Z-scores beyond the maximum age in the reference table.

Value

A data frame with either zero rows or the same number of rows as nrow(data) with colums named hgt_z, wgt_z, and so on.

Details

By default, the function scans for variables named hgt, wgt, hdc, wfh, bmi and dsc, and returns Z-scores for any variables it finds.

Author

Stef van Buuren 2021

Examples

df <- data.frame(hgt = 60, wgt = 5, hdc = 40, age = 0.3,
sex = "male", ga = c(20, 30, 40, 50))
transform2z(df, ynames = c("hdc", "wfh"))
#> # A tibble: 4 × 2
#>    hdc_z wfh_z
#>    <dbl> <dbl>
#> 1 NA     -1.66
#> 2  0.928 -1.66
#> 3 -1.27  -1.70
#> 4 -1.27  -1.70