Skip to main content

trim_mean

Function trim_mean 

Source
pub fn trim_mean(data: &FdMatrix, alpha: f64) -> Result<Vec<f64>, FdarError>
Expand description

Compute the depth-trimmed mean of functional data.

Excludes the floor(alpha * n) least-deep curves (by Fraiman-Muniz depth) and returns the pointwise mean of the remaining curves. With alpha = 0, all curves are retained and the result equals mean_1d exactly.

§Arguments

  • data - Functional data matrix (n x m), requires n >= 1.
  • alpha - Trimming fraction in [0, 1). A value of alpha = 0.2 removes the 20% least-deep curves before averaging.

§Returns

Length-m vector of trimmed pointwise mean values.

§Errors

Returns FdarError::InvalidParameter if alpha is not in [0, 1), or FdarError::InvalidDimension if n == 0.

§Examples

use fdars_core::matrix::FdMatrix;
use fdars_core::fdata::{trim_mean, mean_1d};

let data = FdMatrix::from_column_major(
    vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0], 3, 2,
).unwrap();
// alpha=0 => no trimming => equals mean
let tm = trim_mean(&data, 0.0).unwrap();
let mu = mean_1d(&data);
for j in 0..2 {
    assert!((tm[j] - mu[j]).abs() < 1e-10);
}