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_contab_tabulate_margin (g11bc)

Purpose

nag_contab_tabulate_margin (g11bc) computes a marginal table from a table computed by nag_contab_tabulate_stat (g11ba) or nag_contab_tabulate_percentile (g11bb) using a selected statistic.

Syntax

[stable, mcells, mdim, mlevel, auxt, ifail] = g11bc(stat, table, idim, isdim, maxst, 'ncells', ncells, 'ndim', ndim)
[stable, mcells, mdim, mlevel, auxt, ifail] = nag_contab_tabulate_margin(stat, table, idim, isdim, maxst, 'ncells', ncells, 'ndim', ndim)

Description

For a dataset containing classification variables (known as factors) the functions nag_contab_tabulate_stat (g11ba) and nag_contab_tabulate_percentile (g11bb) compute a table using selected statistics, for example the mean or the median. The table is indexed by the levels of the selected factors, for example if there were three factors A, B and C with 33, 22 and 44 levels respectively and the mean was to be tabulated the resulting table would be 3 × 2 × 43×2×4 with each cell being the mean of all observations with the appropriate combination of levels of the three factors. In further analysis the table of means averaged over C for A and B may be required; this can be computed from the full table by taking the mean over the third dimension of the table, C.
In general, given a table computed by nag_contab_tabulate_stat (g11ba) or nag_contab_tabulate_percentile (g11bb), nag_contab_tabulate_margin (g11bc) computes a sub-table defined by a subset of the factors used to define the table such that each cell of the sub-table is the selected statistic computed over the remaining factors. The statistics that can be used are the total, the mean, the median, the variance, the smallest and the largest value.

References

John J A and Quenouille M H (1977) Experiments: Design and Analysis Griffin
Kendall M G and Stuart A (1969) The Advanced Theory of Statistics (Volume 1) (3rd Edition) Griffin
West D H D (1979) Updating mean and variance estimates: An improved method Comm. ACM 22 532–555

Parameters

Compulsory Input Parameters

1:     stat – string (length ≥ 1)
Indicates which statistic is to be used to compute the marginal table.
stat = 'T'stat='T'
The total.
stat = 'A'stat='A'
The average or mean.
stat = 'M'stat='M'
The median.
stat = 'V'stat='V'
The variance.
stat = 'L'stat='L'
The largest value.
stat = 'S'stat='S'
The smallest value.
Constraint: stat = 'T'stat='T', 'A''A', 'M''M', 'V''V', 'L''L' or 'S''S'.
2:     table(ncells) – double array
3:     idim(ndim) – int64int32nag_int array
ndim, the dimension of the array, must satisfy the constraint ndim2ndim2.
The number of levels for each dimension of table as returned by nag_contab_tabulate_stat (g11ba) or nag_contab_tabulate_percentile (g11bb).
Constraint: idim(i)2idimi2, for i = 1,2,,ndimi=1,2,,ndim.
4:     isdim(ndim) – int64int32nag_int array
ndim, the dimension of the array, must satisfy the constraint ndim2ndim2.
Indicates which dimensions of table are to be included in the sub-table. If isdim(i) > 0isdimi>0 the dimension or factor indicated by idim(i)idimi is to be included in the sub-table, otherwise it is excluded.
5:     maxst – int64int32nag_int scalar
The maximum size of sub-table to be computed.
Constraint: maxstmaxst the product of the levels of the dimensions of table included in the sub-table, stable.

Optional Input Parameters

1:     ncells – int64int32nag_int scalar
Default: The dimension of the array table.
2:     ndim – int64int32nag_int scalar
Default: The dimension of the arrays idim, isdim. (An error is raised if these dimensions are not equal.)
The number of dimensions for table as returned by nag_contab_tabulate_stat (g11ba) or nag_contab_tabulate_percentile (g11bb).
Constraint: ndim2ndim2.

Input Parameters Omitted from the MATLAB Interface

iwk wk

Output Parameters

