A comprehensive R implementation for detecting outliers in functional time series data using various depth-based and bootstrap methods.
This repository provides multiple approaches for outlier detection in functional time series, extending the original proposal by Raña et al. (2015) with several enhancements:
- Bootstrap-based methods for robust cutoff estimation
- Multivariate extensions using derivative information for shape outlier detection
- Directional outlyingness (DirOut) methods for comprehensive outlier characterization
- Sliding window approaches for local outlier detection
Bootstrap-based outlier detection methods following Raña et al. (2015):
- SmBoD: Standard smoothed bootstrap on data
- MBBo: Moving block bootstrap (for temporal dependence)
- StBo: Stationary bootstrap
Best for: General-purpose outlier detection, especially magnitude outliers.
Multivariate extension using derivative information:
- Uses original process, first derivative, and second derivative
- Combines information across variables with weighted depth
- Best for: Shape outliers and partially contaminated observations
⚠️ Note: May mask magnitude outliers. Use when you expect shape but not magnitude outliers.
Directional outlyingness-based detection:
- Two-component outlyingness (average and variance)
- Captures both magnitude and shape outliers
- Best for: Comprehensive outlier detection when both types are possible
Local outlier detection using sliding windows:
- Window-based functional depth and boxplot detection
- Aggregates outlier flags across multiple windows
- Best for: Non-stationary data and local pattern detection
# Required packages
library(fda)
library(roahd)
library(fda.usc)
library(mrfDepth)
library(fdaoutlier) # For DirOut methods# Source required files
source("R/utils.R")
source("R/depths.R")
# Prepare your functional data
data_matrix <- matrix(rnorm(100*50), nrow = 100, ncol = 50)
fdataobj <- fdata(data_matrix)
# Method 1: Original proposal (MBBo)
source("R/original_proposal/bootstrap-procedures.R")
source("R/original_proposal/outlier-detection-procedures.R")
result <- outlier_bootstrap(
fdataobj = fdataobj,
boot = MBBo,
dfunc = MBD
)
print(result$outliers)Each method has detailed documentation with:
- Complete function signatures and parameter descriptions
- Working code examples
- Parameter tuning guidelines
- Troubleshooting tips
See the README files in each directory:
R/original_proposal/README.mdR/multivariate_process/README.mdR/dirout/README.mdR/sliding_window/README.md
| Method | Best For | Strengths |
|---|---|---|
| Original Proposal | General use, magnitude outliers | Robust, well-tested, multiple bootstrap options |
| Multivariate Process | Shape outliers, partial contamination | Excellent for shape detection, uses derivative info |
| DirOut | Comprehensive detection | Two-component outlyingness, captures both types |
| Sliding Window | Non-stationary data, local patterns | Local context, no bootstrap required |
R/
├── original_proposal/ # Original bootstrap methods
├── multivariate_process/ # Multivariate extension with derivatives
├── dirout/ # Directional outlyingness methods
├── sliding_window/ # Sliding window approach
├── real_data/ # Real data examples
├── depths.R # Depth function implementations
├── utils.R # Utility functions
└── simulated-models.R # Simulation models for testing
Raña, P., Aneiros, G. and Vilar, J. (2015) Detection of outliers in functional time series. Environmetrics, 26, 178–191.
[Add your license information here]