naginterfaces.library.univar.outlier_peirce_1var¶
- naginterfaces.library.univar.outlier_peirce_1var(p, y, ldiff, mean=0.0, var=0.0)[source]¶
outlier_peirce_1var
identifies outlying values using Peirce’s criterion.For full information please refer to the NAG Library document for g07ga
https://www.nag.com/numeric/nl/nagdoc_28.7/flhtml/g07/g07gaf.html
- Parameters
- pint
, 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.
- yfloat, array-like, shape
, the data being tested.
- ldiffint
The maximum number of values to be returned in arrays and .
If , arrays and are not referenced.
- meanfloat, optional
If , must contain , the mean of , otherwise is not referenced and the mean is calculated from the data supplied in .
- varfloat, optional
If , must contain , the variance of , otherwise the variance is calculated from the data supplied in .
- Returns
- ioutint, ndarray, shape
The indices of the values in sorted in descending order of the absolute difference from the mean, therefore, , for .
- nioutint
The number of potential outliers. The indices for these potential outliers are held in the first elements of . By construction there can be at most values flagged as outliers.
- difffloat, ndarray, shape
holds for observation , for .
- llambfloat, ndarray, shape
holds for observation , for .
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- Notes
outlier_peirce_1var
flags outlying values in data using Peirce’s criterion. Letdenote 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 [equation]. Equation [equation] is then used to obtain an estimate of and then equation [equation] 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)