match_func {DMTL} | R Documentation |
Estimate Inverse Mapping
Description
This function estimates an inverse map g
for a given set of knots
(input) and values (output) corresponding to a certain map f
i.e.,
given x, y | f: x --> y
, match_func()
estimates g: y --> x
using linear interpolation.
Usage
match_func(knots, vals, new_vals, lims, get_func = FALSE)
Arguments
knots |
Vector containing knots for the distribution estimate. |
vals |
Vector containing distribution values corresponding to the knots. |
new_vals |
Vector containing distribution values for which the knots
are unknown. If missing, |
lims |
Vector providing the range of the knot values for mapping. If missing, these values are estimated from the given knots. |
get_func |
Flag for returning the map function if |
Value
If new_vals
is missing, a function performing interpolation
(linear or constant) of the given data points.
If get_func = FALSE
, a vector containing the matched knots that will
produce new_vals
for the map f
.
If get_func = TRUE
, a named list with two components- mapped
and func
(mapped knots for new_vals
and the mapping function, respectively).
Examples
set.seed(654321)
x <- rnorm(100, 1, 0.5)
F <- ecdf(x)
fval <- F(x)
map <- match_func(knots = x, vals = fval)
x2 <- rnorm(20, 0.8, 0.5)
F2 <- ecdf(x2)
fval2 <- F2(x2)
matched <- match_func(knots = x, vals = fval, new_vals = fval2)
## Plot histograms...
opar <- par(mfrow = c(1, 3))
hist(x); hist(x2); hist(matched)
par(opar) # Reset par