# NAG FL Interfaceg07gbf (outlier_​peirce_​2var)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Function g07gbf ( n, e, var1, var2, x, lx, ux,
 Logical :: g07gbf Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: e, var1, var2 Real (Kind=nag_wp), Intent (Out) :: x, lx, ux
#include <nag.h>
 Nag_Boolean g07gbf_ (const Integer *n, const double *e, const double *var1, const double *var2, double *x, double *lx, double *ux, Integer *ifail)
The routine may be called by the names g07gbf or nagf_univar_outlier_peirce_2var.

## 3Description

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., $|\stackrel{~}{e}|\ge |{e}_{i}|$ 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 $|\stackrel{~}{e}|\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 $|\stackrel{~}{e}| or $|\stackrel{~}{e}|>u$.

## 4References

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

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}\ge 3$.
2: $\mathbf{e}$Real (Kind=nag_wp) Input
On entry: $\stackrel{~}{e}$, the value being tested.
3: $\mathbf{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: $\mathbf{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: $\mathbf{x}$Real (Kind=nag_wp) Output
On exit: an estimated value of $x$, the cutoff that indicates an outlier.
6: $\mathbf{lx}$Real (Kind=nag_wp) Output
On exit: $l$, the lower limit for $x$.
7: $\mathbf{ux}$Real (Kind=nag_wp) Output
On exit: $u$, the upper limit for $x$.
8: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-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}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 3$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{var1}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{var1}}>0.0$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{var1}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{var2}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{var2}}<{\mathbf{var1}}$.
On entry, ${\mathbf{var2}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{var2}}>0.0$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

g07gbf is not threaded in any implementation.

None.

## 10Example

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.

### 10.1Program Text

Program Text (g07gbfe.f90)

### 10.2Program Data

Program Data (g07gbfe.d)

### 10.3Program Results

Program Results (g07gbfe.r)