nag_median_1var (g07dac) (PDF version)
g07 Chapter Contents
g07 Chapter Introduction
NAG C Library Manual

NAG Library Function Document

nag_median_1var (g07dac)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

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

2  Specification

#include <nag.h>
#include <nagg07.h>
void  nag_median_1var (Integer n, const double x[], double y[], double *xme, double *xmd, double *xsd, NagError *fail)

3  Description

The data consists of a sample of size n , denoted by x 1 , x 2 , , x n , drawn from a random variable X . nag_median_1var (g07dac) first computes the median
θ med = med i x i
and from this the median absolute deviation can be computed,
σ med = med i x i - θ med .
Finally, a robust estimate of the standard deviation is computed,
σ med = σ med / Φ -1 0.75
where Φ -1 0.75  is the value of the inverse standard Normal function at the point 0.75. nag_median_1var (g07dac) is based upon the algorithm used in the function LTMDDV in the ROBETH library, see Marazzi (1987).

4  References

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

5  Arguments

1:     nIntegerInput
On entry: the number of observations, n .
Constraint: n>1 .
2:     x[n]const doubleInput
On entry: the vector of observations, x 1 , x 2 , , x n .
3:     y[n]doubleOutput
On exit: the observations sorted into ascending order.
4:     xmedouble *Output
On exit: the median, θ med .
5:     xmddouble *Output
On exit: the median absolute deviation, σ med .
6:     xsddouble *Output
On exit: the robust estimate of the standard deviation, σ med .
7:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_INT_ARG_GT
On entry, n=value.
Constraint: nvalue.
NE_INT_ARG_LE
On entry, n=value.
Constraint: n>1.

7  Accuracy

The computations are believed to be stable.

8  Further Comments

nag_median_1var (g07dac) 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.

9  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.

9.1  Program Text

Program Text (g07dace.c)

9.2  Program Data

Program Data (g07dace.d)

9.3  Program Results

Program Results (g07dace.r)


nag_median_1var (g07dac) (PDF version)
g07 Chapter Contents
g07 Chapter Introduction
NAG C Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012