g01 Chapter Contents
g01 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_summary_stats_1var (g01aac)

## 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 #include
 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 ${x}_{i}$, with corresponding weights, ${w}_{i}$, for $\mathit{i}=1,2,\dots ,n$.
If no specific weighting is required, then each ${w}_{i}$ 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 ${w}_{i}>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 $m\ge 2$, and will be based on $m-1$ degrees of freedom. The other quantities are evaluated provided $m\ge 1$.
None.

## 5  Arguments

1:    $\mathbf{n}$IntegerInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}\ge 1$.
2:    $\mathbf{x}\left[{\mathbf{n}}\right]$const doubleInput
On entry: the sample observations, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3:    $\mathbf{wt}\left[{\mathbf{n}}\right]$const doubleInput
On entry: if weights are being supplied then the elements of wt must contain the weights associated with the observations, ${w}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
If weights are not supplied then wt must be set to NULL.
4:    $\mathbf{nvalid}$Integer *Output
On exit: is used to indicate the number of valid observations, $m$; see Section 3 (g).
5:    $\mathbf{xmean}$double *Output
On exit: the mean, $\stackrel{-}{x}$.
6:    $\mathbf{xsd}$double *Output
On exit: the standard deviation, ${s}_{2}$.
7:    $\mathbf{xskew}$double *Output
On exit: the coefficient of skewness, ${s}_{3}$.
8:    $\mathbf{xkurt}$double *Output
On exit: the coefficient of kurtosis, ${s}_{4}$.
9:    $\mathbf{xmin}$double *Output
On exit: the smallest value in the sample.
10:  $\mathbf{xmax}$double *Output
On exit: the largest value in the sample.
11:  $\mathbf{wsum}$double *Output
On exit: the sum of the weights in the array wt, that is $\sum _{i=1}^{n}{w}_{i}$. This will be $n$ if weighted estimates are not used.
12:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.2.1.2 in the Essential Introduction for further information.
On entry, argument $〈\mathit{\text{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, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
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 3.6.6 in the Essential Introduction for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 3.6.5 in the Essential Introduction for further information.
NE_REAL_ARG_LT
On entry, ${\mathbf{wt}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{wt}}\left[〈\mathit{\text{value}}〉\right]\ge 0.0$.

## 7  Accuracy

The method used is believed to be stable.

## 8  Parallelism and Performance

Not applicable.

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

## 10  Example

This example summarises an (optionally weighted) dataset and displays the results.

### 10.1  Program Text

Program Text (g01aace.c)

### 10.2  Program Data

Program Data (g01aace.d)

### 10.3  Program Results

Program Results (g01aace.r)