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.

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).

Value

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

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.

Author

Stef van Buuren, 2021

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
#> # A tibble: 16 × 5
#>       id   age   hgt   hgt_z obs  
#>    <dbl> <dbl> <dbl>   <dbl> <lgl>
#>  1     1   0    52    0.327  TRUE 
#>  2     1   0.2  60    0.258  TRUE 
#>  3     1   0.4  65.9  0.113  FALSE
#>  4     1   0.6  69.9 -0.0324 FALSE
#>  5     1   0.8  73.0 -0.178  FALSE
#>  6     1   1    75.7 -0.323  FALSE
#>  7     1   1.2  78   -0.468  TRUE 
#>  8     2   0.5  69    0.409  TRUE 
#>  9     3   0.1  62    3.00   TRUE 
#> 10     3   0.2  65.7  2.72   FALSE
#> 11     3   0.4  70.9  2.17   FALSE
#> 12     3   0.6  74.1  1.62   FALSE
#> 13     3   0.8  76.3  1.08   FALSE
#> 14     3   1    78    0.528  TRUE 
#> 15     3   1.2  80.7  0.496  FALSE
#> 16     3   1.3  82    0.48   TRUE