Skip to main content

boxcox_capability

Function boxcox_capability 

Source
pub fn boxcox_capability(
    data: &[f64],
    usl: Option<f64>,
    lsl: Option<f64>,
) -> Result<NonNormalCapabilityResult, NonNormalCapabilityError>
Expand description

Compute process capability indices for non-normal data via Box-Cox transformation.

The data are first transformed to approximate normality using the optimal Box-Cox parameter λ (estimated via maximum likelihood over [-2, 2]). Specification limits are transformed using the same λ. Standard capability indices (Cp, Cpk, Pp, Ppk) are then computed on the transformed scale.

§Arguments

  • data — Process observations. All values must be strictly positive.
  • usl — Upper specification limit (optional). Must be positive if provided.
  • lsl — Lower specification limit (optional). Must be positive if provided.

§Errors

Returns NonNormalCapabilityError if:

  • Fewer than 4 data points are provided.
  • Any data value is ≤ 0 (Box-Cox requires strictly positive data).
  • Neither usl nor lsl is provided.
  • A specification limit is ≤ 0 (cannot be Box-Cox transformed).
  • Capability computation fails (e.g., zero variance in transformed data).

§Examples

use u_analytics::capability::boxcox_capability;

// Right-skewed data
let data: Vec<f64> = (1..=20).map(|i| (i as f64 * 0.3_f64).exp()).collect();
let result = boxcox_capability(&data, Some(100.0), Some(1.0)).unwrap();
assert!(result.lambda >= -2.0 && result.lambda <= 2.0);
assert!(result.indices.ppk.is_some());