Skip to main content

dynamical_correlation

Function dynamical_correlation 

Source
pub fn dynamical_correlation(
    x: &FdMatrix,
    y: &FdMatrix,
    argvals: &[f64],
) -> Result<f64, FdarError>
Expand description

Dynamical (functional) correlation between two paired functional samples.

Implements the Dubin–Müller dynamical correlation (as in fdapace::DynCorr): each curve is centered by its own integrated mean, then by the population mean at each point, standardized to unit functional L2 norm, and the per-subject integrated inner product (divided by the domain length) is averaged over the sample. The result is a scalar in [-1, 1]: it is 1 when the two samples co-vary perfectly (e.g. x == y), -1 when they are exact negatives, and near 0 for independent samples.

Both samples must be observed on the same argument grid argvals (dynamical correlation is a same-domain pointwise construction).

§Errors

Returns FdarError if the two samples have different row counts or column counts, if argvals.len() does not match the number of evaluation points, if n < 2, or if the domain has zero length.

§Examples

use fdars_core::matrix::FdMatrix;
use fdars_core::dynamical_correlation;

let argvals: Vec<f64> = (0..10).map(|i| i as f64 / 9.0).collect();
let data = FdMatrix::from_column_major(
    (0..50).map(|i| (i as f64 * 0.3).sin()).collect(),
    5, 10,
).unwrap();
let r = dynamical_correlation(&data, &data, &argvals).unwrap();
assert!((r - 1.0).abs() < 1e-9);