nag_summary_stats_1var (g01aac) (PDF version)
g01 Chapter Contents
g01 Chapter Introduction
NAG C Library Manual

NAG Library Function Document

nag_summary_stats_1var (g01aac)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_summary_stats_1var (g01aac) calculates the mean, standard deviation, coefficients of skewness and kurtosis, and the maximum and minimum values for a set of ungrouped data. Weighting may be used.

2  Specification

#include <nag.h>
#include <nagg01.h>
void  nag_summary_stats_1var (Integer n, const double x[], const double wt[], Integer *nvalid, double *xmean, double *xsd, double *xskew, double *xkurt, double *xmin, double *xmax, double *wsum, NagError *fail)

3  Description

The data consist of a single sample of n observations, denoted by xi, with corresponding weights, wi, for i=1,2,,n.
If no specific weighting is required, then each wi is set to 1.
The quantities computed are:
(a) The sum of the weights
W=i=1nwi.
(b) Mean
x-=i= 1nwixiW.
(c) Standard deviation
s2=i=1nwi xi-x- 2d,   where  d=W-i=1nwi2W.
(d) Coefficient of skewness
s3=i= 1nwi xi-x- 3 d×s23 .
(e) Coefficient of kurtosis
s4=i=1nwi xi-x- 4 d×s24 -3.
(f) Maximum and minimum elements of the sample.
(g) The number of observations for which wi>0, i.e., the number of valid observations. Suppose m observations are valid, then the quantities in (c), (d) and (e) will be computed if m2, and will be based on m-1 degrees of freedom. The other quantities are evaluated provided m1.

4  References

None.

5  Arguments

1:     nIntegerInput
On entry: n, the number of observations.
Constraint: n1.
2:     x[n]const doubleInput
On entry: the sample observations, xi, for i=1,2,,n.
3:     wt[n]const doubleInput
On entry: if weights are being supplied then the elements of wt must contain the weights associated with the observations, wi, for i=1,2,,n.
If weights are not supplied then wt must be set to the null pointer, i.e., (double *)0.
4:     nvalidInteger *Output
On exit: is used to indicate the number of valid observations, m; see Section 3 (g).
5:     xmeandouble *Output
On exit: the mean, x-.
6:     xsddouble *Output
On exit: the standard deviation, s2.
7:     xskewdouble *Output
On exit: the coefficient of skewness, s3.
8:     xkurtdouble *Output
On exit: the coefficient of kurtosis, s4.
9:     xmindouble *Output
On exit: the smallest value in the sample.
10:   xmaxdouble *Output
On exit: the largest value in the sample.
11:   wsumdouble *Output
On exit: the sum of the weights in the array wt, that is i=1nwi. This will be n if weighted estimates are not used.
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
The number of valid cases is one. The standard deviation and coefficients of skewness and of kurtosis cannot be calculated.
NE_CASES_ZERO
The number of valid cases is zero.
NE_INT_ARG_LE
On entry, n=value.
Constraint: n1.
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_LT
On entry, wt[value] = value.
Constraint: wt[value] 0.0 .

7  Accuracy

The method used is believed to be stable.

8  Further Comments

The time taken by nag_summary_stats_1var (g01aac) is approximately proportional to n.

9  Example

This example summarises a number of datasets. For each dataset the observations and, optionally, weights are read and printed. nag_summary_stats_1var (g01aac) is then called and the calculated quantities are printed.

9.1  Program Text

Program Text (g01aace.c)

9.2  Program Data

Program Data (g01aace.d)

9.3  Program Results

Program Results (g01aace.r)


nag_summary_stats_1var (g01aac) (PDF version)
g01 Chapter Contents
g01 Chapter Introduction
NAG C Library Manual

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