hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_stat_summary_freq (g01ad)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

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, for i=1,2,,k-1, and the boundary values of the classes xi, for i=1,2,,k. Thus the frequency associated with the interval xi,xi+1 is fi, 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 ,  n2.  
(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 y1,,yk-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 .  

References

None.

Parameters

Compulsory Input Parameters

1:     xk – double array
The elements of x must contain the boundary values of the classes in ascending order, so that class i is bounded by the values in xi and xi+1, for i=1,2,,k-1.
Constraint: xi<xi+1, for i=1,2,,k-1.
2:     ifreqk int64int32nag_int array
The ith element of ifreq must contain the frequency associated with the ith class, for i=1,2,,k-1. ifreqk is not used by the function.
Constraints:
  • ifreqi0, for i=1,2,,k-1;
  • i=1 k-1ifreqi>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, the number of class boundaries, which is one more than the number of classes of the frequency distribution.
Constraint: k>1.

Output Parameters

1:     xmean – double scalar
The mean value, y-.
2:     s2 – double scalar
The standard deviation, s2.
3:     s3 – double scalar
The coefficient of skewness, s3.
4:     s4 – double scalar
The coefficient of kurtosis, s4.
5:     n int64int32nag_int scalar
The total frequency, n.
6:     ifail int64int32nag_int scalar
ifail=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
On entry,k1.
   ifail=2
On entry,the boundary values of the classes in x are not in ascending order.
   ifail=3
On entry,i=1 k-1ifreqi=0 or ifreqi<0 for some i, for i=1,2,,k-1.
W  ifail=4
The total frequency, n, is less than 2, hence the quantities s2, s3 and s4 cannot be calculated.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

The method used is believed to be stable.

Further Comments

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


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

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

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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