1:     stable(maxst) – double array
The first mcells elements contain the sub-table computed using the statistic indicated by stat. The table is stored in a similar way to table with the mcells cells stored so that for any two dimensions the index relating to the dimension given later in idim changes faster. For further details see Section [Further Comments].
2:     mcells – int64int32nag_int scalar
The number of cells in the sub-table in stable.
3:     mdim – int64int32nag_int scalar
The number of dimensions to the sub-table in stable.
4:     mlevel(ndim) – int64int32nag_int array
The first mdim elements contain the number of levels for the dimensions of the sub-table in stable. The remaining elements are not referenced.
5:     auxt( : :) – double array
Note: the dimension of the array auxt must be at least maxstmaxst if stat = 'V'stat='V', and at least 11 otherwise.
If stat = 'V'stat='V' auxt contains the sub-table of means corresponding to the sub-table of variances in stable. Otherwise auxt is not referenced.
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:
  ifail = 1ifail=1
On entry,ndim < 2ndim<2,
orstat'T'stat'T', 'A''A', 'M''M', 'V''V', 'L''L' or 'S''S'.
  ifail = 2ifail=2
On entry,idim(i)1idimi1, for some i = 1,2,,ndimi=1,2,,ndim,
orncells is incompatible with idim,
orthe requested sub-table is of dimension 00,
orthe requested sub-table is the full table,
ormaxst is too small, the minimum value is returned in mdim.

Accuracy

Only applicable when stat = 'V'stat='V'. In this case a one pass algorithm is used as describe in West (1979).

Further Comments

The sub-tables created by nag_contab_tabulate_margin (g11bc) and stored in stable and, depending on stat, also in auxt are stored in the following way. Let there be mm dimensions defining the table with dimension kk having lklk levels, then the cell defined by the levels i1,i2,,imi1,i2,,im of the factors is stored in ssth cell given by
m
s = 1 + [(ik1)ck],
k = 1
s=1+k=1m[(ik-1)ck],
where
m
cj = lk  for ​j = 1,2,,n1  and  cm = 1.
k = j + 1
cj=k=j+ 1m lk   for ​ j= 1, 2,, n- 1   and   cm=1.

Example

function nag_contab_tabulate_margin_example
stat = 'A';
table = [274;
     361;
     253;
     325;
     317;
     339;
     326;
     402;
     336;
     379;
     345;
     361;
     352;
     334;
     318;
     339;
     393;
     358;
     350;
     340;
     203;
     397;
     356;
     298;
     382;
     376;
     355;
     418;
     387;
     379;
     432;
     339;
     293;
     322;
     417;
     342;
     82;
     297;
     133;
     306;
     352;
     361;
     220;
     333;
     270;
     388;
     379;
     274;
     336;
     307;
     266;
     389;
     333;
     353];
idim = [int64(3);6;3];
isdim = [int64(0);1;1];
maxst = int64(54);
[stable, mcells, mdim, mlevel, auxt, ifail] = ...
    nag_contab_tabulate_margin(stat, table, idim, isdim, maxst)
 

stable =

  235.3333
  332.6667
  196.3333
  342.6667
  341.6667
  332.6667
  309.3333
  370.3333
  320.3333
  395.0000
  370.3333
  338.0000
  373.3333
  326.6667
  292.3333
  350.0000
  381.0000
  351.0000
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0


mcells =

                   18


mdim =

                    2


mlevel =

                    6
                    3
                    0


auxt =

     0


ifail =

                    0


function g11bc_example
stat = 'A';
table = [274;
     361;
     253;
     325;
     317;
     339;
     326;
     402;
     336;
     379;
     345;
     361;
     352;
     334;
     318;
     339;
     393;
     358;
     350;
     340;
     203;
     397;
     356;
     298;
     382;
     376;
     355;
     418;
     387;
     379;
     432;
     339;
     293;
     322;
     417;
     342;
     82;
     297;
     133;
     306;
     352;
     361;
     220;
     333;
     270;
     388;
     379;
     274;
     336;
     307;
     266;
     389;
     333;
     353];
idim = [int64(3);6;3];
isdim = [int64(0);1;1];
maxst = int64(54);
[stable, mcells, mdim, mlevel, auxt, ifail] = g11bc(stat, table, idim, isdim, maxst)
 

stable =

  235.3333
  332.6667
  196.3333
  342.6667
  341.6667
  332.6667
  309.3333
  370.3333
  320.3333
  395.0000
  370.3333
  338.0000
  373.3333
  326.6667
  292.3333
  350.0000
  381.0000
  351.0000
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0
         0


mcells =

                   18


mdim =

                    2


mlevel =

                    6
                    3
                    0


auxt =

     0


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