NAG Library Routine Document

g07ddf  (robust_1var_trimmed)

 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

Fortran Interface
Subroutine g07ddf ( n, x, alpha, tmean, wmean, tvar, wvar, k, sx, ifail)
Integer, Intent (In):: n
Integer, Intent (Inout):: ifail
Integer, Intent (Out):: k
Real (Kind=nag_wp), Intent (In):: x(n), alpha
Real (Kind=nag_wp), Intent (Out):: tmean, wmean, tvar, wvar, sx(n)
C Header Interface
#include nagmk26.h
void  g07ddf_ ( const Integer *n, const double x[], const double *alpha, double *tmean, double *wmean, double *tvar, double *wvar, Integer *k, double sx[], Integer *ifail)

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
Arguments

1:     n – IntegerInput
On entry: n, the number of observations.
Constraint: n2.
2:     xn – 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:     sxn – 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 argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

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

8
Parallelism and Performance

g07ddf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9
Further Comments

The time taken is proportional to n.

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

10.1
Program Text

Program Text (g07ddfe.f90)

10.2
Program Data

Program Data (g07ddfe.d)

10.3
Program Results

Program Results (g07ddfe.r)

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