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_withdraw_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_withdraw_summary_1var(x, 'n', n, 'wt', wt)
Note: the interface to this routine has changed since earlier releases of the toolbox:
 At Mark 23: wt is no longer an output parameter; output parameters were reordered

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
The sample observations, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.

### Optional Input Parameters

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

### Output Parameters

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

${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}<1$.
W  ${\mathbf{ifail}}=2$
The number of valid cases, $m$, is $1$. In this case, standard deviation and coefficients of skewness and of kurtosis cannot be calculated.
${\mathbf{ifail}}=3$
Either the number of valid cases is $0$, or at least one weight is negative.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The method used is believed to be stable.

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

## Example

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

fprintf('g01aa example results\n\n');

% Data
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];
n = size(x,2);

% Get simple statistics of data
[xmean, s2, s3, s4, xmin, xmax, iwt, wtsum, ifail] = ...
g01aa(x);

fprintf('Number of cases    %7d\n',n);
fprintf('Data as input -\n');
fprintf('%12.1f%12.1f%12.1f%12.1f%12.1f\n',x)
fprintf('\n\n');
fprintf('No. of valid cases %7d\n',iwt);
fprintf('Mean               %7.1f\n',xmean);
fprintf('Minimum            %7.1f\n',xmin);
fprintf('Maximum            %7.1f\n',xmax);
fprintf('Sum of weights     %7.1f\n',wtsum);
fprintf('Std devn           %7.1f\n',s2);
fprintf('Skewness           %7.1f\n',s3);
fprintf('Kurtosis           %7.1f\n',s4);

```
```g01aa example results

Number of cases         24
Data as input -
193.0       216.0       112.0       161.0        92.0
140.0        38.0        33.0       279.0       249.0
473.0       339.0        60.0       130.0        20.0
50.0       257.0       284.0       447.0        52.0
67.0        61.0       150.0      2200.0

No. of valid cases      24
Mean                 254.3
Minimum               20.0
Maximum             2200.0
Sum of weights        24.0
Std devn             433.5
Skewness               3.9
Kurtosis              14.7
```