knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The nlreferences package provides Dutch reference values.
You can install the development version from GitHub with:
# install.packages("devtools") devtools::install_github("growthcharts/nlreferences")
Suppose you want to calculate Z-scores for waist circumference for Dutch boys and girls using the references published in Fredriks AM et al (2005).
The calculation requires two R packages: nlreferences
(with the reference data) and centile
(with the calculation method). Install both. You need to do this only once.
install.packages("remotes") remotes::install_github("growthcharts/nlreferences") remotes::install_github("growthcharts/centile")
The raw reference coordinates for boys and girls can be found in the nlreferences
package as files data-raw/data/nl1997/nl_1997_wst_male_.txt
and data-raw/data/nl1997/nl_1997_wst_female_.txt
. See https://github.com/growthcharts/nlreferences/tree/master/data-raw/data/nl1997. To calculate Z-score for waist circumference, you need their file names without the path and extension.
refs <- c("nl_1997_wst_male_", "nl_1997_wst_female_")
Next you need your data organized into "long format". A minimal example is
data <- data.frame( age = c(0.5, 10, 17.411, 14.328, NA), sex = c("male", NA, "female", "female", "male"), y = c(42.037, 60, 70, NA, 70) ) data
Load the packages, and the run the y2z()
function. Specify for each record the reference that you want to use, and convert each measurement y
into a Z-score z
.
library(centile) library(nlreferences) data$ref <- ifelse(data$sex == "male", refs[1], refs[2]) data$z <- y2z(y = data$y, x = data$age, refcode = data$ref, pkg = "nlreferences")
And presto, your data with two extra columns ref
and z
.
data
Tips:
z
will be NA
when it cannot be calculated. Add argument verbose = TRUE
to generate warnings;y2p()
for conversion into percentiles;z2y()
to convert Z-scores back into the original measurement scale;tidyr::pivot_longer()
to convert wide to long organisation;data
, and specify the desired reference name in each row.Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.