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)

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 fifi, for i = 1,2,,k1i=1,2,,k-1, and the boundary values of the classes xixi, for i = 1,2,,ki=1,2,,k. Thus the frequency associated with the interval (xi,xi + 1)(xi,xi+1) is fifi, 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,,k1.
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 = 1k1fiyi)/n.
y-=i=1 k-1fiyin.
(c) standard deviation,
s2 = sqrt((i = 1k 1fi(yiy)2)/((n1))),   n 2.
s2=i= 1 k- 1fi (yi-y-) 2 (n- 1) ,   n 2.
(d) coefficient of skewness,
s3 = (i = 1k1fi(yiy)3)/((n1) × s23),  n2.
s3=i=1 k-1fi (yi-y-) 3 (n-1)×s23 ,  n2.
(e) coefficient of kurtosis,
s4 = (i = 1k 1fi(yiy)4)/((n1) × 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,,yk1y1,,yk-1, then the boundary values for the classes may be defined as follows:
(i) for k > 2k>2,
x1 = (3y1y2) / 2
xj = (yj1 + yj) / 2, j = 2,,k1
xk = (3yk1yk2) / 2
x1=(3y1-y2)/2 xj=(yj-1+yj)/2, j=2,,k-1 xk=(3yk-1-yk-2)/2
(ii) for k = 2k=2,
x1 = y1a   and   x2 = y1 + a   for any ​a > 0 .
x1=y1-a   and   x2=y1+a   for any ​a>0 .

References

None.

Parameters

Compulsory Input Parameters

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

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     xmean – double scalar
The mean value, yy-.
2:     s2 – double scalar
The standard deviation, s2s2.
3:     s3 – double scalar
The coefficient of skewness, s3s3.
4:     s4 – double scalar
The coefficient of kurtosis, s4s4.
5:     n – int64int32nag_int scalar
The total frequency, nn.
6:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 = 1ifail=1
On entry,k1k1.
  ifail = 2ifail=2
On entry,the boundary values of the classes in x are not in ascending order.
  ifail = 3ifail=3
On entry,i = 1k1ifreq(i) = 0i=1 k-1ifreqi=0 or ifreq(i) < 0ifreqi<0 for some ii, for i = 1,2,,k1i=1,2,,k-1.
W ifail = 4ifail=4
The total frequency, nn, is less than 22, hence the quantities s2s2, s3s3 and s4s4 cannot be calculated.

Accuracy

The method used is believed to be stable.

Further Comments

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

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



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–2013