These are exported evaluator callbacks for tfd objects. They control how
function values are inter-/extrapolated to previously unseen arg values and
are used by tf_evaluate().
In typical use, set an evaluator when constructing a tfd
(tfd(..., evaluator = tf_approx_linear)) or replace it later via
tf_evaluator(x) <- tf_approx_none.
These helpers are wrappers around zoo::na.fill(), zoo::na.approx(), etc.
and all share the same signature (x, arg, evaluations), so they can
also be called directly.
The list:
tf_approx_linearfor linear interpolation without extrapolation (i.e.,zoo::na.approx()withna.rm = FALSE) – this is the default,tf_approx_splinefor cubic spline interpolation, (i.e.,zoo::na.spline()withna.rm = FALSE),tf_approx_nonein order to not inter-/extrapolate ever (i.e.,zoo::na.fill()withfill = NA)tf_approx_fill_extendfor linear interpolation and constant extrapolation (i.e.,zoo::na.fill()withfill = "extend")tf_approx_locffor "last observation carried forward" (i.e.,zoo::na.locf()withna.rm = FALSE)tf_approx_nocbfor "next observation carried backward" (i.e.,zoo::na.locf()withna.rm = FALSE, fromLast = TRUE).
For implementing your own, see source code of tf:::zoo_wrapper.
Usage
tf_approx_linear(x, arg, evaluations)
tf_approx_spline(x, arg, evaluations)
tf_approx_none(x, arg, evaluations)
tf_approx_fill_extend(x, arg, evaluations)
tf_approx_locf(x, arg, evaluations)
tf_approx_nocb(x, arg, evaluations)Value
a vector of values of the function defined by the given
\((x_i, f(x_i))\)=(arg, evaluations)-tuples at new argument values x.
See also
Other tidyfun inter/extrapolation functions:
tf_evaluate(),
tf_interpolate()
Other tidyfun inter/extrapolation functions:
tf_evaluate(),
tf_interpolate()
Other tidyfun inter/extrapolation functions:
tf_evaluate(),
tf_interpolate()
Other tidyfun inter/extrapolation functions:
tf_evaluate(),
tf_interpolate()
Other tidyfun inter/extrapolation functions:
tf_evaluate(),
tf_interpolate()
Other tidyfun inter/extrapolation functions:
tf_evaluate(),
tf_interpolate()
Examples
x <- tfd(matrix(c(0, 1), nrow = 1), arg = c(0, 1))
tf_evaluate(x, c(0, 0.5, 1))
#> [[1]]
#> [1] 0.0 0.5 1.0
#>
tf_evaluator(x) <- tf_approx_none
tf_evaluate(x, c(0, 0.5, 1))
#> [[1]]
#> [1] 0 NA 1
#>
tf_approx_linear(
x = c(0, 0.5, 1),
arg = c(0, 1),
evaluations = c(0, 1)
)
#> [1] 0.0 0.5 1.0