approxMap.Rd
Define a function that generates an approximation function for a given subset of data. This is designed to be used to predict values in one data.table using values in another via the j slot. See examples.
A data.table containing the observed data
The value to look up in dt[[id.col]]
. When used in a data.table target
's
j
slot, this would be the name of the column shared between dt
and target
without
quotes.
A character string representing the name of the independent variable
column in dt
. Default is x = 'x'
.
A character string representing the name of the dependent variable
column in dt
. Default is y = 'y'
.
A character string representing the name of the group column in
dt
. Default is id.col = 'ID'
A character vector with values present in dt[[id.col]]
for which to return a random value. Used for psuedo-observations where the
outcome is known regardless of the value of the predicted variable.
A vector of two numbers repretenting t he range of
potential values for rand.range
. Default is rand.range = c(0,1)
.
The approximation function. Default is approxfun
,
but any function that accepts a two-column data.frame is acceptable.
Additional parameters to pass to FUN
.
# Generate a data.table with different observations for different categories
data <- data.table(ID = rep(c("A","B","C"), each = 10),
x = runif(30),
y = runif(30, min = 10, max = 20))
# Create a target data.table
target <- data.table(ID = rep(c("A","B","C"), each = 101),
x = rep(seq(0,1,length.out=101), each = 3))
target[, y := approxMap(data, id.val = ID, rule = 2, na.rm=TRUE)(x),by='ID']
#> ID x y
#> 1: A 0.00 10.04309
#> 2: A 0.00 10.04309
#> 3: A 0.00 10.04309
#> 4: A 0.01 10.04309
#> 5: A 0.01 10.04309
#> ---
#> 299: C 0.99 11.93651
#> 300: C 0.99 11.93651
#> 301: C 1.00 11.93651
#> 302: C 1.00 11.93651
#> 303: C 1.00 11.93651