PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_univar_outlier_peirce_1var (g07ga)
Purpose
nag_univar_outlier_peirce_1var (g07ga) identifies outlying values using Peirce's criterion.
Syntax
[
iout,
niout,
dif,
llamb,
ifail] = g07ga(
p,
y,
ldiff, 'n',
n, 'mean_p',
mean_p, 'var',
var)
[
iout,
niout,
dif,
llamb,
ifail] = nag_univar_outlier_peirce_1var(
p,
y,
ldiff, 'n',
n, 'mean_p',
mean_p, 'var',
var)
Description
nag_univar_outlier_peirce_1var (g07ga) flags outlying values in data using Peirce's criterion. Let
- denote a vector of observations (for example the residuals) obtained from a model with parameters,
- denote the number of potential outlying values,
- and denote the mean and variance of respectively,
- denote a vector of length constructed by dropping the values from
with the largest value of ,
- denote the (unknown) variance of ,
-
denote the ratio of and with
.
Peirce's method flags
as a potential outlier if
, where
and
is obtained from the solution of
where
and
is the cumulative distribution function for the standard Normal distribution.
As
is unknown an assumption is made that the relationship between
and
, hence
, depends only on the sum of squares of the rejected observations and the ratio estimated as
which gives
A value for the cutoff
is calculated iteratively. An initial value of
is used and a value of
is estimated using equation
(1). Equation
(3) is then used to obtain an estimate of
and then equation
(2) is used to get a new estimate for
. This process is then repeated until the relative change in
between consecutive iterations is
, where
is
machine precision.
By construction, the cutoff for testing for potential outliers is less than the cutoff for testing for potential outliers. Therefore Peirce's criterion is used in sequence with the existence of a single potential outlier being investigated first. If one is found, the existence of two potential outliers is investigated etc.
If one of a duplicate series of observations is flagged as an outlier, then all of them are flagged as outliers.
References
Gould B A (1855) On Peirce's criterion for the rejection of doubtful observations, with tables for facilitating its application The Astronomical Journal 45
Peirce B (1852) Criterion for the rejection of doubtful observations The Astronomical Journal 45
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
, the number of parameters in the model used in obtaining the . If is an observed set of values, as opposed to the residuals from fitting a model with parameters, then should be set to , i.e., as if a model just containing the mean had been used.
Constraint:
.
- 2:
– double array
-
, the data being tested.
- 3:
– int64int32nag_int scalar
-
The maximum number of values to be returned in arrays
dif and
llamb.
If
, arrays
dif and
llamb are not referenced.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
y.
, the number of observations.
Constraint:
.
- 2:
– double scalar
Default:
If
,
mean_p must contain
, the mean of
, otherwise
mean_p is not referenced and the mean is calculated from the data supplied in
y.
- 3:
– double scalar
Default:
If
,
var must contain
, the variance of
, otherwise the variance is calculated from the data supplied in
y.
Output Parameters
- 1:
– int64int32nag_int array
-
The indices of the values in
y sorted in descending order of the absolute difference from the mean, therefore
, for
.
- 2:
– int64int32nag_int scalar
-
The number of potential outliers. The indices for these potential outliers are held in the first
niout elements of
iout. By construction there can be at most
values flagged as outliers.
- 3:
– double array
-
holds for observation , for .
- 4:
– double array
-
holds for observation , for .
- 5:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
Constraint: .
-
-
Constraint: .
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
Not applicable.
Further Comments
One problem with Peirce's algorithm as implemented in
nag_univar_outlier_peirce_1var (g07ga) is the assumed relationship between
, the variance using the full dataset, and
, the variance with the potential outliers removed. In some cases, for example if the data
were the residuals from a linear regression, this assumption may not hold as the regression line may change significantly when outlying values have been dropped resulting in a radically different set of residuals. In such cases
nag_univar_outlier_peirce_2var (g07gb) should be used instead.
Example
This example reads in a series of data and flags any potential outliers.
The dataset used is from Peirce's original paper and consists of fifteen observations on the vertical semidiameter of Venus.
Open in the MATLAB editor:
g07ga_example
function g07ga_example
fprintf('g07ga example results\n\n');
y = [-0.30; 0.48; 0.63; -0.22; 0.18;
-0.44; -0.24; -0.13; -0.05; 0.39;
1.01; 0.06; -1.40; 0.20; 0.10];
p = int64(2);
ldiff = int64(1);
[iout, niout, dif, llamb, ifail] = ...
g07ga(p, y, ldiff);
fprintf('Number of potential outliers: %2d\n',niout);
fprintf(' No. Index Value');
if ldiff > 0
fprintf(' Diff ln(lambda^2)');
end
fprintf('\n');
for i=1:niout
fprintf(' %4d %4d %10.2f', i, iout(i), y(iout(i)));
if i <= ldiff
fprintf(' %10.2f %10.2f', dif(i), llamb(i));
end
fprintf('\n');
end
g07ga example results
Number of potential outliers: 2
No. Index Value Diff ln(lambda^2)
1 13 -1.40 0.31 -0.30
2 11 1.01
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015