Provides S3 vector types for functional data represented on grids, in spline bases, or via functional principal components. Supports arithmetic and summary methods, plotting, derivation, integration, smoothing, registration, and data import/export for these functional vectors. Includes data-wrangling tools for re-evaluation, subsetting, sub-assignment, zooming into sub-domains, and extracting functional features such as minima, maxima, and their locations. Enables joint analysis of functional and scalar variables by integrating functional vectors into standard data frames.

The tf package provides necessary infrastructure for
tidyfun with minimal
dependencies – vctrs/rlang/cli/purrr from the r-lib/tidyverse
ecosystem, otherwise just mgcv, zoo, and checkmate.
The goal of tidyfun, in turn, is to provide accessible and
well-documented software that makes functional data analysis in R
easy – specifically data wrangling and exploratory analysis.
tf includes definitions of new S3 data types for vectors of
functional data and associated methods. These tf-vectors, with
subclasses tfd and tfb, use the
vctrs-framework, can be operated on
using most standard functions (+, mean(), c(), etc.) as well as
several new functions in tf that implement operations specific for
functional data (tf_smooth, tf_derive, tf_integrate,
tf_register, …).
Crucially, vectors of class tf can be included in data frames
containing other variables, for simple and reliable data manipulation.
This approach is connected to the conceptual framework in functional
data analysis which assumes that complete functions are the unit of
observation. With tidyfun and tf, you can keep full curves alongside
numeric, factor, and other observations on the same subject in one data
frame.
You can install the released version of tf from CRAN with:
install.packages("tf")
And the development version from GitHub with:
# install.packages("pak")
pak::pak("tidyfun/tf")
tf provides:
tfd & tfbtf vectorstf-objectstf-objectsPlease see the tidyfun website
for the full documentation including vignettes etc.
tf provides new S3-classes for functional
data,
either as raw data (class tfd for tidy functional data) or in
basis representation (class tfb for tidy functional basis data).
Such tf-objects can be subsetted or subassigned, computed on and
summarized.
Almost all
==, + or *sum, log or absmean or sdare defined for the vector classes defined in tf
(more).
The tf objects are just glorified lists, so they work well as columns
in data frames. That makes it a lot easier to keep your other data and
functional measurements together in one object for preprocessing,
exploratory analysis and description. At the same time, these objects
actually behave like vectors of functions to some extent, i.e., they
can be evaluated on any point in their domain, they can be integrated or
differentiated, etc.
See
here
for more information on the operations defined for tf vectors.
tf also provides tfd_mv() and tfb_mv() for vector-valued
functional data – i.e., functions whose codomain is R^d, sharing a
single domain across components. These behave like the univariate tf
classes (subsetting, arithmetic, plotting), with component-wise
accessors and the geometry verbs tf_norm(), tf_inner(),
tf_tangent(), tf_arclength():
fm <- tfd_mv(list(x = tf_rgp(5), y = tf_rgp(5)))
plot(fm, type = "facet")
Multivariate FPCA is available via tfb_mfpc() (Happ & Greven, 2018),
and tf_register() supports joint multivariate alignment
(method = "srvf_mv") as well as elastic shape registration
(tf_register_shape()). Note that is_tf() is TRUE for tf_mv as
well; use the new is_tf_1d() to test specifically for univariate tf.
tf and backtf includes functions tfd and tfb for converting matrices,
data frames, etc. to tf vectors and back. More data wrangling methods
in a tidyverse-inspired way and ggplot2-geoms for functional data
are available in tidyfun.
See
here
for details on getting data into (and out of) the tf format.
Found a bug? Got a question? Missing some functionality?
Please let us know so we can make it better.