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

# Syntax

C#
```public static bool g07gb(
int n,
double e,
double var1,
double var2,
out double x,
out double lx,
out double ux,
out int ifail
)```
Visual Basic
```Public Shared Function g07gb ( _
n As Integer, _
e As Double, _
var1 As Double, _
var2 As Double, _
<OutAttribute> ByRef x As Double, _
<OutAttribute> ByRef lx As Double, _
<OutAttribute> ByRef ux As Double, _
<OutAttribute> ByRef ifail As Integer _
) As Boolean```
Visual C++
```public:
static bool g07gb(
int n,
double e,
double var1,
double var2,
[OutAttribute] double% x,
[OutAttribute] double% lx,
[OutAttribute] double% ux,
[OutAttribute] int% ifail
)```
F#
```static member g07gb :
n : int *
e : float *
var1 : float *
var2 : float *
x : float byref *
lx : float byref *
ux : float byref *
ifail : int byref -> bool
```

#### Parameters

n
Type: System..::..Int32
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}\ge 3$.
e
Type: System..::..Double
On entry: $\stackrel{~}{e}$, the value being tested.
var1
Type: System..::..Double
On entry: ${\sigma }^{2}$, the residual variance on fitting model $M$ to $y$.
Constraint: ${\mathbf{var1}}>0.0$.
var2
Type: System..::..Double
On entry: ${\stackrel{~}{\sigma }}^{2}$, the residual variance on fitting model $M$ to $\stackrel{~}{y}$.
Constraints:
• ${\mathbf{var2}}>0.0$;
• ${\mathbf{var2}}<{\mathbf{var1}}$.
x
Type: System..::..Double%
On exit: an estimated value of $x$, the cutoff that indicates an outlier.
lx
Type: System..::..Double%
On exit: $l$, the lower limit for $x$.
ux
Type: System..::..Double%
On exit: $u$, the upper limit for $x$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

#### Return Value

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

# Description

g07gb 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-nn-1n-1nn$ (1)
where
 $R=2expz2-121-Φz$ (2)
and $\Phi$ is the cumulative distribution function for the standard Normal distribution.
Unlike g07ga, 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 method uses an algorithm described in e04ab 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$.

# 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

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\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}}$.
${\mathbf{ifail}}=-9000$
An error occured, see message report.

Not applicable.

None.

None.

# 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.

Example program (C#): g07gbe.cs

Example program data: g07gbe.d

Example program results: g07gbe.r