Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_stat_summary_1var (g01aa)

## Purpose

nag_stat_summary_1var (g01aa) 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.
Note: this function is scheduled to be withdrawn, please see g01aa in Advice on Replacement Calls for Withdrawn/Superseded Routines..

## Syntax

[xmean, s2, s3, s4, xmin, xmax, iwt, wtsum, ifail] = g01aa(x, 'n', n, 'wt', wt)
[xmean, s2, s3, s4, xmin, xmax, iwt, wtsum, ifail] = nag_stat_summary_1var(x, 'n', n, 'wt', wt)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: wt no longer an output parameter, output parameters re-ordered
.

## Description

The data consist of a single sample of n$n$ observations, denoted by xi${x}_{i}$, with corresponding weights, wi${w}_{i}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
If no specific weighting is required, then each wi${w}_{i}$ is set to 1$1$.
The quantities computed are:
(a) The sum of the weights
 n W = ∑ wi. i = 1
$W=∑i=1nwi.$
(b) Mean
 x = ( ∑ i = 1nwixi)/W. $x-=∑i= 1nwixiW.$
(c) Standard deviation
 s2 = sqrt(( ∑ i = 1nwi(xi − x)2)/d),   where  d = W − ( ∑ i = 1nwi2)/W. $s2=∑i=1nwi (xi-x-) 2d, where d=W-∑i=1nwi2W.$
(d) Coefficient of skewness
 s3 = ( ∑ i = 1nwi(xi − x)3)/(d × s23). $s3=∑i= 1nwi (xi-x-) 3 d×s23 .$
(e) Coefficient of kurtosis
 s4 = ( ∑ i = 1nwi(xi − x)4)/(d × s24) − 3. $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${w}_{i}>0$, i.e., the number of valid observations. Suppose m$m$ observations are valid, then the quantities in (c), (d) and (e) will be computed if m2$m\ge 2$, and will be based on m1$m-1$ degrees of freedom. The other quantities are evaluated provided m1$m\ge 1$.

None.

## Parameters

### Compulsory Input Parameters

1:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The sample observations, xi${x}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays x, wt. (An error is raised if these dimensions are not equal.)
n$n$, the number of observations.
Constraint: n1${\mathbf{n}}\ge 1$.
2:     wt(n) – double array
If the user wishes to supply weights then the elements of wt must contain the weights associated with the observations, wi${w}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.

iwt

### Output Parameters

1:     xmean – double scalar
The mean, x$\stackrel{-}{x}$.
2:     s2 – double scalar
The standard deviation, s2${s}_{2}$.
3:     s3 – double scalar
The coefficient of skewness, s3${s}_{3}$.
4:     s4 – double scalar
The coefficient of kurtosis, s4${s}_{4}$.
5:     xmin – double scalar
The smallest value in the sample.
6:     xmax – double scalar
The largest value in the sample.
7:     iwt – int64int32nag_int scalar
iwt is used to indicate the number of valid observations, m$m$; see (g) in Section [Description] above.
8:     wtsum – double scalar
The sum of the weights in the array wt, that is i = 1nwi$\sum _{i=1}^{n}{w}_{i}$. This will be n if iwt was 0$0$ on entry.
9:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

ifail = 1${\mathbf{ifail}}=1$
 On entry, n < 1${\mathbf{n}}<1$.
W ifail = 2${\mathbf{ifail}}=2$
The number of valid cases, m$m$, is 1$1$. In this case, standard deviation and coefficients of skewness and of kurtosis cannot be calculated.
ifail = 3${\mathbf{ifail}}=3$
Either the number of valid cases is 0$0$, or at least one weight is negative.

## Accuracy

The method used is believed to be stable.

The time taken by nag_stat_summary_1var (g01aa) is approximately proportional to n$n$.

## Example

```function nag_stat_summary_1var_example
x = [193;
216;
112;
161;
92;
140;
38;
33;
279;
249;
473;
339;
60;
130;
20;
50;
257;
284;
447;
52;
67;
61;
150;
2200];
[xmean, s2, s3, s4, xmin, xmax, iwt, wtsum, ifail] = nag_stat_summary_1var(x)
```
```

xmean =

254.2917

s2 =

433.5318

s3 =

3.8951

s4 =

14.6653

xmin =

20

xmax =

2200

iwt =

24

wtsum =

24

ifail =

0

```
```function g01aa_example
x = [193;
216;
112;
161;
92;
140;
38;
33;
279;
249;
473;
339;
60;
130;
20;
50;
257;
284;
447;
52;
67;
61;
150;
2200];
[xmean, s2, s3, s4, xmin, xmax, iwt, wtsum, ifail] = g01aa(x)
```
```

xmean =

254.2917

s2 =

433.5318

s3 =

3.8951

s4 =

14.6653

xmin =

20

xmax =

2200

iwt =

24

wtsum =

24

ifail =

0

```