G07 Chapter Contents
G07 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG07GBF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G07GBF returns a flag indicating whether a single data point is an outlier as defined by Peirce's criterion.

## 2  Specification

 FUNCTION G07GBF ( N, E, VAR1, VAR2, X, LX, UX, IFAIL)
 LOGICAL G07GBF
 INTEGER N, IFAIL REAL (KIND=nag_wp) E, VAR1, VAR2, X, LX, UX

## 3  Description

G07GBF tests a potential outlying value using Peirce's criterion. Let
• $e$ denote a vector of $n$ residuals with mean zero and variance ${\sigma }^{2}$ obtained from fitting some model $M$ to a series of data $y$,
• $\stackrel{~}{e}$ denote the largest absolute residual in $e$, i.e., $\left|\stackrel{~}{e}\right|\ge \left|{e}_{i}\right|$ for all $i$, and let $\stackrel{~}{y}$ denote the data series $y$ with the observation corresponding to $\stackrel{~}{e}$ having been omitted,
• ${\stackrel{~}{\sigma }}^{2}$ denote the residual variance on fitting model $M$ to $\stackrel{~}{y}$,
• $\lambda$ denote the ratio of $\stackrel{~}{\sigma }$ and $\sigma$ with $\lambda =\frac{\stackrel{~}{\sigma }}{\sigma }$.
Peirce's method flags $\stackrel{~}{e}$ as a potential outlier if $\left|\stackrel{~}{e}\right|\ge x$, where $x={\sigma }^{2}z$ and $z$ is obtained from the solution of
 $R = λ 1-n n-1 n-1 nn$ (1)
where
 $R = 2 exp z2 - 1 2 1- Φz$ (2)
and $\Phi$ is the cumulative distribution function for the standard Normal distribution.
Unlike G07GAF, both ${\sigma }^{2}$ and ${\stackrel{~}{\sigma }}^{2}$ must be supplied and therefore no assumptions are made about the nature of the relationship between these two quantities. Only a single potential outlier is tested for at a time.
This routine uses an algorithm described in E04ABF/E04ABA to refine a lower, $l$, and upper, $u$, limit for $x$. This refinement stops when $\left|\stackrel{~}{e}\right| or $\left|\stackrel{~}{e}\right|>u$.
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

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{N}}\ge 3$.
2:     E – REAL (KIND=nag_wp)Input
On entry: $\stackrel{~}{e}$, the value being tested.
3:     VAR1 – REAL (KIND=nag_wp)Input
On entry: ${\sigma }^{2}$, the residual variance on fitting model $M$ to $y$.
Constraint: ${\mathbf{VAR1}}>0.0$.
4:     VAR2 – REAL (KIND=nag_wp)Input
On entry: ${\stackrel{~}{\sigma }}^{2}$, the residual variance on fitting model $M$ to $\stackrel{~}{y}$.
Constraints:
• ${\mathbf{VAR2}}>0.0$;
• ${\mathbf{VAR2}}<{\mathbf{VAR1}}$.
5:     X – REAL (KIND=nag_wp)Output
On exit: an estimated value of $x$, the cutoff that indicates an outlier.
6:     LX – REAL (KIND=nag_wp)Output
On exit: $l$, the lower limit for $x$.
7:     UX – REAL (KIND=nag_wp)Output
On exit: $u$, the upper limit for $x$.
8:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{N}}<3$.
${\mathbf{IFAIL}}=3$
On entry, ${\mathbf{VAR1}}\le 0.0$.
${\mathbf{IFAIL}}=4$
On entry, ${\mathbf{VAR2}}\le 0.0$ or ${\mathbf{VAR2}}\ge {\mathbf{VAR1}}$.

Not applicable.

None.

## 9  Example

This example reads in a series of values and variances and checks whether each is a potential outlier.
The dataset used is from Peirce's original paper and consists of fifteen observations on the vertical semidiameter of Venus. Each subsequent line in the dataset, after the first, is the result of dropping the observation with the highest absolute value from the previous data and recalculating the variance.

### 9.1  Program Text

Program Text (g07gbfe.f90)

### 9.2  Program Data

Program Data (g07gbfe.d)

### 9.3  Program Results

Program Results (g07gbfe.r)