# NAG FL Interfaceg07daf (robust_​1var_​median)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine g07daf ( n, x, y, xme, xmd, xsd,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x(n) Real (Kind=nag_wp), Intent (Out) :: y(n), xme, xmd, xsd
#include <nag.h>
 void g07daf_ (const Integer *n, const double x[], double y[], double *xme, double *xmd, double *xsd, Integer *ifail)
The routine may be called by the names g07daf or nagf_univar_robust_1var_median.

## 3Description

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=medi{xi},$
and from this the median absolute deviation can be computed,
 $σmed=medi{|xi-θmed|}.$
Finally, a robust estimate of the standard deviation is computed,
 $σmed′=σmed/Φ-1(0.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).
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

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}>1$.
2: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the vector of observations, ${x}_{1},{x}_{2},\dots ,{x}_{n}$.
3: $\mathbf{y}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the observations sorted into ascending order.
4: $\mathbf{xme}$Real (Kind=nag_wp) Output
On exit: the median, ${\theta }_{\mathrm{med}}$.
5: $\mathbf{xmd}$Real (Kind=nag_wp) Output
On exit: the median absolute deviation, ${\sigma }_{\mathrm{med}}$.
6: $\mathbf{xsd}$Real (Kind=nag_wp) Output
On exit: the robust estimate of the standard deviation, ${\sigma }_{\mathrm{med}}^{\prime }$.
7: $\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}}>1$.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
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.

## 7Accuracy

The computations are believed to be stable.

## 8Parallelism 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 arguments 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.

## 10Example

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.1Program Text

Program Text (g07dafe.f90)

### 10.2Program Data

Program Data (g07dafe.d)

### 10.3Program Results

Program Results (g07dafe.r)