Package 'FunctionalCalibration'

Title: Aggregated Functional Data Calibration using Splines and Wavelets
Description: Implements methods for calibrating an aggregated functional data model using wavelets or splines. Each aggregated curve is modeled as a linear combination of component functions and known weights. The component functions are estimated using wavelets or splines. The package is based on dos Santos Sousa (2024) <doi:10.1515/mcma-2023-2016>, Saraiva and Dias (2009) <doi:10.47749/T/UNICAMP.2009.471073> and Johnstone and Silverman (1997) <doi:10.1111/1467-9868.00071>.
Authors: Vitor Perrone [aut, cre] (ORCID: <https://orcid.org/0009-0009-6923-7712>), Alex Sousa [aut] (ORCID: <https://orcid.org/0000-0001-5887-3638>)
Maintainer: Vitor Perrone <[email protected]>
License: GPL-3
Version: 2.0.0
Built: 2026-10-27 12:05:17 UTC
Source: https://github.com/vitorribasp/functionalcalibration

Help Index


Functional Data Calibration with Splines

Description

This function performs functional calibration based on the following model:

Ai(xm)=∑l=1Lyilαl(xm)+ei(xm),i=1,...,I,m=1,...,M=2JA_i(x_m) = \displaystyle \sum_{l=1}^{L} y_{il} \alpha_l(x_m) + e_i(x_m), \quad i = 1,...,I, \quad m = 1,...,M = 2^J

where the functions αl(x)\alpha_l(x) are estimated using spline basis functions.

In matrix notation, the model is represented as:

A=αy+eA = \alpha y + e

Usage

functional_calibration_splines(data, weights, x, n_functions = 10)

Arguments

data

A matrix MM x II where each column represents one sample of the aggregated function — the matrix AA in the model.

weights

A matrix LL x II representing the weight values associated with each sample — the matrix yy in the model.

x

A numeric vector of values at which the function is evaluated.

n_functions

Number of spline basis functions to be used for estimating αl(x)\alpha_l(x).

Value

The function returns a list containing two objects.

alpha

A matrix with the estimated functional coefficients α\alpha.

Plots

A list of plot objects, each representing the corresponding function αl(x)\alpha_l(x).

References

Saraiva, M. A., & Dias, R. (2009). Analise não-parametrica de dados funcionais: uma aplicação a quimiometria (Doctoral dissertation, Master’s thesis, Universidade Estadual de Campinas, Campinas).

Examples

functional_calibration_splines(simulated_data_spl$data,
simulated_data_spl$weights, simulated_data_spl$x)
functional_calibration_splines(simulated_data_spl$data,
simulated_data_spl$weights, simulated_data_spl$x, 12)

Functional Data Calibration with Wavelets

Description

This function performs functional calibration based on the following model:

Ai(xm)=∑l=1Lyilαl(xm)+ei(xm),i=1,...,I,m=1,...,M=2JA_i(x_m) = \displaystyle \sum_{l=1}^{L} y_{il} \alpha_l(x_m) + e_i(x_m), \quad i = 1,...,I, \quad m = 1,...,M = 2^J

where the functions αl(x)\alpha_l(x) are estimated using wavelet decomposition.

In matrix notation, the model is represented as:

A=αy+eA = \alpha y + e

Usage

functional_calibration_wavelets(
  data,
  weights,
  wavelet = "DaubExPhase",
  method = "bayesian",
  tau = 1,
  p = NULL,
  sigma = NULL,
  MC = TRUE,
  type = "soft",
  singular = FALSE,
  corre = FALSE,
  x = NULL
)

Arguments

data

A matrix MM x II where each column represents one sample of the aggregated function — the matrix AA in the model.

weights

A matrix LL x II representing the weight values associated with each sample — the matrix yy in the model.

wavelet

A string indicating the wavelet family to be used in the Discrete Wavelet Transform (DWT).

method

A string specifying the shrinkage method applied to the empirical wavelet coefficients. Options are: "bayesian", "universal", "sure", "probability", or "cv".

tau

A numeric value for the τ\tau parameter in the Bayesian shrinkage. If NULL, it is estimated from the data.

p

A numeric value for the pp parameter in the Bayesian shrinkage. If NULL, it is estimated from the data.

sigma

A numeric value for the σ\sigma parameter in the Bayesian shrinkage. If NULL, it is estimated from the data.

MC

A logical evaluating to TRUE or FALSE indicating if the integrals in the Bayesian shrinkage are approximated using Monte Carlo simulation.

type

A string indicating whether the thresholding should be "soft" or "hard" (applies only when the method is not "bayesian").

singular

A logical evaluating to TRUE or FALSE indicating if it adds a small constant (1e-10) to the diagonal of yyTyy^T to stabilize the matrix inversion.

corre

A logical evaluating to TRUE or FALSE indicating if the errors of the data are correlated. Only available for "bayesian" and "universal" methods.

x

A numeric vector of values at which the function is evaluated. If NULL, the default is the sequence 1:nrow(data).

Value

The function returns a list containing two objects:

alpha

A matrix with the estimated functional coefficients α\alpha.

Plots

A list of plot objects, each representing the corresponding function αl(x)\alpha_l(x).

References

dos Santos Sousa, A. R. (2024). A wavelet-based method in aggregated functional data analysis. Monte Carlo Methods and Applications, 30(1), 19-30.

JOHNSTONE, I. M.; SILVERMAN, B. W. Wavelet Threshold Estimators for Data with Correlated Noise. Journal of the Royal Statistical Society: Series B (Statistical Methodology), v. 59, n. 2, p. 319–351, 1997.

Examples

functional_calibration_wavelets(simulated_data_wav$data, simulated_data_wav$weights)
functional_calibration_wavelets(simulated_data_wav$data, simulated_data_wav$weights,
                                tau = 5, p = 0.95, sigma = 0.1, x = simulated_data_wav$x)
functional_calibration_wavelets(simulated_data_wav$data, simulated_data_wav$weights,
                                method = "universal")
functional_calibration_wavelets(simulated_data_cor$data, simulated_data_cor$weights, corre = TRUE)

Aggregated Curve Plot

Description

Generates the plot of the aggregated curve based on the functional coefficients and their corresponding weights. The aggregated curve is computed as:

A(x)=∑l=1Lylαl(x)A(x) = \displaystyle \sum_{l=1}^{L} y_l \alpha_l(x)

Usage

plot_aggregated_curve(alpha, weights, title = NULL, x = NULL)

Arguments

alpha

A numeric matrix where each column represents the values of a function αl(x)\alpha_l(x) evaluated at each point in xx.

weights

A numeric vector with the weight values corresponding to each function αl(x)\alpha_l(x).

title

A string specifying the title of the plot.

x

A numeric vector of values at which the function is evaluated. If NULL, the default is the sequence 1:nrow(alpha).

Value

The function returns the plot of the aggregated function.

Examples

plot_aggregated_curve(simulated_data_wav$alphas, c(0.7, 0.3))
plot_aggregated_curve(simulated_data_wav$alphas, c(0.7, 0.3),
                      "Aggregated Curve Example", simulated_data_wav$x)

Simulated Data

Description

This is a simulated dataset designed to illustrate the functionalities of the package. It contains 100 samples of aggregated data generated from two functions, α1(x)\alpha_1(x) and α2(x)\alpha_2(x), with added Gaussian noise N(0,0.1)N(0, 0.1).

The functions used in the simulation are:

α1(x)=sin⁡(5x)e−x2α2(x)={−2,x<00,0≤x<1.53,x≥1.5\alpha_1(x) = \sin(5x) e^{-x^2} \quad \alpha_2(x) = \begin{cases} -2, & x < 0 \\ 0, & 0 \leq x < 1.5 \\ 3, & x \geq 1.5 \end{cases}

The simulations were performed over an equally spaced grid of 1024 points in the interval [-1, 2]. These functions were linearly combined using random concentrations to generate the samples, with the addition of Gaussian noise.

Usage

simulated_data

Format

An object of class list of length 4.

Value

data

A data frame with 1024 rows and 100 columns.
Each column represents one sample of the aggregated functions with Gaussian noise N(0,0.1)N(0, 0.1).

weigths

A data frame with 2 rows and 100 columns.
Each column contains the random concentrations used to aggregate the two functions in each sample.

x

A numeric vector of length 1024.
The grid of x-values used in the simulation, equally spaced from -1 to 2.

alphas

A data frame with 1024 rows and 2 columns.
The true values of the functions α1(x)\alpha_1(x) and α2(x)\alpha_2(x) evaluated over the x grid.


Simulated Data Correlated

Description

This is a simulated dataset designed to illustrate the functionalities of the package. It contains 100 samples of aggregated data generated from two functions, α1(x)\alpha_1(x) and α2(x)\alpha_2(x), with added noise AR(1) process with autoregressive parameter 0.5 and Gaussian process noise distributed as N(0,0.0075)N(0, 0.0075).

The functions used in the simulation are:

α1(x)=∑j=111hj(1+∣x−xjwj∣)−4α2(x)=x(1−x)sin⁡(2π(1+0.05)x+0.05)\alpha_1(x) = \sum_{j=1}^{11} h_j \left(1 + \left|\frac{x - x_j}{w_j}\right|\right)^{-4} \quad \alpha_2(x) = \sqrt{x(1-x)}\sin\left(\frac{2\pi(1 + 0.05)}{x + 0.05}\right)

where x=(0.1, 0.13, 0.15, 0.23, 0.25, 0.40, 0.44, 0.65, 0.76, 0.78, 0.81)x = (0.1,\,0.13,\,0.15,\,0.23,\,0.25,\,0.40,\,0.44,\,0.65,\,0.76,\,0.78,\,0.81),

h=(4, 5, 3, 4, 5, 4.2, 2.1, 4.3, 3.1, 5.1, 4.2)h = (4,\,5,\,3,\,4,\,5,\,4.2,\,2.1,\,4.3,\,3.1,\,5.1,\,4.2),

w=(0.005, 0.005, 0.006, 0.01, 0.01, 0.03, 0.01, 0.01, 0.005, 0.008, 0.005)w = (0.005,\,0.005,\,0.006,\,0.01,\,0.01,\,0.03,\,0.01,\,0.01,\,0.005,\,0.008,\,0.005).

The simulations were performed over an equally spaced grid of 1024 points in the interval [0, 1]. These functions were linearly combined using random concentrations to generate the samples, with the addition of AR(1) noise.

Usage

simulated_data_cor

Format

An object of class list of length 4.

Value

data

A data frame with 1024 rows and 100 columns.
Each column represents one sample of the aggregated functions with AR(1) noise.

weigths

A data frame with 2 rows and 100 columns.
Each column contains the random concentrations used to aggregate the two functions in each sample.

x

A numeric vector of length 1024.
The grid of x-values used in the simulation, equally spaced from 0 to 1.

alphas

A data frame with 1024 rows and 2 columns.
The true values of the functions α1(x)\alpha_1(x) and α2(x)\alpha_2(x) evaluated over the x grid.


Simulated Data Splines

Description

This is a simulated dataset designed to illustrate the functionalities of the package. It contains 100 samples of aggregated data generated from two functions, α1(x)\alpha_1(x) and α2(x)\alpha_2(x), with added Gaussian noise N(0,0.01)N(0, 0.01).

The functions used in the simulation are:

α1(x)=sin⁡(5x)e−x2α2(x)=1.2log⁡(1+9x)log⁡(10)e−x\alpha_1(x) = \sin(5x) e^{-x^2} \quad \alpha_2(x) = \frac{1.2 \log(1 + 9x)}{\log(10)} e^{-x}

The simulations were performed over an equally spaced grid of 1024 points in the interval [0, 1]. These functions were linearly combined using random concentrations to generate the samples, with the addition of Gaussian noise.

Usage

simulated_data_spl

Format

An object of class list of length 4.

Value

data

A data frame with 1024 rows and 100 columns.
Each column represents one sample of the aggregated functions with Gaussian noise.

weigths

A data frame with 2 rows and 100 columns.
Each column contains the random concentrations used to aggregate the two functions in each sample.

x

A numeric vector of length 1024.
The grid of x-values used in the simulation, equally spaced from 0 to 1.

alphas

A data frame with 1024 rows and 2 columns.
The true values of the functions α1(x)\alpha_1(x) and α2(x)\alpha_2(x) evaluated over the x grid.


Simulated Data Wavelets

Description

This is a simulated dataset designed to illustrate the functionalities of the package. It contains 100 samples of aggregated data generated from two functions, α1(x)\alpha_1(x) and α2(x)\alpha_2(x), with added Gaussian noise N(0,0.01)N(0, 0.01).

The functions used in the simulation are:

α1(x)=∑j=111hj(1+∣x−xjwj∣)−4α2(x)=x(1−x)sin⁡(2π(1+0.05)x+0.05)\alpha_1(x) = \sum_{j=1}^{11} h_j \left(1 + \left|\frac{x - x_j}{w_j}\right|\right)^{-4} \quad \alpha_2(x) = \sqrt{x(1-x)}\sin\left(\frac{2\pi(1 + 0.05)}{x + 0.05}\right)

where x=(0.1, 0.13, 0.15, 0.23, 0.25, 0.40, 0.44, 0.65, 0.76, 0.78, 0.81)x = (0.1,\,0.13,\,0.15,\,0.23,\,0.25,\,0.40,\,0.44,\,0.65,\,0.76,\,0.78,\,0.81),

h=(4, 5, 3, 4, 5, 4.2, 2.1, 4.3, 3.1, 5.1, 4.2)h = (4,\,5,\,3,\,4,\,5,\,4.2,\,2.1,\,4.3,\,3.1,\,5.1,\,4.2),

w=(0.005, 0.005, 0.006, 0.01, 0.01, 0.03, 0.01, 0.01, 0.005, 0.008, 0.005)w = (0.005,\,0.005,\,0.006,\,0.01,\,0.01,\,0.03,\,0.01,\,0.01,\,0.005,\,0.008,\,0.005).

The simulations were performed over an equally spaced grid of 1024 points in the interval [0, 1]. These functions were linearly combined using random concentrations to generate the samples, with the addition of Gaussian noise.

Usage

simulated_data_wav

Format

An object of class list of length 4.

Value

data

A data frame with 1024 rows and 100 columns.
Each column represents one sample of the aggregated functions with Gaussian noise.

weigths

A data frame with 2 rows and 100 columns.
Each column contains the random concentrations used to aggregate the two functions in each sample.

x

A numeric vector of length 1024.
The grid of x-values used in the simulation, equally spaced from 0 to 1.

alphas

A data frame with 1024 rows and 2 columns.
The true values of the functions α1(x)\alpha_1(x) and α2(x)\alpha_2(x) evaluated over the x grid.


Weight Estimation

Description

Estimates the weights associated with the functional coefficients αl(x)\alpha_l(x) using the using Ordinary Least Squares.

The problem can be formulated as:

A(x)=∑l=1Lylαl(x)A(x) = \displaystyle \sum_{l=1}^{L} y_l \alpha_l(x)

where A(x)A(x) is the aggregated function evaluated at each point xx, αl(x)\alpha_l(x) are the functional coefficients, and yly_l are the weights to be estimated.

Usage

weight_estimation(data, alpha)

Arguments

data

A numeric vector representing one sample of the aggregated function A(x)A(x), evaluated at a grid of points xx.

alpha

A numeric matrix where each column represents the values of a function αl(x)\alpha_l(x) evaluated at the same grid of points as data.

Value

The function returns a vector with the estimated weights obtained using Ordinary Least Squares.

Examples

weight_estimation(simulated_data_wav$data[,1], simulated_data_wav$alphas)