| tfd | R Documentation |
Various constructor methods for tfd-objects.
tfd.matrix accepts a numeric matrix with one function per
row (!). If arg is not provided, it tries to guess arg from the
column names and falls back on 1:ncol(data) if that fails.
tfd.data.frame uses the first 3 columns of data for
function information by default: (id, arg, value)
tfd.list accepts a list of vectors of identical lengths
containing evaluations or a list of 2-column matrices/data.frames with
arg in the first and evaluations in the second column
tfd.default returns class prototype when argument to tfd() is
NULL or not a recognised class
tfd(data, ...)
## S3 method for class 'matrix'
tfd(data, arg = NULL, domain = NULL, evaluator = tf_approx_linear, ...)
## S3 method for class 'numeric'
tfd(data, arg = NULL, domain = NULL, evaluator = tf_approx_linear, ...)
## S3 method for class 'data.frame'
tfd(
data,
id = 1,
arg = 2,
value = 3,
domain = NULL,
evaluator = tf_approx_linear,
...
)
## S3 method for class 'list'
tfd(data, arg = NULL, domain = NULL, evaluator = tf_approx_linear, ...)
## S3 method for class 'tf'
tfd(data, arg = NULL, domain = NULL, evaluator = NULL, ...)
## Default S3 method:
tfd(data, arg = NULL, domain = NULL, evaluator = tf_approx_linear, ...)
as.tfd(data, ...)
as.tfd_irreg(data, ...)
data |
a |
... |
not used in |
arg |
|
domain |
range of the |
evaluator |
a function accepting arguments |
id |
The name or number of the column defining which data belong to which function. |
value |
The name or number of the column containing the function evaluations. |
evaluator: must be the (quoted or bare) name of a
function with signature function(x, arg, evaluations) that returns
the functions' (approximated/interpolated) values at locations x based on
the function evaluations available at locations arg.
Available evaluator-functions:
tf_approx_linear for linear interpolation without extrapolation (i.e.,
zoo::na.approx() with na.rm = FALSE) – this is the default,
tf_approx_spline for cubic spline interpolation, (i.e., zoo::na.spline()
with na.rm = FALSE),
tf_approx_fill_extend for linear interpolation and constant extrapolation
(i.e., zoo::na.fill() with fill = "extend")
tf_approx_locf for "last observation carried forward" (i.e.,
zoo::na.locf() with na.rm = FALSE and
tf_approx_nocb for "next observation carried backward" (i.e.,
zoo::na.locf() with na.rm = FALSE, fromLast = TRUE).
See tf:::zoo_wrapper and tf:::tf_approx_linear, which is simply
zoo_wrapper(zoo::na.tf_approx, na.rm = FALSE), for examples of
implementations of this.
an tfd-object (or a data.frame/matrix for the conversion
functions, obviously.)
# turn irregular to regular tfd by evaluating on a common grid:
f <- c(
tf_rgp(1, arg = seq(0, 1, length.out = 11)),
tf_rgp(1, arg = seq(0, 1, length.out = 21))
)
tfd(f, arg = seq(0, 1, length.out = 21))
set.seed(1213)
f <- tf_rgp(3, arg = seq(0, 1, length.out = 51)) |> tf_sparsify(0.9)
# does not yield regular data because linear extrapolation yields NAs
# outside observed range:
tfd(f, arg = seq(0, 1, length.out = 101))
# this "works" (but may not yield sensible values..!!) for
# e.g. constant extrapolation:
tfd(f, evaluator = tf_approx_fill_extend, arg = seq(0, 1, length.out = 101))
plot(f, col = 2)
tfd(f,
arg = seq(0, 1, length.out = 151), evaluator = tf_approx_fill_extend
) |> lines()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.