pub fn estimate_lambda(
y: &[f64],
lambda_min: f64,
lambda_max: f64,
) -> Result<f64, TransformError>Expand description
Estimate the optimal Box-Cox λ via maximum likelihood.
Maximises the profile log-likelihood:
ℓ(λ) = -(n/2)·ln(Var_population(y(λ))) + (λ-1)·Σ ln(yᵢ)using a golden-section search over [lambda_min, lambda_max] with up
to 100 iterations (terminating early when the bracket width < 1e-6).
§Errors
TransformError::InsufficientData— fewer than 2 data pointsTransformError::NonPositiveData— any element ≤ 0
§Examples
use u_numflow::transforms::estimate_lambda;
// Exponential data is well-linearised by log (λ ≈ 0).
let y: Vec<f64> = (1..=30).map(|i| (i as f64 * 0.2_f64).exp()).collect();
let lambda = estimate_lambda(&y, -2.0, 2.0).unwrap();
assert!(lambda.abs() < 0.3, "expected lambda near 0, got {lambda}");