The routine may be called by the names g07gaf or nagf_univar_outlier_peirce_1var.
3Description
g07gaf 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
(1)
where
(2)
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
(3)
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.
4References
Gould B A (1855) On Peirce's criterion for the rejection of doubtful observations, with tables for facilitating its application The Astronomical Journal45
Peirce B (1852) Criterion for the rejection of doubtful observations The Astronomical Journal45
5Arguments
1: – IntegerInput
On entry: , the number of observations.
Constraint:
.
2: – IntegerInput
On entry: , 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:
.
3: – Real (Kind=nag_wp) arrayInput
On entry: , the data being tested.
4: – Real (Kind=nag_wp)Input
On entry: if , mean must contain , the mean of , otherwise mean is not referenced and the mean is calculated from the data supplied in y.
5: – Real (Kind=nag_wp)Input
On entry: if , var must contain , the variance of , otherwise the variance is calculated from the data supplied in y.
6: – Integer arrayOutput
On exit: the indices of the values in y sorted in descending order of the absolute difference from the mean, therefore,
, for .
7: – IntegerOutput
On exit: 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.
8: – IntegerInput
On entry: the maximum number of values to be returned in arrays diff and llamb.
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or is used it is essential to test the value of ifail on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry, .
Constraint: .
On entry, and .
Constraint: .
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
Not applicable.
8Parallelism and Performance
g07gaf is not threaded in any implementation.
9Further Comments
One problem with Peirce's algorithm as implemented in g07gaf 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 g07gbf should be used instead.
10Example
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.