# NAG CL Interfaceg01atc (summary_​onevar)

Settings help

CL Name Style:

## 1Purpose

g01atc calculates the mean, standard deviation, coefficients of skewness and kurtosis, and the maximum and minimum values for a set of (optionally weighted) data. The input data can be split into arbitrary sized blocks, allowing large datasets to be summarised.

## 2Specification

 #include
 void g01atc (Integer nb, const double x[], const double wt[], Integer *pn, double *xmean, double *xsd, double *xskew, double *xkurt, double *xmin, double *xmax, double rcomm[], NagError *fail)
The function may be called by the names: g01atc, nag_stat_summary_onevar or nag_summary_stats_onevar.

## 3Description

Given a sample of $n$ observations, denoted by $x=\left\{{x}_{i}:i=1,2,\dots ,n\right\}$ and a set of non-negative weights, $w=\left\{{w}_{i}:i=1,2,\dots ,n\right\}$, g01atc calculates a number of quantities:
1. (a)Mean
 $x¯ = ∑ i=1 n wi xi W , where W = ∑ i=1 n wi .$
2. (b)Standard deviation
 $s2 = ∑ i=1 n wi (xi-x¯) 2 d , where d = W - ∑ i=1 n wi2 W .$
3. (c)Coefficient of skewness
 $s3 = ∑ i=1 n wi (xi-x¯) 3 d ⁢ s23 .$
4. (d)Coefficient of kurtosis
 $s4 = ∑ i=1 n wi (xi-x¯) 4 d ⁢ s24 -3 .$
5. (e)Maximum and minimum elements, with ${w}_{i}\ne 0$.
These quantities are calculated using the one pass algorithm of West (1979).
For large datasets, or where all the data is not available at the same time, $x$ and $w$ can be split into arbitrary sized blocks and g01atc called multiple times.
West D H D (1979) Updating mean and variance estimates: An improved method Comm. ACM 22 532–555

## 5Arguments

1: $\mathbf{nb}$Integer Input
On entry: $b$, the number of observations in the current block of data. The size of the block of data supplied in x and wt can vary;, therefore, nb can change between calls to g01atc.
Constraint: ${\mathbf{nb}}\ge 0$.
2: $\mathbf{x}\left[{\mathbf{nb}}\right]$const double Input
On entry: the current block of observations, corresponding to ${x}_{\mathit{i}}$, for $\mathit{i}=k+1,\dots ,k+b$, where $k$ is the number of observations processed so far and $b$ is the size of the current block of data.
3: $\mathbf{wt}\left[\mathit{dim}\right]$const double Input
Note: the dimension, dim, of the array wt must be at least
• ${\mathbf{nb}}$, when ${\mathbf{wt}}\phantom{\rule{0.25em}{0ex}}\text{is not}\phantom{\rule{0.25em}{0ex}}\mathbf{NULL}$.
On entry: if wt is not NULL, wt must contain the user-supplied weights corresponding to the block of data supplied in x, that is ${w}_{\mathit{i}}$, for $\mathit{i}=k+1,\dots ,k+b$.
If wt is NULL, ${w}_{i}=1$ for all $i$.
Constraint: ${\mathbf{wt}}\left[\mathit{i}-1\right]\ge 0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nb}}$.
4: $\mathbf{pn}$Integer * Input/Output
On entry: the number of valid observations processed so far, that is the number of observations with ${w}_{i}>0$, for $\mathit{i}=1,2,\dots ,k$. On the first call to g01atc, or when starting to summarise a new dataset, pn must be set to $0$.
If ${\mathbf{pn}}\ne 0$, it must be the same value as returned by the last call to g01atc.
On exit: the updated number of valid observations processed, that is the number of observations with ${w}_{i}>0$, for $\mathit{i}=1,2,\dots ,k+b$.
Constraints:
• ${\mathbf{pn}}\ge 0$;
• if rcomm is NULL, ${\mathbf{pn}}=0$.
5: $\mathbf{xmean}$double * Output
On exit: $\overline{x}$, the mean of the first $k+b$ observations.
6: $\mathbf{xsd}$double * Output
On exit: ${s}_{2}$, the standard deviation of the first $k+b$ observations.
7: $\mathbf{xskew}$double * Output
On exit: ${s}_{3}$, the coefficient of skewness for the first $k+b$ observations.
8: $\mathbf{xkurt}$double * Output
On exit: ${s}_{4}$, the coefficient of kurtosis for the first $k+b$ observations.
9: $\mathbf{xmin}$double * Output
On exit: the smallest value in the first $k+b$ observations.
10: $\mathbf{xmax}$double * Output
On exit: the largest value in the first $k+b$ observations.
11: $\mathbf{rcomm}\left[\mathit{dim}\right]$double Communication Array
Note: the dimension, dim, of the array rcomm must be at least
• $20$, when ${\mathbf{rcomm}}\phantom{\rule{0.25em}{0ex}}\text{is not}\phantom{\rule{0.25em}{0ex}}\mathbf{NULL}$.
On entry: communication array, used to store information between calls to g01atc. If ${\mathbf{pn}}=0$, rcomm need not be initialized, otherwise it must be unchanged since the last call to this function.
If rcomm is NULL, rcomm is not referenced and all the data must be supplied in one go.
On exit: the updated communication array. The first five elements of rcomm hold information that may be of interest with
 $rcomm = ∑ i=1 k+b wi rcomm = (∑ i=1 k+b wi) 2 - ∑ i=1 k+b wi2 rcomm = ∑ i=1 k+b wi (xi-x¯) 2 rcomm = ∑ i=1 k+b wi (xi-x¯) 3 rcomm = ∑ i=1 k+b wi (xi-x¯) 4$
