# NAG FL Interfaceg01atf (summary_​onevar)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g01atf 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

Fortran Interface
 Subroutine g01atf ( nb, x, iwt, wt, pn, xsd, xmin, xmax,
 Integer, Intent (In) :: nb, iwt Integer, Intent (Inout) :: pn, ifail Real (Kind=nag_wp), Intent (In) :: x(nb), wt(*) Real (Kind=nag_wp), Intent (Inout) :: rcomm(*) Real (Kind=nag_wp), Intent (Out) :: xmean, xsd, xskew, xkurt, xmin, xmax
#include <nag.h>
 void g01atf_ (const Integer *nb, const double x[], const Integer *iwt, const double wt[], Integer *pn, double *xmean, double *xsd, double *xskew, double *xkurt, double *xmin, double *xmax, double rcomm[], Integer *ifail)
The routine may be called by the names g01atf or nagf_stat_summary_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\}$, g01atf 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 g01atf called multiple times.

## 4References

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 g01atf.
Constraint: ${\mathbf{nb}}\ge 0$.
2: $\mathbf{x}\left({\mathbf{nb}}\right)$Real (Kind=nag_wp) array 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{iwt}$Integer Input
On entry: indicates whether user-supplied weights are provided:
${\mathbf{iwt}}=1$
User-supplied weights are given in the array wt.
${\mathbf{iwt}}=0$
${w}_{i}=1$, for all $i$, so no user-supplied weights are given and wt is not referenced.
Constraint: ${\mathbf{iwt}}=0$ or $1$.
4: $\mathbf{wt}\left(*\right)$Real (Kind=nag_wp) array Input
Note: the dimension of the array wt must be at least ${\mathbf{nb}}$ if ${\mathbf{iwt}}=1$.
On entry: if ${\mathbf{iwt}}=1$, 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$.
Constraint: if ${\mathbf{iwt}}=1$, ${\mathbf{wt}}\left(\mathit{i}\right)\ge 0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nb}}$.
5: $\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 g01atf, 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 g01atf.
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$.
Constraint: ${\mathbf{pn}}\ge 0$.
6: $\mathbf{xmean}$Real (Kind=nag_wp) Output
On exit: $\overline{x}$, the mean of the first $k+b$ observations.
7: $\mathbf{xsd}$Real (Kind=nag_wp) Output
On exit: ${s}_{2}$, the standard deviation of the first $k+b$ observations.
8: $\mathbf{xskew}$Real (Kind=nag_wp) Output
On exit: ${s}_{3}$, the coefficient of skewness for the first $k+b$ observations.
9: $\mathbf{xkurt}$Real (Kind=nag_wp) Output
On exit: ${s}_{4}$, the coefficient of kurtosis for the first $k+b$ observations.
10: $\mathbf{xmin}$Real (Kind=nag_wp) Output
On exit: the smallest value in the first $k+b$ observations.
11: $\mathbf{xmax}$Real (Kind=nag_wp) Output
On exit: the largest value in the first $k+b$ observations.
12: $\mathbf{rcomm}\left(*\right)$Real (Kind=nag_wp) array Communication Array
Note: the dimension of the array rcomm must be at least $20$.
On entry: communication array, used to store information between calls to g01atf. If ${\mathbf{pn}}=0$, rcomm need not be initialized, otherwise it must be unchanged since the last call to this routine.
On exit: the updated communication array. The first five elements of rcomm hold information that may be of interest with
 $rcomm(1) = ∑ i=1 k+b wi rcomm(2) = (∑ i=1 k+b wi) 2 - ∑ i=1 k+b wi2 rcomm(3) = ∑ i=1 k+b wi (xi-x¯) 2 rcomm(4) = ∑ i=1 k+b wi (xi-x¯) 3 rcomm(5) = ∑ i=1 k+b wi (xi-x¯) 4$
the remaining elements of rcomm are used for workspace and so are undefined.
13: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=11$
On entry, ${\mathbf{nb}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nb}}\ge 0$.
${\mathbf{ifail}}=31$
On entry, ${\mathbf{iwt}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{iwt}}=0$ or $1$.
${\mathbf{ifail}}=41$
On entry, ${\mathbf{wt}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{iwt}}=1$ then ${\mathbf{wt}}\left(\mathit{i}\right)\ge 0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nb}}$.
${\mathbf{ifail}}=51$
On entry, ${\mathbf{pn}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pn}}\ge 0$.
${\mathbf{ifail}}=52$
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.
${\mathbf{ifail}}=53$
On entry, the number of valid observations is zero.
${\mathbf{ifail}}=71$
On exit we were unable to calculate xskew or xkurt. A value of $0$ has been returned.
${\mathbf{ifail}}=72$
On exit we were unable to calculate xsd, xskew or xkurt. A value of $0$ has been returned.
${\mathbf{ifail}}=121$
rcomm has been corrupted between calls.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g01atf 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.

Both g01atf and g01auf 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 (g01atfe.f90)

### 10.2Program Data

Program Data (g01atfe.d)

### 10.3Program Results

Program Results (g01atfe.r)