nag_robust_trimmed_1var (g07ddc) (PDF version)
g07 Chapter Contents
g07 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_robust_trimmed_1var (g07ddc)

## 1  Purpose

nag_robust_trimmed_1var (g07ddc) calculates the trimmed and Winsorized means of a sample and estimates of the variances of the two means.

## 2  Specification

 #include #include
 void nag_robust_trimmed_1var (Integer n, const double x[], double alpha, double *tmean, double *wmean, double *tvar, double *wvar, Integer *k, double sx[], NagError *fail)

## 3  Description

nag_robust_trimmed_1var (g07ddc) calculates the $\alpha$-trimmed mean and $\alpha$-Winsorized mean for a given $\alpha$, as described below.
Let ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, represent the $n$ sample observations sorted into ascending order. Let $k=\left[\alpha n\right]$ where $\left[y\right]$ represents the integer nearest to $y$; if $2k=n$ then $k$ is reduced by 1.
Then the trimmed mean is defined as:
 $x-t = 1 n-2k ∑ i=k+1 n-k xi ,$
and the Winsorized mean is defined as:
 $x-w = 1n ∑ i=k+1 n-k xi + kx k+1 + kx n-k .$
nag_robust_trimmed_1var (g07ddc) then calculates the Winsorized variance about the trimmed and Winsorized means respectively and divides by $n$ to obtain estimates of the variances of the above two means.
Thus we have
 $Estimate of ​ var x - t = 1 n 2 ∑ i = k + 1 n-k x i - x - t 2 + k x k+1 - x - t 2 + k x n-k - x - t 2$
and
 $Estimate of ​ var x - w = 1 n 2 ∑ i = k + 1 n-k x i - x - w 2 + k x k+1 - x - w 2 + k x n-k - x - w 2 .$
Hampel F R, Ronchetti E M, Rousseeuw P J and Stahel W A (1986) Robust Statistics. The Approach Based on Influence Functions Wiley
Huber P J (1981) Robust Statistics Wiley

## 5  Arguments

1:     nIntegerInput
On entry: the number of observations, $n$.
Constraint: ${\mathbf{n}}\ge 2$.
2:     x[n]const doubleInput
On entry: the sample observations, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3:     alphadoubleInput
On entry: the proportion of observations to be trimmed at each end of the sorted sample, $\alpha$.
Constraint: $0.0\le {\mathbf{alpha}}<0.5$.
4:     tmeandouble *Output
On exit: the $\alpha$-trimmed mean, ${\stackrel{-}{x}}_{t}$.
5:     wmeandouble *Output
On exit: the $\alpha$-Winsorized mean, ${\stackrel{-}{x}}_{w}$.
6:     tvardouble *Output
On exit: contains an estimate of the variance of the trimmed mean.
7:     wvardouble *Output
On exit: contains an estimate of the variance of the Winsorized mean.
8:     kInteger *Output
On exit: contains the number of observations trimmed at each end, $k$.
9:     sx[n]doubleOutput
On exit: contains the sample observations sorted into ascending order.
10:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_INT_ARG_LT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 2$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_REAL_ARG_GE
On entry, alpha must not be greater than or equal to 0.5: ${\mathbf{alpha}}=⟨\mathit{\text{value}}⟩$.
NE_REAL_ARG_LT
On entry, alpha must not be less than 0.0: ${\mathbf{alpha}}=⟨\mathit{\text{value}}⟩$.

## 7  Accuracy

The results should be accurate to within a small multiple of machine precision.

Not applicable.

## 9  Further Comments

The time taken by nag_robust_trimmed_1var (g07ddc) is proportional to $n$.

## 10  Example

The following program finds the $\alpha$-trimmed mean and $\alpha$-Winsorized mean for a sample of 16 observations where $\alpha =0.15$. The estimates of the variances of the above two means are also calculated.

### 10.1  Program Text

Program Text (g07ddce.c)

### 10.2  Program Data

Program Data (g07ddce.d)

### 10.3  Program Results

Program Results (g07ddce.r)

nag_robust_trimmed_1var (g07ddc) (PDF version)
g07 Chapter Contents
g07 Chapter Introduction
NAG Library Manual