G07DDF (PDF version)
G07 Chapter Contents
G07 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G07DDF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

G07DDF calculates the trimmed and Winsorized means of a sample and estimates of the variances of the two means.

2  Specification

SUBROUTINE G07DDF ( N, X, ALPHA, TMEAN, WMEAN, TVAR, WVAR, K, SX, IFAIL)
INTEGER  N, K, IFAIL
REAL (KIND=nag_wp)  X(N), ALPHA, TMEAN, WMEAN, TVAR, WVAR, SX(N)

3  Description

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

4  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

5  Parameters

1:     N – INTEGERInput
On entry: n, the number of observations.
Constraint: N2.
2:     X(N) – REAL (KIND=nag_wp) arrayInput
On entry: the sample observations, xi, for i=1,2,,n.
3:     ALPHA – REAL (KIND=nag_wp)Input
On entry: α, the proportion of observations to be trimmed at each end of the sorted sample.
Constraint: 0.0ALPHA<0.5.
4:     TMEAN – REAL (KIND=nag_wp)Output
On exit: the α-trimmed mean, x-t.
5:     WMEAN – REAL (KIND=nag_wp)Output
On exit: the α-Winsorized mean, x-w.
6:     TVAR – REAL (KIND=nag_wp)Output
On exit: contains an estimate of the variance of the trimmed mean.
7:     WVAR – REAL (KIND=nag_wp)Output
On exit: contains an estimate of the variance of the Winsorized mean.
8:     K – INTEGEROutput
On exit: contains the number of observations trimmed at each end, k.
9:     SX(N) – REAL (KIND=nag_wp) arrayOutput
On exit: contains the sample observations sorted into ascending order.
10:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,N1.
IFAIL=2
On entry,ALPHA<0.0,
orALPHA0.5.

7  Accuracy

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

8  Further Comments

The time taken is proportional to n.

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

9.1  Program Text

Program Text (g07ddfe.f90)

9.2  Program Data

Program Data (g07ddfe.d)

9.3  Program Results

Program Results (g07ddfe.r)


G07DDF (PDF version)
G07 Chapter Contents
G07 Chapter Introduction
NAG Library Manual

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