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

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_univar_robust_1var_median (g07da)

## Purpose

nag_univar_robust_1var_median (g07da) finds the median, median absolute deviation, and a robust estimate of the standard deviation for a set of ungrouped data.

## Syntax

[y, xme, xmd, xsd, ifail] = g07da(x, 'n', n)
[y, xme, xmd, xsd, ifail] = nag_univar_robust_1var_median(x, 'n', n)

## 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$.
nag_univar_robust_1var_median (g07da) 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$.
nag_univar_robust_1var_median (g07da) is based upon function LTMDDV within the ROBETH library, see Marazzi (1987).

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
The vector of observations, ${x}_{1},{x}_{2},\dots ,{x}_{n}$.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the array x.
$n$, the number of observations.
Constraint: ${\mathbf{n}}>1$.

### Output Parameters

1:     $\mathrm{y}\left({\mathbf{n}}\right)$ – double array
The observations sorted into ascending order.
2:     $\mathrm{xme}$ – double scalar
The median, ${\theta }_{\mathrm{med}}$.
3:     $\mathrm{xmd}$ – double scalar
The median absolute deviation, ${\sigma }_{\mathrm{med}}$.
4:     $\mathrm{xsd}$ – double scalar
The robust estimate of the standard deviation, ${\sigma }_{\mathrm{med}}^{\prime }$.
5:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}\le 1$.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The computations are believed to be stable.

None.

## 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.
```function g07da_example

fprintf('g07da example results\n\n');

x = [13;  11;  16;  5;  3;  18;  9;  8;  6;  27;  7];
fprintf('Original Data\n ');
fprintf('%7.3f',x)
fprintf('\n\n');

% Sort Data abd compute estimates
[y, xme, xmd, xsd, ifail] = g07da(x);

fprintf('Sorted Data\n ');
fprintf('%7.3f',y)
fprintf('\n\n');
fprintf('Median                             = %6.3f\n', xme);
fprintf('Median absolute deviation          = %6.3f\n', xmd);
fprintf('Robust estimate standard deviation = %6.3f\n', xsd);

```
```g07da example results

Original Data
13.000 11.000 16.000  5.000  3.000 18.000  9.000  8.000  6.000 27.000  7.000

Sorted Data
3.000  5.000  6.000  7.000  8.000  9.000 11.000 13.000 16.000 18.000 27.000

Median                             =  9.000
Median absolute deviation          =  4.000
Robust estimate standard deviation =  5.930
```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015