# NAG C Library Function Document

## 1Purpose

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

## 2Specification

 #include #include
 void nag_median_1var (Integer n, const double x[], double y[], double *xme, double *xmd, double *xsd, NagError *fail)

## 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$. 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 ${\Phi }^{-1}\left(0.75\right)$ 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).

## 4References

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

## 5Arguments

1:    $\mathbf{n}$IntegerInput
On entry: the number of observations, $n$.
Constraint: ${\mathbf{n}}>1$.
2:    $\mathbf{x}\left[{\mathbf{n}}\right]$const doubleInput
On entry: the vector of observations, ${x}_{1},{x}_{2},\dots ,{x}_{n}$.
3:    $\mathbf{y}\left[{\mathbf{n}}\right]$doubleOutput
On exit: the observations sorted into ascending order.
4:    $\mathbf{xme}$double *Output
On exit: the median, ${\theta }_{\mathrm{med}}$.
5:    $\mathbf{xmd}$double *Output
On exit: the median absolute deviation, ${\sigma }_{\mathrm{med}}$.
6:    $\mathbf{xsd}$double *Output
On exit: the robust estimate of the standard deviation, ${\sigma }_{\mathrm{med}}^{\prime }$.
7:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_INT_ARG_GT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\le 〈\mathit{\text{value}}〉$.
NE_INT_ARG_LE
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}>1$.

## 7Accuracy

The computations are believed to be stable.

## 8Parallelism and Performance

nag_median_1var (g07dac) is not threaded in any implementation.

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.

## 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 (g07dace.c)

### 10.2Program Data

Program Data (g07dace.d)

### 10.3Program Results

Program Results (g07dace.r)