— Back to Blogs & Publications Outlier detection statistical plot on screen

Chemometric Outlier Detection: Mahalanobis Distance vs. Hotelling's T²

How Mahalanobis distance, Hotelling’s T², leverage and Q residuals tell a process NIR analyzer whether a spectrum belongs to the calibration it is about to use, how the limits for these statistics are derived, and why the same quantity appears under different names and scales in different software — with the original statistical papers and the relevant ASTM practices.

Why every prediction needs a validity check

A multivariate calibration, whether it runs on an inline analyzer in the chemical and pharmaceutical industry or on a benchtop instrument in a feed mill, is an empirical model of the samples it was trained on, and Martens and Næs list automatic outlier detection among the things such a calibration must provide [1]. ASTM E1655 states that the calibration procedures define the range over which measurements are valid and treats the handling of outliers as part of a conforming calibration [2]. For routine operation ASTM D6122 is explicit: the applicability of a model to a sample cannot be assumed, outlier detection demonstrates that the calibration applies to the measured spectrum, and if the spectrum is an outlier the analyzer result is invalid, although the test does not say whether the sample, the model or the instrument is the cause [3].

Mahalanobis distance: a distance that respects covariance

The generalised distance introduced by Mahalanobis in 1936 measures how far a point lies from the centre of a population in units of that population’s own variance and covariance [4]. The tutorial by De Maesschalck, Jouan-Rimbaud and Massart explains why this matters for spectra: neighbouring wavelengths are strongly correlated, so a Euclidean distance treats a normal change along the main direction of spectral variation exactly like an equally large change in a direction the calibration set never showed, whereas the Mahalanobis distance scales each direction by its variance [5]. Because the full-wavelength covariance matrix of a NIR data set cannot be inverted reliably, the distance is computed in principal-component or PLS score space, on the components the model actually uses, a case the tutorial treats alongside the original variable space [5].

Hotelling’s T², leverage and GH: one quantity on several scales

Hotelling generalised Student’s ratio to several correlated variables in 1931; his T² is a deviation vector weighted by the inverse covariance matrix, the squared Mahalanobis distance under another name [6]. Garrido-Varo, García-Olmo and Fearn establish that the squared Mahalanobis distance D², Hotelling’s T², the leverage L of The Unscrambler and the GH distance of WinISI are related as D² = T² ≈ L·n ≈ GH·k, where n and k are the numbers of samples and variables in the data that define the distance, so a threshold copied between packages without this translation is wrong by a data-dependent factor [7]. The GH scale comes from Shenk and Westerhaus, who used a standardised distance of 3.0 from the population mean as the boundary for excluding spectral outliers, while a minimum neighbourhood distance of 0.6 between samples gave an adequate calibration set in their study [8].

Q residuals: what the model did not explain

A distance in score space only asks whether the sample is extreme along the directions the model knows. A spectrum can sit inside those limits and still contain structure the model has never seen, such as a band from a contaminant or an instrument artefact. Jackson and Mudholkar addressed this with tests on the residuals of a principal-component model, the difference between an observation and its reconstruction from fewer than the full set of components, for a single observation vector and for a group, with outlier detection in quality control as the intended use [9]. The sum of squared residuals is the Q statistic or squared prediction error (SPE); Jackson’s book treats Q and T² together [10]. Nomikos and MacGregor built multivariate control charts on both statistics, with control limits developed from the historical reference distribution of past successful batches [11]. The two are complementary: a sample flagged by T² is unusual in a direction the calibration spans, a sample flagged by Q lies off the model plane, and only the second reveals a new interferent [9][10].

Setting the limits: F, beta and chi-square

Limits for T² depend on whether the tested sample was part of the data that defined the distance. Tracy, Young and Mason point out that the approximate F and chi-square limits normally used are conservative when only individual observations are available at the start-up stage, and derive an exact beta-distribution limit for that case [12]. In a calibration project this is the difference between screening the calibration samples themselves and judging a new process spectrum against a frozen model, where the F-based limit applies [12]. For Q, the approximate distribution derived by Jackson and Mudholkar gives a limit at a chosen significance level [9]. A separate hazard affects the calibration stage: Rousseeuw and van Zomeren show that the classical mean and covariance are themselves distorted by the outliers they are meant to find, so that several outliers mask one another, and propose distances computed from robust estimates of location and covariance [13]. Three points follow:

  • Clean the calibration set with the right limit: the beta-based T² limit or a robust distance, since the F approximation is conservative at this stage and a classical covariance can be masked by multiple outliers [12][13].
  • Use T² and Q together in routine prediction, plus the optional nearest-neighbour test that D6122 recommends when calibration spectra are highly clustered [3][9].
  • Record which statistic and scale a limit refers to, because GH, leverage and T² differ by factors of n and k [7].

