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_trimmed (g07dd)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

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 α-trimmed mean and α-Winsorized mean for a given α, as described below.
Let xi, for i=1,2,,n represent the n sample observations sorted into ascending order. Let k=αn where y 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 + 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 to obtain estimates of the variances of the above two means.
Thus we have;
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 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:     xn – double array
The sample observations, xi, for i=1,2,,n.
2:     alpha – double scalar
α, the proportion of observations to be trimmed at each end of the sorted sample.
Constraint: 0.0alpha<0.5.

Optional Input Parameters

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

Output Parameters

1:     tmean – double scalar
The α-trimmed mean, x-t.
2:     wmean – double scalar
The α-Winsorized mean, 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.
6:     sxn – double array
Contains the sample observations sorted into ascending order.
7:     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:
   ifail=1
On entry,n1.
   ifail=2
On entry,alpha<0.0,
oralpha0.5.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

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

Further Comments

The time taken is proportional to n.

Example

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


fprintf('g07dd example results\n\n');

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

% Calculate proportion of data cut
propn = 100*(1-2*double(k)/numel(x));

fprintf('Statistics from middle %6.2f%% of data\n\n',propn);
fprintf('               Trimmed-mean = %11.4f\n', tmean);
fprintf('   Variance of Trimmed-mean = %11.4f\n\n', tvar);
fprintf('            Winsorized-mean = %11.4f\n', wmean);
fprintf('Variance of Winsorized-mean = %11.4f\n', wvar);


g07dd example results

Statistics from middle  75.00% of data

               Trimmed-mean =      8.8333
   Variance of Trimmed-mean =      1.5434

            Winsorized-mean =      9.1250
Variance of Winsorized-mean =      1.5381

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