Learn R Programming

fdars (version 0.3.3)

fdata2basis: Convert Functional Data to Basis Coefficients

Description

Project functional data onto a basis system and return coefficients. Supports B-spline and Fourier basis. Works with both regular fdata and irregular irregFdata objects.

Usage

fdata2basis(x, nbasis = 10, type = c("bspline", "fourier"), ...)

# S3 method for fdata fdata2basis(x, nbasis = 10, type = c("bspline", "fourier"), ...)

# S3 method for irregFdata fdata2basis(x, nbasis = 10, type = c("bspline", "fourier"), ...)

Value

A matrix of coefficients (n x nbasis).

Arguments

x

An object of class 'fdata' or 'irregFdata'.

nbasis

Number of basis functions (default 10).

type

Type of basis: "bspline" (default) or "fourier".

...

Additional arguments (currently unused).

Details

For regular fdata objects, all curves are projected onto the same basis evaluated at the common grid points.

For irregular irregFdata objects, each curve is individually fitted to the basis using least squares at its own observation points. This is the preferred approach for sparse/irregularly sampled data as it avoids interpolation artifacts.

Examples

Run this code
# Regular fdata
t <- seq(0, 1, length.out = 50)
X <- matrix(0, 20, 50)
for (i in 1:20) X[i, ] <- sin(2*pi*t) + rnorm(50, sd = 0.1)
fd <- fdata(X, argvals = t)
coefs <- fdata2basis(fd, nbasis = 10, type = "bspline")

# Irregular fdata (sparsified)
ifd <- sparsify(fd, minObs = 10, maxObs = 20, seed = 42)
coefs_irreg <- fdata2basis(ifd, nbasis = 10, type = "bspline")

Run the code above in your browser using DataLab