# NAG CL Interfaceg07ddc (robust_​1var_​trimmed)

## 1Purpose

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

## 2Specification

 #include
 void g07ddc (Integer n, const double x[], double alpha, double *tmean, double *wmean, double *tvar, double *wvar, Integer *k, double sx[], NagError *fail)
The function may be called by the names: g07ddc, nag_univar_robust_1var_trimmed or nag_robust_trimmed_1var.

## 3Description

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

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: the number of observations, $n$.
Constraint: ${\mathbf{n}}\ge 2$.
2: $\mathbf{x}\left[{\mathbf{n}}\right]$const double Input
On entry: the sample observations, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3: $\mathbf{alpha}$double Input
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: $\mathbf{tmean}$double * Output
On exit: the $\alpha$-trimmed mean, ${\overline{x}}_{t}$.
5: $\mathbf{wmean}$double * Output
On exit: the $\alpha$-Winsorized mean, ${\overline{x}}_{w}$.
6: $\mathbf{tvar}$double * Output
On exit: contains an estimate of the variance of the trimmed mean.
7: $\mathbf{wvar}$double * Output
On exit: contains an estimate of the variance of the Winsorized mean.
8: $\mathbf{k}$Integer * Output
On exit: contains the number of observations trimmed at each end, $k$.
9: $\mathbf{sx}\left[{\mathbf{n}}\right]$double Output
On exit: contains the sample observations sorted into ascending order.
10: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error 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}}〉$.

## 7Accuracy

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

## 8Parallelism and Performance

g07ddc is not threaded in any implementation.

The time taken by g07ddc is proportional to $n$.

## 10Example

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.1Program Text

Program Text (g07ddce.c)

### 10.2Program Data

Program Data (g07ddce.d)

### 10.3Program Results

Program Results (g07ddce.r)