y2p: Convert measurements into centiles

View source: R/y2p.R

y2pR Documentation

Convert measurements into centiles

Description

Converts measurements into age- or hgt-conditional centile scores using one or more external reference distributions.

Usage

y2p(
  y,
  x,
  refcode,
  pkg = "centile",
  verbose = FALSE,
  dec = 3L,
  rule = 1L,
  tail_adjust = FALSE,
  scale = 100,
  ...
)

Arguments

y

A numerical vector with measurements'.

x

A vector containing length(y) values of the numerical covariate (typically decimal age or height) at which conversion is desired. A scalar x will be expanded to length(y).

refcode

A character vector with length(y) elements, each of which is the name of a reference. Scalar refcode expands to length(y). Alternatively, refcode may be an object of class reference, typically produced by import_rif(). If NULL the procedure returns NA's.

pkg

The package containing the references in the R/sysdata.dta object. The package needs to be loaded. The default pkg = "centile" searches in the centile package.

verbose

Set to TRUE to turn on warnings

dec

A scalar value indicating the number of decimals used to round the value. The default is 3 decimals.

rule

an integer (of length 1 or 2) describing how interpolation is to take place outside the interval [min(x), max(x)]. If rule is 1 then NAs are returned for such points and if it is 2, the value at the closest data extreme is used. Use, e.g., rule = 2:1, if the left and right side extrapolation should differ.

tail_adjust

Logical. If TRUE the procedure applies the WHO method for tail adjustment under the LMS distribution. We do not recommend this. The default is FALSE.

scale

The maximum of the scale. The default (100) returns percentiles. Set scale = 1 to obtain probabilities.

...

Not used.

Value

A vector with length(y) elements containing centiles.

Note

The type of reference distribution is defined by the distribution field of the study attribute in the reference. The function executes transformations specified by the tx and ty fields before calculating the Z-score.

Functions y2p() and p2y() functions are the inverse of each other.

Author(s)

Stef van Buuren, 2021

Examples

y <- c(50, 50, 60, 60, 4, 4, 4, 4)
x <- c(rep(0.1, 4), rep(0.1, 4))
refcode <- c(
  rep(c("who_2006_hgt_male_", "who_2006_hgt_female_"), 2),
  rep(c("who_2006_wgt_male_", "who_2006_wgt_female_"), 2)
)
y2p(y, x, refcode)

growthcharts/centile documentation built on May 8, 2024, 9:25 a.m.