PDF version (NAG web site
, 64-bit version, 64-bit version)
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
,
and
levels respectively and the mean was to be tabulated the resulting table would be
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:
– string (length ≥ 1)
-
Indicates which statistic is to be used to compute the marginal table.
- The total.
- The average or mean.
- The median.
- The variance.
- The largest value.
- The smallest value.
Constraint:
, , , , or .
- 2:
– double array
-
- 3:
– int64int32nag_int array
-
Constraint:
, for .
- 4:
– int64int32nag_int array
-
Indicates which dimensions of
table are to be included in the sub-table. If
the dimension or factor indicated by
is to be included in the sub-table, otherwise it is excluded.
- 5:
– int64int32nag_int scalar
-
The maximum size of sub-table to be computed.
Constraint:
the product of the levels of the dimensions of
table included in the sub-table,
stable.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
table.
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the arrays
idim,
isdim. (An error is raised if these dimensions are not equal.)
Constraint:
.
Output Parameters
- 1:
– 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
Further Comments.
- 2:
– int64int32nag_int scalar
-
The number of cells in the sub-table in
stable.
- 3:
– int64int32nag_int scalar
-
The number of dimensions to the sub-table in
stable.
- 4:
– 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:
– double array
-
The dimension of the array
auxt will be
if
and
otherwise
If
auxt contains the sub-table of means corresponding to the sub-table of variances in
stable. Otherwise
auxt is not referenced.
- 6:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
On entry, | , |
or | , , , , or . |
-
-
On entry, | , for some , |
or | ncells is incompatible with idim, |
or | the requested sub-table is of dimension , |
or | the requested sub-table is the full table, |
or | maxst is too small, the minimum value is returned in mdim. |
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
Only applicable when
. 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
dimensions defining the table with dimension
having
levels, then the cell defined by the levels
of the factors is stored in
th cell given by
where
Example
The data, given by
John and Quenouille (1977), is for 3 blocks of a
factorial experiment. The data can be considered as a
table (i.e., blocks
treatment with
levels
treatment with
levels). This table is input and the
table of treatment means for over blocks is computed and printed.
Open in the MATLAB editor:
g11bc_example
function g11bc_example
fprintf('g11bc example results\n\n');
y = [ 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];
maxt = prod(idim(isdim~=0));
maxt = int64(maxt);
stat = 'A';
[table, mcells, mdim, mlevel, auxt, ifail] = ...
g11bc( ...
stat, y, idim, isdim, maxt);
fprintf(' Marginal Table\n\n');
ncol = mlevel(mdim);
nrow = mcells/ncol;
table = transpose(reshape(table,[ncol,nrow]));
for i = 1:nrow
fprintf('%8.2f', table(i,:));
fprintf('\n');
end
g11bc example results
Marginal Table
235.33 332.67 196.33
342.67 341.67 332.67
309.33 370.33 320.33
395.00 370.33 338.00
373.33 326.67 292.33
350.00 381.00 351.00
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015