#' This function transforms Z-scores stored in the wide matrix to measurements using the selector method implemented in set_refcodes(). It is the inverse of transform2z().

transform2y(
  data,
  znames = c("hgt_z", "wgt_z", "hdc_z", "wfh_z", "bmi_z", "dsc_z"),
  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_z, wgt_z, hdc_z, wfh_z, bmi_z and dsc_z.

znames

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

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::z2y(), 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, wgt, and so on.

Details

By default, the function scans for variables named hgt_z, wgt_z, hdc_z, wfh_z, bmi_z and dsc_z, and returns the measurement values for any variables it finds.

The conversion of wfh_z to wfh is special. As wfh is conditional on hgt, the calculation requires either hgt or hgt_z to be present in the data. Availability of hgt takes precedence over hgt_z. If only hgt_z is known, then the function calculates hgt from hgt_z.

Author

Stef van Buuren 2021

Examples

df <- data.frame(hgt_z = 0, wgt_z = 1, hdc_z = -1, age = 0.3,
sex = "male", ga = c(20, 30, 40, 50))
transform2y(df, znames = c("hdc_z", "wfh_z"))
#> # A tibble: 4 × 1
#>     hdc
#>   <dbl>
#> 1  NA  
#> 2  37.3
#> 3  40.4
#> 4  40.4