Skip to main content

energy_test

Function energy_test 

Source
pub fn energy_test<T: Float, I: IntoIterator<Item = T>>(
    data: I,
    method: EnergyTestMethod,
) -> Result<Computation<T>, Error>
Expand description

Performs the Energy test for univariate normality.

It assesses the null hypothesis that the data comes from a normal distribution with unknown mean and variance (Case 4).

It calculates the Energy statistic (E) and determines the p-value using either a parametric bootstrap (Monte Carlo) or the asymptotic distribution.

Takes an argument data which is an iterator over floating-point numbers (impl IntoIterator<Item = T>). Must contain at least 5 elements. Also takes method which is the method for calculating the p-value (MonteCarlo or Asymptotic).

ยงExamples

use normality::{Computation, EnergyTestMethod, energy_test};

let normal_data = vec![-0.9, -0.6, -0.3, 0.0, 0.2, 0.5, 0.8, 1.1, 1.4, 1.6];

// Use the Asymptotic method (fast, deterministic)
let result = energy_test(normal_data.iter().copied(), EnergyTestMethod::Asymptotic).unwrap();
assert!(result.p_value > 0.05);

// Use the Monte Carlo method (robust)
let mc_result = energy_test(normal_data, EnergyTestMethod::MonteCarlo(1000)).unwrap();
assert!(mc_result.p_value > 0.05);