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 the paper <doi:10.1515/mcma-2023-2016> and the Master's thesis <doi:10.47749/T/UNICAMP.2009.471073>.
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: 1.0.0
Built: 2026-05-16 06:09:46 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$data, simulated_data$weights, simulated_data$x)
functional_calibration_splines(simulated_data$data, simulated_data$weights, simulated_data$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 = FALSE,
  type = "soft",
  singular = 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.

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.

Examples

functional_calibration_wavelets(simulated_data$data, simulated_data$weights)
functional_calibration_wavelets(simulated_data$data, simulated_data$weights,
                                tau = 5, p = 0.95, sigma = 0.1, x = simulated_data$x)
functional_calibration_wavelets(simulated_data$data, simulated_data$weights,
                                method = "universal")

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$alphas, c(0.7, 0.3))
plot_aggregated_curve(simulated_data$alphas, c(0.7, 0.3),
                      "Aggregated Curve Example", simulated_data$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)ex2α2(x)={2,x<00,0x<1.53,x1.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.


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$data[,1], simulated_data$alphas)