tfd_mv represents vector-valued functional data – vectors of functions
\(f: \mathcal{T} \subset \mathbb{R} \to \mathbb{R}^d\), such as movement
trajectories \((x(t), y(t))\) or other multivariate-output curves.
Usage
tfd_mv(data, ...)
# S3 method for class 'list'
tfd_mv(data, arg = NULL, domain = NULL, evaluator = tf_approx_linear, ...)
# S3 method for class 'array'
tfd_mv(data, arg = NULL, domain = NULL, evaluator = tf_approx_linear, ...)
# S3 method for class 'data.frame'
tfd_mv(
data,
id = 1,
arg = 2,
value = 3,
domain = NULL,
evaluator = tf_approx_linear,
...
)
# S3 method for class 'tf_mv'
tfd_mv(data, arg = NULL, domain = NULL, evaluator = NULL, ...)
# Default S3 method
tfd_mv(data, arg = NULL, domain = NULL, ...)
as.tfd_mv(data, ...)
# Default S3 method
as.tfd_mv(data, ...)
# S3 method for class 'tf_mv'
as.tfd_mv(data, ...)Arguments
- data
one of: a (named)
listof univariatetfvectors (used directly, one per component); a (named)listof numeric matrices / data.frames (one per component, each turned into atfd()); a 3-d numericarraywith dimensions[curve, arg, component]; or a longdata.framewith anidcolumn, anargcolumn and one or morevaluecolumns (one component pervaluecolumn).- ...
forwarded to the univariate
tfd()constructor.- arg
evaluation grid, see
tfd().- domain
range of
arg, seetfd().- evaluator
inter-/extrapolation function, see
tfd().- id, value
for the
data.framemethod: the column defining functionid, the column defining thearggrid, and the (possibly several) columns containing component evaluations (one component pervaluecolumn).
Details
A tfd_mv object of length n bundles d univariate tfd() vectors
(one per output dimension / component), each of length n. All numeric work
(evaluation, arithmetic, smoothing, ...) is delegated to these components, so
regular and irregular sampling, the choice of evaluator, etc. all behave
exactly as in the univariate case – and components may even live on
different argument grids. Use tfb_mv() for a basis representation.
Inheritance contract
tf_mv classes inherit from "tf" only for the purpose of tf_domain(),
type predicates (is_tf(), is_tf_mv(), ...) and S4 generic reuse.
Behaviour on tf_mv comes only from explicitly registered .tf_mv
methods: any generic without one aborts with a classed
tf_mv_method_unimplemented condition. The earlier promise of automatic
"right thing component-wise" dispatch via inheritance was incorrect –
silent fall-through produced wrong-shape results or deep internal errors,
so it has been replaced with fail-fast stubs. The stubbed (i.e., not
implemented) verbs are listed in tf_mv_unimplemented; design of real
component-wise semantics is tracked at
https://github.com/tidyfun/tf/issues/255. When you need to distinguish
univariate-only from any-tf inside a helper, use is_tf_1d(): it returns
TRUE for tfd / tfb and FALSE for tfd_mv / tfb_mv.
See also
tfb_mv() for basis representation; tf_components(),
tf_ncomp() and the $ operator to access components.
Other tf_mv-class:
plot.tf_mv(),
tf_arclength(),
tf_geom,
tf_mv_methods,
tfb_mfpc(),
tfb_mv()
Examples
# (a) from a (named) list of univariate tfd vectors -- one per component:
traj <- tfd_mv(list(x = tf_rgp(3), y = tf_rgp(3)))
traj
#> tfd_mv<d=2>[3] (x, y): [0, 1] -> [-2.384502, 1.093416] x [-1.715262, 2.546049]
#> components based on 51 evaluations each, interpolation by tf_approx_linear
#> [1]: ▆▆▆▆▆▆▆▇▇▇█████████▇▇▇▆▆▆▅ | ▃▄▄▅▆▆▆▆▆▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅
#> [2]: ▄▄▄▃▃▂▁▁▁▁▁▁▂▂▂▂▂▂▂▂▂▂▂▂▃▃ | ▆▆▆▅▅▅▄▄▃▃▂▂▂▂▁▁▁▁▁▁▁▂▂▃▃▄
#> [3]: ▅▄▄▅▅▆▆▇▇▇▆▆▅▄▃▂▂▁▁▁▁▁▁▁▂▃ | ▆▆▆▆▇▇▇████████▇▇▆▅▅▄▄▃▃▂▂
#>
tf_ncomp(traj)
#> [1] 2
traj$x
#> tfd[3]: [0,1] -> [-2.384502,1.093416] based on 51 evaluations each
#> interpolation by tf_approx_linear
#> 1: ▆▆▆▆▆▆▆▇▇▇█████████▇▇▇▆▆▆▅
#> 2: ▄▄▄▃▃▂▁▁▁▁▁▁▂▂▂▂▂▂▂▂▂▂▂▂▃▃
#> 3: ▅▄▄▅▅▆▆▇▇▇▆▆▅▄▃▂▂▁▁▁▁▁▁▁▂▃
# (b) from a list of matrices (one [curve, arg] matrix per component):
t <- seq(0, 1, length.out = 50)
mx <- matrix(sin(2 * pi * outer(1:3, t)), nrow = 3)
my <- matrix(cos(2 * pi * outer(1:3, t)), nrow = 3)
tfd_mv(list(x = mx, y = my), arg = t)
#> tfd_mv<d=2>[3] (x, y): [0, 1] -> [-0.9994862, 0.9994862] x [-0.9979454, 1]
#> components based on 50 evaluations each, interpolation by tf_approx_linear
#> [1]: ▅▆▇▇██████▇▆▅▄▃▂▁▁▁▁▁▁▂▂▃▄ | ███▇▆▅▄▄▃▂▁▁▁▁▁▁▂▃▄▄▅▆▇███
#> [2]: ▅▇███▆▄▃▂▁▁▂▃▆▇██▇▆▅▃▁▁▁▂▄ | ██▆▄▂▁▁▁▂▄▆▇██▇▆▄▂▁▁▁▂▄▆██
#> [3]: ▅██▇▄▁▁▁▃▆██▆▃▁▁▃▆███▅▂▁▁▄ | █▇▄▁▁▂▅▆██▆▃▁▁▃▆██▆▅▂▁▁▄▇█
#>
# (c) from a 3-d array with dimensions [curve, arg, component]:
arr <- array(c(mx, my), dim = c(3, 50, 2),
dimnames = list(NULL, NULL, c("x", "y")))
tfd_mv(arr, arg = t)
#> tfd_mv<d=2>[3] (x, y): [0, 1] -> [-0.9994862, 0.9994862] x [-0.9979454, 1]
#> components based on 50 evaluations each, interpolation by tf_approx_linear
#> [1]: ▅▆▇▇██████▇▆▅▄▃▂▁▁▁▁▁▁▂▂▃▄ | ███▇▆▅▄▄▃▂▁▁▁▁▁▁▂▃▄▄▅▆▇███
#> [2]: ▅▇███▆▄▃▂▁▁▂▃▆▇██▇▆▅▃▁▁▁▂▄ | ██▆▄▂▁▁▁▂▄▆▇██▇▆▄▂▁▁▁▂▄▆██
#> [3]: ▅██▇▄▁▁▁▃▆██▆▃▁▁▃▆███▅▂▁▁▄ | █▇▄▁▁▂▅▆██▆▃▁▁▃▆██▆▅▂▁▁▄▇█
#>
# (d) from a long data.frame (id, arg, one value column per component):
df <- data.frame(
id = rep(1:3, each = 50),
arg = rep(t, times = 3),
x = as.vector(t(mx)),
y = as.vector(t(my))
)
tfd_mv(df, id = "id", arg = "arg", value = c("x", "y"))
#> tfd_mv<d=2>[3] (x, y): [0, 1] -> [-0.9994862, 0.9994862] x [-0.9979454, 1]
#> components based on 50 evaluations each, interpolation by tf_approx_linear
#> [1]: ▅▆▇▇██████▇▆▅▄▃▂▁▁▁▁▁▁▂▂▃▄ | ███▇▆▅▄▄▃▂▁▁▁▁▁▁▂▃▄▄▅▆▇███
#> [2]: ▅▇███▆▄▃▂▁▁▂▃▆▇██▇▆▅▃▁▁▁▂▄ | ██▆▄▂▁▁▁▂▄▆▇██▇▆▄▂▁▁▁▂▄▆██
#> [3]: ▅██▇▄▁▁▁▃▆██▆▃▁▁▃▆███▅▂▁▁▄ | █▇▄▁▁▂▅▆██▆▃▁▁▃▆██▆▅▂▁▁▄▇█
#>