nag_summary_stats_onevar (g01atc) (PDF version)
g01 Chapter Contents
g01 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_summary_stats_onevar (g01atc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_summary_stats_onevar (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.

2  Specification

#include <nag.h>
#include <nagg01.h>
void  nag_summary_stats_onevar (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)

3  Description

Given a sample of n observations, denoted by x = xi : i=1,2,,n  and a set of non-negative weights, w = wi : i=1,2,,n , nag_summary_stats_onevar (g01atc) calculates a number of quantities:
(a) Mean
x- = i=1 n wi xi W ,   where   W = i=1 n wi .
(b) Standard deviation
s2 = i=1 n wi xi - x- 2 d ,   where   d = W - i=1 n wi2 W .
(c) Coefficient of skewness
s3 = i=1 n wi xi - x- 3 d s23 .
(d) Coefficient of kurtosis
s4 = i=1 n wi xi - x- 4 d s24 -3 .
(e) Maximum and minimum elements, with wi0.
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 nag_summary_stats_onevar (g01atc) called multiple times.

4  References

West D H D (1979) Updating mean and variance estimates: An improved method Comm. ACM 22 532–555

5  Arguments

1:     nbIntegerInput
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 nag_summary_stats_onevar (g01atc).
Constraint: nb0.
2:     x[nb]const doubleInput
On entry: the current block of observations, corresponding to xi, for i=k+1,,k+b, where k is the number of observations processed so far and b is the size of the current block of data.
3:     wt[nb]const doubleInput
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 wi, for i=k+1,,k+b.
If wt is NULL, wi=1 for all i.
Constraint: wt[i-1]0, for i=1,2,,nb.
4:     pnInteger *Input/Output
On entry: the number of valid observations processed so far, that is the number of observations with wi>0, for i=1,2,,k. On the first call to nag_summary_stats_onevar (g01atc), or when starting to summarise a new dataset, pn must be set to 0.
If pn0, it must be the same value as returned by the last call to nag_summary_stats_onevar (g01atc).
On exit: the updated number of valid observations processed, that is the number of observations with wi>0, for i=1,2,,k+b.
Constraints:
  • pn0;
  • if rcomm is NULL, pn=0.
5:     xmeandouble *Output
On exit: x-, the mean of the first k+b observations.
6:     xsddouble *Output
On exit: s2, the standard deviation of the first k+b observations.
7:     xskewdouble *Output
On exit: s3, the coefficient of skewness for the first k+b observations.
8:     xkurtdouble *Output
On exit: s4, the coefficient of kurtosis for the first k+b observations.
9:     xmindouble *Output
On exit: the smallest value in the first k+b observations.
10:   xmaxdouble *Output
On exit: the largest value in the first k+b observations.
11:   rcomm[20]doubleCommunication Array
On entry: communication array, used to store information between calls to nag_summary_stats_onevar (g01atc). If 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[0] = i=1 k+b wi rcomm[1] = i=1 k+b wi 2 - i=1 k+b wi2 rcomm[2] = i=1 k+b wi xi - x- 2 rcomm[3] = i=1 k+b wi xi - x- 3 rcomm[4] = i=1 k+b wi xi - x- 4
the remaining elements of rcomm are used for workspace and so are undefined.
12:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_BAD_PARAM
On entry, argument 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, nb=value.
Constraint: nb0.
On entry, pn=value.
Constraint: if rcommisNULL then pn=0.
On entry, pn=value.
Constraint: pn0.
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_NEG_WEIGHT
On entry, wt[value]=value.
Constraint: if wtis notNULL then wt[i-1]0, for i=1,2,,nb.
NE_PREV_CALL
On entry, pn=value.
On exit from previous call, pn=value.
Constraint: if 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.

7  Accuracy

Not applicable.

8  Parallelism and Performance

nag_summary_stats_onevar (g01atc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the Users' Note for your implementation for any additional implementation-specific information.

9  Further Comments

Both nag_summary_stats_onevar (g01atc) and nag_summary_stats_onevar_combine (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.

10  Example

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

Program Text (g01atce.c)

10.2  Program Data

Program Data (g01atce.d)

10.3  Program Results

Program Results (g01atce.r)


nag_summary_stats_onevar (g01atc) (PDF version)
g01 Chapter Contents
g01 Chapter Introduction
NAG Library Manual

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