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

## Purpose

nag_stat_summary_freq (g01ad) calculates the mean, standard deviation and coefficients of skewness and kurtosis for data grouped in a frequency distribution.

## Syntax

[xmean, s2, s3, s4, n, ifail] = g01ad(x, ifreq, 'k', k)
[xmean, s2, s3, s4, n, ifail] = nag_stat_summary_freq(x, ifreq, 'k', k)

## Description

The input data consist of a univariate frequency distribution, denoted by ${f}_{i}$, for $\mathit{i}=1,2,\dots ,k-1$, and the boundary values of the classes ${x}_{i}$, for $\mathit{i}=1,2,\dots ,k$. Thus the frequency associated with the interval $\left({x}_{i},{x}_{i+1}\right)$ is ${f}_{i}$, and nag_stat_summary_freq (g01ad) assumes that all the values in this interval are concentrated at the point
 $yi=xi+1+xi/2, i=1,2,…,k-1.$
The following quantities are calculated:
(a) total frequency,
 $n=∑i= 1 k- 1fi.$
(b) mean,
 $y-=∑i=1 k-1fiyin.$
(c) standard deviation,
 $s2=∑i= 1 k- 1fi yi-y- 2 n- 1 , n≥ 2.$
(d) coefficient of skewness,
 $s3=∑i=1 k-1fi yi-y- 3 n-1×s23 , n≥2.$
(e) coefficient of kurtosis,
 $s4=∑i= 1 k- 1fi yi-y- 4 n- 1×s24 - 3, n≥ 2.$
The function has been developed primarily for groupings of a continuous variable. If, however, the function is to be used on the frequency distribution of a discrete variable, taking the values ${y}_{1},\dots ,{y}_{k-1}$, then the boundary values for the classes may be defined as follows:
(i) for $k>2$,
 $x1=3y1-y2/2 xj=yj-1+yj/2, j=2,…,k-1 xk=3yk-1-yk-2/2$
(ii) for $k=2$,
 $x1=y1-a and x2=y1+a for any ​a>0 .$

None.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}\left({\mathbf{k}}\right)$ – double array
The elements of x must contain the boundary values of the classes in ascending order, so that class $\mathit{i}$ is bounded by the values in ${\mathbf{x}}\left(\mathit{i}\right)$ and ${\mathbf{x}}\left(\mathit{i}+1\right)$, for $\mathit{i}=1,2,\dots ,k-1$.
Constraint: ${\mathbf{x}}\left(\mathit{i}\right)<{\mathbf{x}}\left(\mathit{i}+1\right)$, for $\mathit{i}=1,2,\dots ,k-1$.
2:     $\mathrm{ifreq}\left({\mathbf{k}}\right)$int64int32nag_int array
The $\mathit{i}$th element of ifreq must contain the frequency associated with the $\mathit{i}$th class, for $\mathit{i}=1,2,\dots ,k-1$. ${\mathbf{ifreq}}\left(k\right)$ is not used by the function.
Constraints:
• ${\mathbf{ifreq}}\left(\mathit{i}\right)\ge 0$, for $\mathit{i}=1,2,\dots ,k-1$;
• $\sum _{i=1}^{k-1}{\mathbf{ifreq}}\left(i\right)>0$.

### Optional Input Parameters

1:     $\mathrm{k}$int64int32nag_int scalar
Default: the dimension of the arrays x, ifreq. (An error is raised if these dimensions are not equal.)
$k$, the number of class boundaries, which is one more than the number of classes of the frequency distribution.
Constraint: ${\mathbf{k}}>1$.

### Output Parameters

1:     $\mathrm{xmean}$ – double scalar
The mean value, $\stackrel{-}{y}$.
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{n}$int64int32nag_int scalar
The total frequency, $n$.
6:     $\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{k}}\le 1$.
${\mathbf{ifail}}=2$
 On entry, the boundary values of the classes in x are not in ascending order.
${\mathbf{ifail}}=3$
 On entry, $\sum _{i=1}^{k-1}{\mathbf{ifreq}}\left(i\right)=0$ or ${\mathbf{ifreq}}\left(i\right)<0$ for some $i$, for $i=1,2,\dots ,k-1$.
W  ${\mathbf{ifail}}=4$
The total frequency, $n$, is less than $2$, hence the quantities ${s}_{2}$, ${s}_{3}$ and ${s}_{4}$ cannot be calculated.
${\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_freq (g01ad) increases linearly with $k$.

## Example

In the example program, NPROB determines the number of sets of data to be analysed. For each analysis, the boundary values of the classes and the frequencies are read. After nag_stat_summary_freq (g01ad) has been successfully called, the input data and calculated quantities are printed. In the example, there is one set of data, with $14$ classes.
```function g01ad_example

x     = [  9.3     12     14     16     18  ...
20       22     24     26     28  ...
30       32     34     36     39.7];
ifreq = [  3       19     52     96    121  ...
115       86     70     49     31  ...
16        6      8      7      0];
ifreq = int64(ifreq);

[xmean, s2, s3, s4, n, ifail] = g01ad( ...
x, ifreq);

fprintf('Number of classes %7d\n\n',size(x,2)-1);

fprintf('%14s%20s\n', 'Class', 'Frequency');
fprintf('%9.2f%9.2f%15d\n',[x(1:end-1);x(2:end);ifreq(1:end-1)]);
fprintf('\n');
fprintf('Mean               %10.4f\n',xmean);
fprintf('Std devn           %10.4f\n',s2);
fprintf('Skewness           %10.4f\n',s3);
fprintf('Kurtosis           %10.4f\n',s4);
fprintf('Number of cases    %5d\n',n);

```
```g01ad example results

Number of classes      14

Class           Frequency
9.00    12.00              3
12.00    14.00             19
14.00    16.00             52
16.00    18.00             96
18.00    20.00            121
20.00    22.00            115
22.00    24.00             86
24.00    26.00             70
26.00    28.00             49
28.00    30.00             31
30.00    32.00             16
32.00    34.00              6
34.00    36.00              8
36.00    40.00              7

Mean                  21.4932
Std devn               4.9325
Skewness               0.7072
Kurtosis               0.5738
Number of cases      679
```

Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015