curve_interpolation: Interpolates of growth curves along reference centiles

View source: R/curve_interpolation.R

curve_interpolationR Documentation

Interpolates of growth curves along reference centiles

Description

By convention, we connect the points of a growth curve by straight lines. This is OK when ages are relatively close together. However, for ages that are more apart, the straight line gives an ugly representation that doesn't follow the real growth during the interval.

Usage

curve_interpolation(
  data,
  xname = "x",
  yname = "y",
  xout = numeric(0),
  refcode = NULL,
  rule = 2L
)

Arguments

data

A data frame in long format, with columns for person number (named id), the x and y variables.

xname

Name of the variable on the horizontal axis.

yname

Name of the variable on the vertical axis.

xout

A vector of values for the horizontal axis in the scale of the variable xname. Only xout points within the data range of xname are interpolated.

refcode

The name of reference needed to calculate the Z-score scores and the back-transformation to measured scores. There can only be one reference.

rule

The rule argument passed down to approx. The default here is rule = 2L, so any extrapolations beyond the ranges of the reference take the closest value (min or max).

Details

The curve_interpolation() function provides a solution for this. It defines a number of additional points (specified through the xout argument), and calculates the linear interpolation between these points in the Z-scores metric. After that, the procedure transforms back the interpolated Z-scores to the original scale, so the curve points follow the curvy centiles.

Value

A tibble with five columns: id, xname, yname, zname and obs. The obs variables signals whether the point is observed or not.

Author(s)

Stef van Buuren, 2021

See Also

centile::y2z(), centile::z2y()

Examples

data <- data.frame(
  id = c(1, 1, 1, 2, 3, 3, 3),
  age = c(0, 0.2, 1.2, 0.5, 0.1, 1, 1.3),
  hgt = c(52, 60, 78, 69, 62, 78, 82)
)
refcode <- "nl_1997_hgt_male_nl"
xout <- seq(0, 3, 0.2)
int <- chartplotter:::curve_interpolation(data,
  xname = "age", yname = "hgt",
  xout = xout, refcode = refcode
)
int

growthcharts/chartplotter documentation built on May 12, 2024, 8:43 a.m.