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 fi${f}_{i}$, for i = 1,2,,k1$\mathit{i}=1,2,\dots ,k-1$, and the boundary values of the classes xi${x}_{i}$, for i = 1,2,,k$\mathit{i}=1,2,\dots ,k$. Thus the frequency associated with the interval (xi,xi + 1)$\left({x}_{i},{x}_{i+1}\right)$ is fi${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. $yi=(xi+1+xi)/2, i=1,2,…,k-1.$
The following quantities are calculated:
(a) total frequency,
 k − 1 n = ∑ fi. i = 1
$n=∑i= 1 k- 1fi.$
(b) mean,
 y = ( ∑ i = 1k − 1fiyi)/n. $y-=∑i=1 k-1fiyin.$
(c) standard deviation,
 s2 = sqrt(( ∑ i = 1k − 1fi(yi − y)2)/((n − 1))),   n ≥ 2. $s2=∑i= 1 k- 1fi (yi-y-) 2 (n- 1) , n≥ 2.$
(d) coefficient of skewness,
 s3 = ( ∑ i = 1k − 1fi(yi − y)3)/((n − 1) × s23),  n ≥ 2. $s3=∑i=1 k-1fi (yi-y-) 3 (n-1)×s23 , n≥2.$
(e) coefficient of kurtosis,
 s4 = ( ∑ i = 1k − 1fi(yi − y)4)/((n − 1) × s24) − 3,   n ≥ 2. $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 y1,,yk1${y}_{1},\dots ,{y}_{k-1}$, then the boundary values for the classes may be defined as follows:
(i) for k > 2$k>2$,
 x1 = (3y1 − y2) / 2 xj = (yj − 1 + yj) / 2, j = 2, … ,k − 1 xk = (3yk − 1 − yk − 2) / 2
$x1=(3y1-y2)/2 xj=(yj-1+yj)/2, j=2,…,k-1 xk=(3yk-1-yk-2)/2$
(ii) for k = 2$k=2$,
 x1 = y1 − a   and   x2 = y1 + a   for any ​a > 0 . $x1=y1-a and x2=y1+a for any ​a>0 .$

None.

## Parameters

### Compulsory Input Parameters

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

### Optional Input Parameters

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

None.

### Output Parameters

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

## Accuracy

The method used is believed to be stable.

The time taken by nag_stat_summary_freq (g01ad) increases linearly with k$k$.

## Example

```function nag_stat_summary_freq_example
x = [9.3;
12;
14;
16;
18;
20;
22;
24;
26;
28;
30;
32;
34;
36;
39.7];
ifreq = [int64(3);19;52;96;121;115;86;70;49;31;16;6;8;7;0];
[xmean, s2, s3, s4, n, ifail] = nag_stat_summary_freq(x, ifreq)
```
```

xmean =

21.4932

s2 =

4.9325

s3 =

0.7072

s4 =

0.5738

n =

679

ifail =

0

```
```function g01ad_example
x = [9.3;
12;
14;
16;
18;
20;
22;
24;
26;
28;
30;
32;
34;
36;
39.7];
ifreq = [int64(3);19;52;96;121;115;86;70;49;31;16;6;8;7;0];
[xmean, s2, s3, s4, n, ifail] = g01ad(x, ifreq)
```
```

xmean =

21.4932

s2 =

4.9325

s3 =

0.7072

s4 =

0.5738

n =

679

ifail =

0

```