G07 Chapter Contents
G07 Chapter Introduction
NAG Library Manual

NAG Library Routine DocumentG07DAF

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

G07DAF finds the median, median absolute deviation, and a robust estimate of the standard deviation for a set of ungrouped data.

2  Specification

 SUBROUTINE G07DAF ( N, X, Y, XME, XMD, XSD, IFAIL)
 INTEGER N, IFAIL REAL (KIND=nag_wp) X(N), Y(N), XME, XMD, XSD

3  Description

The data consists of a sample of size $n$, denoted by ${x}_{1},{x}_{2},\dots ,{x}_{n}$, drawn from a random variable $X$.
G07DAF first computes the median,
 $θmed=medixi,$
and from this the median absolute deviation can be computed,
 $σmed=medixi-θmed.$
Finally, a robust estimate of the standard deviation is computed,
 $σmed′=σmed/Φ-10.75$
where ${\Phi }^{-1}\left(0.75\right)$ is the value of the inverse standard Normal function at the point $0.75$.
G07DAF is based upon subroutine LTMDDV within the ROBETH library, see Marazzi (1987).

4  References

Huber P J (1981) Robust Statistics Wiley
Marazzi A (1987) Subroutines for robust estimation of location and scale in ROBETH Cah. Rech. Doc. IUMSP, No. 3 ROB 1 Institut Universitaire de Médecine Sociale et Préventive, Lausanne

5  Parameters

1:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{N}}>1$.
2:     $\mathrm{X}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: the vector of observations, ${x}_{1},{x}_{2},\dots ,{x}_{n}$.
3:     $\mathrm{Y}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the observations sorted into ascending order.
4:     $\mathrm{XME}$ – REAL (KIND=nag_wp)Output
On exit: the median, ${\theta }_{\mathrm{med}}$.
5:     $\mathrm{XMD}$ – REAL (KIND=nag_wp)Output
On exit: the median absolute deviation, ${\sigma }_{\mathrm{med}}$.
6:     $\mathrm{XSD}$ – REAL (KIND=nag_wp)Output
On exit: the robust estimate of the standard deviation, ${\sigma }_{\mathrm{med}}^{\prime }$.
7:     $\mathrm{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}}\le 1$.
${\mathbf{IFAIL}}=-99$
See Section 3.8 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

The computations are believed to be stable.

8  Parallelism and Performance

G07DAF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G07DAF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

Unless otherwise stated in the Users' Note, the routine may be called with the same actual array supplied for parameters X and Y, in which case the sorted data values will overwrite the original contents of X. However this is not standard Fortran, and may not work on all systems.

10  Example

The following program reads in a set of data consisting of eleven observations of a variable $X$. The median, median absolute deviation and a robust estimate of the standard deviation are calculated and printed along with the sorted data in output array Y.

10.1  Program Text

Program Text (g07dafe.f90)

10.2  Program Data

Program Data (g07dafe.d)

10.3  Program Results

Program Results (g07dafe.r)