Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_univar_outlier_peirce_2var (g07gb)

Purpose

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

Syntax

[result, x, lx, ux, ifail] = g07gb(n, e, var1, var2)
[result, x, lx, ux, ifail] = nag_univar_outlier_peirce_2var(n, e, var1, var2)

Description

nag_univar_outlier_peirce_2var (g07gb) tests a potential outlying value using Peirce's criterion. Let
• e$e$ denote a vector of n$n$ residuals with mean zero and variance σ2${\sigma }^{2}$ obtained from fitting some model M$M$ to a series of data y$y$,
• $\stackrel{~}{e}$ denote the largest absolute residual in e$e$, i.e., || |ei| $|\stackrel{~}{e}|\ge |{e}_{i}|$ for all i$i$, and let $\stackrel{~}{y}$ denote the data series y$y$ with the observation corresponding to $\stackrel{~}{e}$ having been omitted,
• σ̃2${\stackrel{~}{\sigma }}^{2}$ denote the residual variance on fitting model M$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 ||x$|\stackrel{~}{e}|\ge x$, where x = σ2z$x={\sigma }^{2}z$ and z$z$ is obtained from the solution of
 R = λ1 − n ( (n − 1)n − 1 )/(nn) $R = λ 1-n (n-1) n-1 nn$ (1)
where
 R = 2 exp((( z2 − 1 )/2)(1 − Φ(z))) $R = 2 exp( ( z2 - 1 2 ) ( 1- Φ(z) ) )$ (2)
and Φ$\Phi$ is the cumulative distribution function for the standard Normal distribution.
Unlike nag_univar_outlier_peirce_1var (g07ga), both σ2${\sigma }^{2}$ and σ̃2${\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_func (e04ab) to refine a lower, l$l$, and upper, u$u$, limit for x$x$. This refinement stops when || < l$|\stackrel{~}{e}| or || > u$|\stackrel{~}{e}|>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

Parameters

Compulsory Input Parameters

1:     n – int64int32nag_int scalar
n$n$, the number of observations.
Constraint: n3${\mathbf{n}}\ge 3$.
2:     e – double scalar
$\stackrel{~}{e}$, the value being tested.
3:     var1 – double scalar
σ2${\sigma }^{2}$, the residual variance on fitting model M$M$ to y$y$.
Constraint: var1 > 0.0${\mathbf{var1}}>0.0$.
4:     var2 – double scalar
σ̃2${\stackrel{~}{\sigma }}^{2}$, the residual variance on fitting model M$M$ to $\stackrel{~}{y}$.
Constraints:
• var2 > 0.0${\mathbf{var2}}>0.0$;
• ${\mathbf{var2}}<{\mathbf{var1}}$.

None.

None.

Output Parameters

1:     result – logical scalar
The result of the function.
2:     x – double scalar
An estimated value of x$x$, the cutoff that indicates an outlier.
3:     lx – double scalar
l$l$, the lower limit for x$x$.
4:     ux – double scalar
u$u$, the upper limit for x$x$.
5:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
Constraint: n3${\mathbf{n}}\ge 3$.
ifail = 3${\mathbf{ifail}}=3$
Constraint: var1 > 0.0${\mathbf{var1}}>0.0$.
ifail = 4${\mathbf{ifail}}=4$
Constraint: ${\mathbf{var2}}<{\mathbf{var1}}$.
Constraint: var2 > 0.0${\mathbf{var2}}>0.0$.

Not applicable.

None.

Example

```function nag_univar_outlier_peirce_2var_example
ns = [int64(15); 14; 13];
es = [-1.4; 1.01; 0.63];
var1s = [0.303; 0.161; 0.103];
var2s = [0.161; 0.103; 0.08];
for i = 1:3
% Check whether es(i) is a potential outlier
[outlier, x, lx, ux, ifail] = nag_univar_outlier_peirce_2var(ns(i), es(i), var1s(i), var2s(i));

% Display results
if ifail == 0
fprintf('\nSample size                              : %10d\n', ns(i));
fprintf('Largest absolute residual (E)            : %10.3f\n', es(i));
fprintf('Variance for whole sample                : %10.3f\n', var1s(i));
fprintf('Variance excluding E                     : %10.3f\n', var2s(i));
fprintf('Estimate for cutoff (X)                  : %10.3f\n', x);
fprintf('Lower limit for cutoff (LX)              : %10.3f\n', lx);
fprintf('Upper limit for cutoff (UX)              : %10.3f\n', ux);
if outlier
fprintf('e is a potential outlier\n');
else
fprintf('e does not appear to be an outlier\n');
end
end
end
```
```

Sample size                              :         15
Largest absolute residual (E)            :     -1.400
Variance for whole sample                :      0.303
Variance excluding E                     :      0.161
Estimate for cutoff (X)                  :      0.000
Lower limit for cutoff (LX)              :      0.000
Upper limit for cutoff (UX)              :      0.000
e is a potential outlier

Sample size                              :         14
Largest absolute residual (E)            :      1.010
Variance for whole sample                :      0.161
Variance excluding E                     :      0.103
Estimate for cutoff (X)                  :      0.105
Lower limit for cutoff (LX)              :      0.100
Upper limit for cutoff (UX)              :      0.110
e is a potential outlier

Sample size                              :         13
Largest absolute residual (E)            :      0.630
Variance for whole sample                :      0.103
Variance excluding E                     :      0.080
Estimate for cutoff (X)                  :      1.059
Lower limit for cutoff (LX)              :      1.011
Upper limit for cutoff (UX)              :      1.155
e does not appear to be an outlier

```
```function g07gb_example
ns = [int64(15); 14; 13];
es = [-1.4; 1.01; 0.63];
var1s = [0.303; 0.161; 0.103];
var2s = [0.161; 0.103; 0.08];
for i = 1:3
% Check whether es(i) is a potential outlier
[outlier, x, lx, ux, ifail] = g07gb(ns(i), es(i), var1s(i), var2s(i));

% Display results
if ifail == 0
fprintf('\nSample size                              : %10d\n', ns(i));
fprintf('Largest absolute residual (E)            : %10.3f\n', es(i));
fprintf('Variance for whole sample                : %10.3f\n', var1s(i));
fprintf('Variance excluding E                     : %10.3f\n', var2s(i));
fprintf('Estimate for cutoff (X)                  : %10.3f\n', x);
fprintf('Lower limit for cutoff (LX)              : %10.3f\n', lx);
fprintf('Upper limit for cutoff (UX)              : %10.3f\n', ux);
if outlier
fprintf('e is a potential outlier\n');
else
fprintf('e does not appear to be an outlier\n');
end
end
end
```
```

Sample size                              :         15
Largest absolute residual (E)            :     -1.400
Variance for whole sample                :      0.303
Variance excluding E                     :      0.161
Estimate for cutoff (X)                  :      0.000
Lower limit for cutoff (LX)              :      0.000
Upper limit for cutoff (UX)              :      0.000
e is a potential outlier

Sample size                              :         14
Largest absolute residual (E)            :      1.010
Variance for whole sample                :      0.161
Variance excluding E                     :      0.103
Estimate for cutoff (X)                  :      0.105
Lower limit for cutoff (LX)              :      0.100
Upper limit for cutoff (UX)              :      0.110
e is a potential outlier

Sample size                              :         13
Largest absolute residual (E)            :      0.630
Variance for whole sample                :      0.103
Variance excluding E                     :      0.080
Estimate for cutoff (X)                  :      1.059
Lower limit for cutoff (LX)              :      1.011
Upper limit for cutoff (UX)              :      1.155
e does not appear to be an outlier

```