the remaining elements of rcomm are used for workspace and so are undefined.
12: $\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_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_CASES_ONE
On exit we were unable to calculate xsd, xskew or xkurt. A value of $0$ has been returned.
NE_CASES_ZERO
On entry, the number of valid observations is zero.
NE_ILLEGAL_COMM
rcomm has been corrupted between calls.
NE_INT
On entry, ${\mathbf{nb}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nb}}\ge 0$.
On entry, ${\mathbf{pn}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{rcomm}}\phantom{\rule{0.25em}{0ex}}\text{is}\phantom{\rule{0.25em}{0ex}}\mathbf{NULL}$ then ${\mathbf{pn}}=0$.
On entry, ${\mathbf{pn}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pn}}\ge 0$.
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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NEG_WEIGHT
On entry, ${\mathbf{wt}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{wt}}\phantom{\rule{0.25em}{0ex}}\text{is not}\phantom{\rule{0.25em}{0ex}}\mathbf{NULL}$ then ${\mathbf{wt}}\left[\mathit{i}-1\right]\ge 0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nb}}$.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_PREV_CALL
On entry, ${\mathbf{pn}}=⟨\mathit{\text{value}}⟩$.
On exit from previous call, ${\mathbf{pn}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{pn}}>0$, pn must be unchanged since previous call.
NE_ZERO_VARIANCE
On exit we were unable to calculate xskew or xkurt. A value of $0$ has been returned.

Not applicable.

## 8Parallelism and Performance

g01atc 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

Both g01atc and g01auc consolidate results from multiple summaries. Whereas the former can only be used to combine summaries calculated sequentially, the latter combines summaries calculated in an arbitrary order allowing, for example, summaries calculated on different processing units to be combined.

## 10Example

This example summarises some simulated data. The data is supplied in three blocks, the first consisting of $21$ observations, the second $51$ observations and the last $28$ observations.

### 10.1Program Text

Program Text (g01atce.c)

### 10.2Program Data

Program Data (g01atce.d)

### 10.3Program Results

Program Results (g01atce.r)