Outlier statistics in caliX and ProChem

The caliX suite lists Hotelling’s T² and Q residuals, PLS leverage and the Mahalanobis distance among its outlier-detection methods and offers GH/NH cutoffs for cleaning a calibration set; ProChem runs the exported models on USTECH analyzers and links them to PLC or SCADA systems with dashboards and alarms, so that a spectrum outside the calibration space is flagged rather than silently converted into a value. Which limits suit a given product and instrument is established in a feasibility study with your own samples.

References

  • [1] Martens, H., Næs, T. (1989). Multivariate Calibration. John Wiley & Sons, Chichester. wiley.com/en-us/Multivariate+Calibration-p-9780471930471
  • [2] ASTM E1655-17(2024). Standard Practices for Infrared Multivariate Quantitative Analysis. ASTM International, West Conshohocken, PA. store.astm.org/e1655-17r24.html
  • [3] ASTM D6122-25. Standard Practice for Validation of the Performance of Multivariate Online, At-Line, Field and Laboratory Infrared Spectrophotometer, and Raman Spectrometer Based Analyzer Systems. ASTM International, West Conshohocken, PA. store.astm.org/d6122-25.html
  • [4] Mahalanobis, P.C. (2018). Reprint of: Mahalanobis, P.C. (1936) “On the generalised distance in statistics.” Sankhya A, 80(S1), 1–7; originally Proceedings of the National Institute of Sciences of India, 2(1), 49–55. doi:10.1007/s13171-019-00164-5
  • [5] De Maesschalck, R., Jouan-Rimbaud, D., Massart, D.L. (2000). The Mahalanobis distance. Chemometrics and Intelligent Laboratory Systems, 50(1), 1–18. doi:10.1016/S0169-7439(99)00047-7
  • [6] Hotelling, H. (1931). The generalization of Student’s ratio. The Annals of Mathematical Statistics, 2(3), 360–378. doi:10.1214/aoms/1177732979
  • [7] Garrido-Varo, A., García-Olmo, J., Fearn, T. (2019). A note on Mahalanobis and related distance measures in WinISI and The Unscrambler. Journal of Near Infrared Spectroscopy, 27(4), 253–258. doi:10.1177/0967033519848296
  • [8] Shenk, J.S., Westerhaus, M.O. (1991). Population definition, sample selection, and calibration procedures for near infrared reflectance spectroscopy. Crop Science, 31(2), 469–474. doi:10.2135/cropsci1991.0011183X003100020049x
  • [9] Jackson, J.E., Mudholkar, G.S. (1979). Control procedures for residuals associated with principal component analysis. Technometrics, 21(3), 341–349. doi:10.1080/00401706.1979.10489779
  • [10] Jackson, J.E. (1991). A User’s Guide to Principal Components. John Wiley & Sons, New York. doi:10.1002/0471725331
  • [11] Nomikos, P., MacGregor, J.F. (1995). Multivariate SPC charts for monitoring batch processes. Technometrics, 37(1), 41–59. doi:10.1080/00401706.1995.10485888
  • [12] Tracy, N.D., Young, J.C., Mason, R.L. (1992). Multivariate control charts for individual observations. Journal of Quality Technology, 24(2), 88–95. doi:10.1080/00224065.1992.12015232
  • [13] Rousseeuw, P.J., van Zomeren, B.C. (1990). Unmasking multivariate outliers and leverage points. Journal of the American Statistical Association, 85(411), 633–639. doi:10.1080/01621459.1990.10474920
USTECH Innovations Logo

Discuss this application for your process

Our application team can walk through the method, share the supporting literature and discuss how it applies to your process.

Contact Us

Read Next

Introduction to PLS Regression in caliX Suite
GUIDE

Introduction to PLS Regression in caliX Suite

A practitioner's walk through a PLS calibration: how the data are split, how the pre-processing and the number of latent variables are chosen by validation, which diagnostics to read, and how the model is kept alive in production.

Read Guide
Developing Robust Chemometric Classification Models via PCA
GUIDE

Developing Robust Chemometric Classification Models via PCA

How PCA scores, loadings and residuals become a classification model, where the Hotelling and Q limits come from, why class-modelling differs from PLS-DA, and how regulators expect a qualitative NIR model to be validated.

Read Guide