Functional Data Analysis (FDA)
High-performance Functional Data Analysis tools implemented in Rust with R bindings.
Packages
| Package | Language | Registry | Folder | Status |
|---|---|---|---|---|
| fdars | R | CRAN | sipemu/fdars-r | |
| fdars-core | Rust | crates.io | fdars-core/ |
Features
| Area | Capabilities |
|---|---|
| Core | Simulation (KL expansion, GP with 8 kernels), functional operations, smoothing (NW, local polynomial, k-NN), basis representations (B-spline, Fourier, P-spline) |
| Descriptive | 10 depth measures + streaming online depth, 12 distance metrics (Lp, DTW, elastic, semimetrics, KL), LRT outlier detection |
| Regression | Scalar-on-function (FPC, kernel, logistic, robust), function-on-scalar (FOSR, 2D FOSR, FANOVA), FPCA, PLS, ridge, mixed effects |
| Classification | LDA, QDA, k-NN, kernel, DD-classifier, conformal prediction sets; k-means, fuzzy c-means, GMM |
| Elastic Alignment | SRSF/DP alignment, Karcher mean (1-D/N-D), TSRVF, Bayesian (pCN MCMC), closed curves, transfer alignment, partial matching, multi-resolution, generative models, geodesics, FPNS, lambda CV, peak persistence |
| Elastic Robust | Karcher median, trimmed mean, SRVF outlier detection, elastic depth, shape CIs, diagnostics, warp statistics, phase box plots, shape analysis |
| Elastic Models | Elastic FPCA, regression, PCR, logistic, scalar-on-shape (ScoSh), changepoint detection, elastic clustering |
| SPM | T²/SPE Phase I/II, EWMA, MEWMA, CUSUM, adaptive EWMA, FRCC, profile monitoring; bootstrap/KDE limits, ARL, partial-domain, elastic SPM, iterative Phase I, Western Electric/Nelson rules |
| Explainability | PDP/ICE, SHAP, ALE, LIME, Sobol, Friedman H, anchors, counterfactuals, prototype/criticism; influence diagnostics, VIF, calibration (ECE, Brier), saliency maps; FpcPredictor trait |
| Inference | Tolerance bands (FPCA, conformal, Degras, exponential, elastic), conformal prediction (split, Jackknife+, CV+), equivalence testing (TOST) |
| Time Series | Seasonal detection (FFT, ACF, Autoperiod, SAZED, Lomb-Scargle, SSA, matrix profile), detrending (polynomial, LOESS, STL) |
| Specialized | Streaming depth (online O(log N)), irregular data (CSR, kernel estimation) |
Installation
R (fdars)
install.packages("fdars")
# Development version from GitHub (requires Rust toolchain)
devtools::install_github("sipemu/fdars-r")
Rust (fdars-core)
[dependencies]
fdars-core = "0.9"
Or install from the repository:
[dependencies]
fdars-core = { git = "https://github.com/sipemu/fdars" }
Feature Flags
parallel(default): Enable rayon-based parallel processinglinalg: Enable linear algebra features (faer, ridge regression) — requires Rust 1.84+js: Enable WASM support with JS random number generation
For WASM builds, disable default features:
[dependencies]
fdars-core = { version = "0.9", default-features = false }
Data Layout
Functional data is represented using the FdMatrix type, a column-major matrix wrapping a flat Vec<f64> with safe (i, j) indexing and dimension tracking:
- For n observations with m evaluation points:
data[(i, j)]gives observation i at point j - Zero-copy column access via
data.column(j), row gather viadata.row(i) - nalgebra interop via
to_dmatrix()/from_dmatrix()for SVD operations - 2D surfaces (n observations, m1 x m2 grid): stored as n x (m1*m2) matrices
Quick Start
use fdars_core::{FdMatrix, fdata, depth};
// Create sample functional data (3 observations, 10 points each)
let n = 3;
let m = 10;
let data: Vec<f64> = (0..(n * m)).map(|i| (i as f64).sin()).collect();
let mat = FdMatrix::from_column_major(data, n, m).unwrap();
let argvals: Vec<f64> = (0..m).map(|i| i as f64 / (m - 1) as f64).collect();
// Compute mean function
let mean = fdata::mean_1d(&mat);
// Compute Fraiman-Muniz depth
let depths = depth::fraiman_muniz_1d(&mat, &mat, true);
Examples
27 runnable examples in fdars-core/examples/:
| # | Example | Topics |
|---|---|---|
| 01 | Simulation | KL expansion, GP generation |
| 02 | Functional Operations | Mean, derivatives, norms |
| 03 | Smoothing | NW, local polynomial, k-NN |
| 04 | Basis Representation | B-splines, Fourier, P-splines |
| 05 | Depth Measures | 8 depth measures, outlier ranking |
| 06 | Distances | Lp, DTW, elastic, semimetrics |
| 07 | Clustering | K-means, fuzzy c-means |
| 08 | Regression | FPCA, PLS |
| 09 | Outlier Detection | LRT bootstrap |
| 10 | Seasonal Analysis | FFT, Autoperiod, SAZED |
| 11 | Detrending | Polynomial, LOESS, STL |
| 12 | Streaming Depth | Online depth |
| 13 | Irregular Data | CSR storage, kernel estimation |
| 14 | Complete Pipeline | End-to-end workflow |
| 15 | Tolerance Bands | FPCA, conformal, Degras SCB |
| 16 | Elastic Alignment | SRSF, DP, Karcher mean |
| 17 | Equivalence Test | Functional TOST |
| 18 | Landmark Registration | Constrained alignment |
| 19 | TSRVF | Transported SRVF |
| 20 | Scalar-on-Function * |
FPC linear, logistic, kernel |
| 21 | Function-on-Scalar * |
FOSR, FANOVA |
| 22 | GMM Clustering * |
GMM-EM, BIC/ICL |
| 23 | Classification * |
LDA, QDA, k-NN, DD |
| 24 | Mixed Effects * |
FAMM, REML |
| 25 | Explainability * |
SHAP, ALE, PDP, anchors |
| 26 | Elastic Analysis * |
Elastic FPCA, regression, PCR |
| 27 | SPM | Phase I/II, EWMA, CUSUM, rules |
* requires --features linalg
Run with cargo run -p fdars-core --example <name> (add --features linalg where marked).
Performance
With the parallel feature (enabled by default), computationally intensive operations use rayon for multi-core performance. The library also supports WASM targets with sequential execution.
Documentation
- R Package: https://sipemu.github.io/fdars/
- Rust Crate: https://docs.rs/fdars-core
License
MIT