nag_outlier_peirce_two_var (g07gbc) (PDF version)
g07 Chapter Contents
g07 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_outlier_peirce_two_var (g07gbc)

## 1  Purpose

nag_outlier_peirce_two_var (g07gbc) returns a flag indicating whether a single data point is an outlier as defined by Peirce's criterion.

## 2  Specification

 #include #include
 Nag_Boolean nag_outlier_peirce_two_var (Integer n, double e, double var1, double var2, double *x, double *lx, double *ux, NagError *fail)

## 3  Description

nag_outlier_peirce_two_var (g07gbc) 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 nag_outlier_peirce (g07gac), 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 function uses an algorithm described in nag_opt_one_var_no_deriv (e04abc) 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$.

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

## 5  Arguments

1:     nIntegerInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}\ge 3$.
2:     edoubleInput
On entry: $\stackrel{~}{e}$, the value being tested.
3:     var1doubleInput
On entry: ${\sigma }^{2}$, the residual variance on fitting model $M$ to $y$.
Constraint: ${\mathbf{var1}}>0.0$.
4:     var2doubleInput
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:     xdouble *Output
On exit: an estimated value of $x$, the cutoff that indicates an outlier.
6:     lxdouble *Output
On exit: $l$, the lower limit for $x$.
7:     uxdouble *Output
On exit: $u$, the upper limit for $x$.
8:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_BAD_PARAM
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 3$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_REAL
On entry, ${\mathbf{var1}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{var1}}>0.0$.
On entry, ${\mathbf{var2}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{var2}}>0.0$.
NE_REAL_2
On entry, ${\mathbf{var1}}=〈\mathit{\text{value}}〉$, ${\mathbf{var2}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{var2}}<{\mathbf{var1}}$.

Not applicable.

Not applicable.

## 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 (g07gbce.c)

### 9.2  Program Data

Program Data (g07gbce.d)

### 9.3  Program Results

Program Results (g07gbce.r)

nag_outlier_peirce_two_var (g07gbc) (PDF version)
g07 Chapter Contents
g07 Chapter Introduction
NAG C Library Manual