hide long namesshow long names
hide short namesshow short names
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)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


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.


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


The data consists of a sample of size n, denoted by x1,x2,,xn, drawn from a random variable X.
nag_univar_robust_1var_median (g07da) first computes the median,
and from this the median absolute deviation can be computed,
Finally, a robust estimate of the standard deviation is computed,
where Φ-10.75 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).


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


Compulsory Input Parameters

1:     xn – double array
The vector of observations, x1,x2,,xn.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the array x.
n, the number of observations.
Constraint: n>1.

Output Parameters

1:     yn – double array
The observations sorted into ascending order.
2:     xme – double scalar
The median, θmed.
3:     xmd – double scalar
The median absolute deviation, σmed.
4:     xsd – double scalar
The robust estimate of the standard deviation, σmed.
5:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
On entry,n1.
An unexpected error has been triggered by this routine. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
Dynamic memory allocation failed.


The computations are believed to be stable.

Further Comments



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 ');

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

fprintf('Sorted Data\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