g01 Chapter Contents
g01 Chapter Introduction
NAG C 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:     nIntegerInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}\ge 1$.
2:     x[n]const doubleInput
On entry: the sample observations, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,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, ${w}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,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, $\stackrel{-}{x}$.
6:     xsddouble *Output
On exit: the standard deviation, ${s}_{2}$.
7:     xskewdouble *Output
On exit: the coefficient of skewness, ${s}_{3}$.
8:     xkurtdouble *Output
On exit: the coefficient of kurtosis, ${s}_{4}$.
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 $\sum _{i=1}^{n}{w}_{i}$. 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

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

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)