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

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_univar_robust_1var_trimmed (g07dd)

## Purpose

nag_univar_robust_1var_trimmed (g07dd) calculates the trimmed and Winsorized means of a sample and estimates of the variances of the two means.

## Syntax

[tmean, wmean, tvar, wvar, k, sx, ifail] = g07dd(x, alpha, 'n', n)
[tmean, wmean, tvar, wvar, k, sx, ifail] = nag_univar_robust_1var_trimmed(x, alpha, 'n', n)

## Description

nag_univar_robust_1var_trimmed (g07dd) calculates the α$\alpha$-trimmed mean and α$\alpha$-Winsorized mean for a given α$\alpha$, as described below.
Let xi${x}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$ represent the n$n$ sample observations sorted into ascending order. Let k = [αn]$k=\left[\alpha n\right]$ where [y]$\left[y\right]$ represents the integer nearest to y$y$; if 2k = n $2k=n$ then k $k$ is reduced by 1$1$.
Then the trimmed mean is defined as:
 n − k xt = 1/(n − 2k) ∑ xi, i = k + 1
$x-t = 1 n-2k ∑ i=k+1 n-k xi ,$
and the Winsorized mean is defined as:
xw = 1/n
 ( n − k ) ∑ xi + kxk + 1 + kxn − k i = k + 1
.
$x-w = 1n ( ∑ i=k+ 1 n-k xi + k ⁢ x k+1 + k ⁢ x n-k ) .$
nag_univar_robust_1var_trimmed (g07dd) then calculates the Winsorized variance about the trimmed and Winsorized means respectively and divides by n$n$ to obtain estimates of the variances of the above two means.
Thus we have;
Estimate of ​ var(xt) = 1/(n2)
 ( n − k ) ∑ (xi − xt)2 + k(xk + 1 − xt)2 + k(xn − k − xt)2 i = k + 1
$Estimate of ​ var( x-t ) = 1n2 ( ∑ i=k+1 n-k ( xi - x-t ) 2 + k ( xk+1 - x-t ) 2 + k ( xn-k - x-t ) 2 )$
and
Estimate of ​ var(xw) = 1/(n2)
 ( n − k ) ∑ (xi − xw)2 + k(xk + 1 − xw)2 + k(xn − k − xw)2 i = k + 1
.
$Estimate of ​ var( x-w ) = 1 n2 ( ∑ i=k+ 1 n-k ( xi - x-w ) 2 + k ( xk+ 1 - x-w ) 2 + k ( xn-k - x-w ) 2 ) .$

## References

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

## Parameters

### Compulsory Input Parameters

1:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n2${\mathbf{n}}\ge 2$.
The sample observations, xi${x}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
2:     alpha – double scalar
α$\alpha$, the proportion of observations to be trimmed at each end of the sorted sample.
Constraint: 0.0alpha < 0.5$0.0\le {\mathbf{alpha}}<0.5$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array x.
n$n$, the number of observations.
Constraint: n2${\mathbf{n}}\ge 2$.

None.

### Output Parameters

1:     tmean – double scalar
The α$\alpha$-trimmed mean, xt${\stackrel{-}{x}}_{t}$.
2:     wmean – double scalar
The α$\alpha$-Winsorized mean, xw${\stackrel{-}{x}}_{w}$.
3:     tvar – double scalar
Contains an estimate of the variance of the trimmed mean.
4:     wvar – double scalar
Contains an estimate of the variance of the Winsorized mean.
5:     k – int64int32nag_int scalar
Contains the number of observations trimmed at each end, k$k$.
6:     sx(n) – double array
Contains the sample observations sorted into ascending order.
7:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, n ≤ 1${\mathbf{n}}\le 1$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, alpha < 0.0${\mathbf{alpha}}<0.0$, or alpha ≥ 0.5${\mathbf{alpha}}\ge 0.5$.

## Accuracy

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

The time taken is proportional to n$n$.

## Example

```function nag_univar_robust_1var_trimmed_example
x = [26;
12;
9;
2;
5;
6;
8;
14;
7;
3;
1;
11;
10;
4;
17;
21];
alpha = 0.15;
[tmean, wmean, tvar, wvar, k, sx, ifail] = nag_univar_robust_1var_trimmed(x, alpha)
```
```

tmean =

8.8333

wmean =

9.1250

tvar =

1.5434

wvar =

1.5381

k =

2

sx =

1
2
3
4
5
6
7
8
9
10
11
12
14
17
21
26

ifail =

0

```
```function g07dd_example
x = [26;
12;
9;
2;
5;
6;
8;
14;
7;
3;
1;
11;
10;
4;
17;
21];
alpha = 0.15;
[tmean, wmean, tvar, wvar, k, sx, ifail] = g07dd(x, alpha)
```
```

tmean =

8.8333

wmean =

9.1250

tvar =

1.5434

wvar =

1.5381

k =

2

sx =

1
2
3
4
5
6
7
8
9
10
11
12
14
17
21
26

ifail =

0

```