tf_interpolate {tf} | R Documentation |
Re-evaluate tf
-objects on a new grid of argument values.
Description
Change the internal representation of a tf
-object so that it
uses a different grid of argument values (arg
). Useful for
thinning out dense grids to make data smaller
filling out sparse grids to make derivatives/integrals and locating extrema or zero crossings more accurate (... if the interpolation works well ...)
making irregular functional data into (more) regular data.
For tfd
-objects, this is just syntactic sugar for tfd(object, arg = arg)
.
To inter/extrapolate more reliably and avoid NA
s, call
tf_interpolate
with evaluator = tf_approx_fill_extend
.
For tfb
-objects, this re-evaluates basis functions on the new grid which can
speed up subsequent computations if they all use that grid.
NB: To reliably impute very irregular data on a regular, common grid,
you'll be better off doing FPCA-based imputation or other model-based
approaches in most cases.
Usage
tf_interpolate(object, arg, ...)
## S3 method for class 'tfb'
tf_interpolate(object, arg, ...)
## S3 method for class 'tfd'
tf_interpolate(object, arg, ...)
Arguments
object |
an object inheriting from |
arg |
a vector of argument values on which to evaluate the functions in
|
... |
additional arguments handed over to |
Value
a tfd
or tfb
object on the new grid given by arg
See Also
tf_rebase()
, which is more general.
Other tidyfun inter/extrapolation functions:
tf_approx_linear()
,
tf_evaluate()
Examples
# thinning out a densely observed tfd
dense <- tf_rgp(10, arg = seq(0, 1, length.out = 1001))
less_dense <- tf_interpolate(dense, arg = seq(0, 1, length.out = 101))
dense
less_dense
# filling out sparse data (use a suitable evaluator-function!)
sparse <- tf_rgp(10, arg = seq(0, 5, length.out = 11))
plot(sparse, points = TRUE)
# change evaluator for better interpolation
tfd(sparse, evaluator = tf_approx_spline) |>
tf_interpolate(arg = seq(0, 5, length.out = 201)) |>
lines(col = 2, lty = 2)
set.seed(1860)
sparse_irregular <- tf_rgp(5) |>
tf_sparsify(0.5) |>
tf_jiggle()
tf_interpolate(sparse_irregular, arg = seq(0, 1, length.out = 51))