Categories &

Functions List

Function Reference: robustcov

statistics: sig = robustcov (X)

statistics: [sig, mu] = robustcov (X)

statistics: [sig, mu, mah] = robustcov (X)

statistics: [sig, mu, mah, outliers] = robustcov (X)

statistics: [sig, mu, mah, outliers, s] = robustcov (X)

statistics: […] = robustcov (…, name, value)

Robust multivariate covariance and mean estimate.

sig = robustcov (X) returns a robust estimate sig of the covariance matrix of the N×P data matrix X, computed so that it is not distorted by outlying observations. Rows of X are observations and columns are variables. Rows containing NaN values are removed with a warning.

[sig, mu, mah, outliers, s] = robustcov (…) also returns the robust mean mu (1×P), the robust Mahalanobis distances mah (N×1) of each observation from the estimated distribution, a logical vector outliers (N×1) flagging observations whose distance exceeds sqrt (chi2inv (0.975, P)), and a structure s holding the estimate metadata. mah and outliers have one row per row of X; for removed rows, mah is NaN and outliers is false. When sig is not positive definite, every distance is 0, removed rows included, and no observation is flagged.

Additional parameters can be specified by Name-Value pair arguments.

NameValue
'Method'the estimator, one of 'fmcd' (default, the Fast Minimum Covariance Determinant algorithm), 'ogk' (the Orthogonalized Gnanadesikan-Kettenring estimator) or 'olivehawkins' (the Olive-Hawkins concentration algorithm). If any of 'ReweightingMethod', 'StartMethod' or 'NumConcentrationSteps' is given and 'Method' is not, the method is 'olivehawkins'.
'OutlierFraction'the maximum fraction of outliers, a scalar in [0, 0.5] (default 0.5), used to set the size of the subsets in 'fmcd' and 'olivehawkins'. It is not valid for 'ogk'.
'NumTrials'a positive integer. For 'fmcd' it is the number of random elemental subsets drawn (default 500). For 'olivehawkins' it is the number of starts and must equal the number of starts in 'StartMethod' (default 2); with 'elemental' alone it is the number of random starts. It is not valid for 'ogk'.
'BiasCorrection'a logical scalar (default true) that applies the small-sample bias correction to the raw and the reweighted 'fmcd' estimate. Only valid for 'fmcd'.
'NumOGKIterations'the number of orthogonalization iterations for 'ogk', a positive integer (default 2). Only valid for 'ogk'.
'UnivariateEstimator'the robust univariate location/scale estimator used by 'ogk', either 'tauscale' (default) or 'qn'. Only valid for 'ogk'.
'ReweightingMethod'the reweighting used by 'olivehawkins', either 'rfch' (default) or 'rmvn'.
'NumConcentrationSteps'the number of concentration steps taken from each start by 'olivehawkins', a positive integer (default 10).
'StartMethod'the starts of 'olivehawkins': one of 'classical', 'medianball' or 'elemental', a function handle [T, C] = f (X) returning a 1×P location and a P×P scatter, or a cell array of these. The default is {'classical', 'medianball'}.

Note on reproducibility. 'fmcd' and the 'elemental' start of 'olivehawkins' draw random subsets, so their exact estimate depends on the random number generator and is not identical to MATLAB’s on data where the optimal subset is ambiguous; on well-separated data both converge to the same estimate.

Small-sample correction. With 'BiasCorrection' enabled, 'fmcd' scales the raw and the reweighted covariance by the small-sample factors of Pison, Van Aelst and Willems (2002), interpolated over 1 - OutlierFraction, as the covMcd function of the R package robustbase computes them. Where those formulas give negative or very large factors, at the default 'OutlierFraction' for up to 9 variables and small samples, the simulated factors of robustbase are used instead. MATLAB applies the formulas there as well, so it can return a covariance with negative variances (for example, with 3 variables and 6 to 8 observations), and for 2 variables it uses other factors, so its estimate differs from this one at every sample size. When the subset is the whole sample, the classical estimate is reweighted with no small-sample factor.

Singular subsets. If 'olivehawkins' finds a singular subset, a warning is issued and the selected estimate is returned without reweighting. A singular estimate gives zero robust distances. When several starts end in singular subsets, the 'medianball' start is selected if present, otherwise the first one listed in 'StartMethod'.

See also: mahal, cov, mad, dbscan

Source Code: robustcov

Robust covariance is unaffected by a cluster of outliers.

 rng (42);
 X = [randn(80,2); 8 + randn(10,2)];
 [sig, mu, mah, outliers] = robustcov (X);
plotted figure

 gscatter (X(:,1), X(:,2), outliers);
error: Invalid call to legend.  Correct usage is:

 -- legend ()
 -- legend COMMAND
 -- legend (STR1, STR2, ...)
 -- legend (CHARMAT)
 -- legend ({CELLSTR})
 -- legend (..., PROPERTY, VALUE, ...)
 -- legend (HOBJS, ...)
 -- legend ("COMMAND")
 -- legend (HAX, ...)
 -- legend (HLEG, ...)
 -- HLEG = legend (...)
 title ("robustcov: inliers vs. flagged outliers");

Olive-Hawkins robust distances expose outliers that the classical Mahalanobis distances mask.

 rng (42);
 X = [randn(80,2); 6 + randn(10,2)];
 [~, ~, mah, outliers] = robustcov (X, "Method", "olivehawkins");
 dcl = sqrt (mahal (X, X));
 plot (dcl(! outliers), mah(! outliers), "bo", ...
       dcl(outliers), mah(outliers), "r+");
 xlabel ("Classical Mahalanobis distance");
 ylabel ("Robust distance");
 legend ("inliers", "flagged outliers");
plotted figure

Tolerance ellipses of the two Olive-Hawkins reweighting methods.

 rng (42);
 X = [randn(80,2); 6 + randn(10,2)];
 [s1, m1] = robustcov (X, "ReweightingMethod", "rfch");
 [s2, m2] = robustcov (X, "ReweightingMethod", "rmvn");
 t = linspace (0, 2 * pi, 100)';
 c = sqrt (chi2inv (0.975, 2));
 e1 = m1 + c * [cos(t), sin(t)] * chol (s1);
 e2 = m2 + c * [cos(t), sin(t)] * chol (s2);
 plot (X(:,1), X(:,2), "k.", e1(:,1), e1(:,2), "b-", e2(:,1), e2(:,2), "r-");
 axis equal;
 legend ("data", "rfch", "rmvn");
plotted figure