G11 Chapter Contents
G11 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG11BCF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G11BCF computes a marginal table from a table computed by G11BAF or G11BBF using a selected statistic.

## 2  Specification

 SUBROUTINE G11BCF ( STAT, TABLE, NCELLS, NDIM, IDIM, ISDIM, STABLE, MAXST, MCELLS, MDIM, MLEVEL, AUXT, IWK, WK, IFAIL)
 INTEGER NCELLS, NDIM, IDIM(NDIM), ISDIM(NDIM), MAXST, MCELLS, MDIM, MLEVEL(NDIM), IWK(3*NDIM), IFAIL REAL (KIND=nag_wp) TABLE(NCELLS), STABLE(MAXST), AUXT(*), WK(NCELLS) CHARACTER(1) STAT

## 3  Description

For a dataset containing classification variables (known as factors) the routines G11BAF and G11BBF 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 $3$, $2$ and $4$ levels respectively and the mean was to be tabulated the resulting table would be $3×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 G11BAF or G11BBF, G11BCF 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.

## 4  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

## 5  Parameters

1:     STAT – CHARACTER(1)Input
On entry: indicates which statistic is to be used to compute the marginal table.
${\mathbf{STAT}}=\text{'T'}$
The total.
${\mathbf{STAT}}=\text{'A'}$
The average or mean.
${\mathbf{STAT}}=\text{'M'}$
The median.
${\mathbf{STAT}}=\text{'V'}$
The variance.
${\mathbf{STAT}}=\text{'L'}$
The largest value.
${\mathbf{STAT}}=\text{'S'}$
The smallest value.
Constraint: ${\mathbf{STAT}}=\text{'T'}$, $\text{'A'}$, $\text{'M'}$, $\text{'V'}$, $\text{'L'}$ or $\text{'S'}$.
2:     TABLE(NCELLS) – REAL (KIND=nag_wp) arrayInput
On entry: the table as computed by G11BAF or G11BBF.
3:     NCELLS – INTEGERInput
On entry: the number of cells in TABLE as returned by G11BAF or G11BBF.
4:     NDIM – INTEGERInput
On entry: the number of dimensions for TABLE as returned by G11BAF or G11BBF.
Constraint: ${\mathbf{NDIM}}\ge 2$.
5:     IDIM(NDIM) – INTEGER arrayInput
On entry: the number of levels for each dimension of TABLE as returned by G11BAF or G11BBF.
Constraint: ${\mathbf{IDIM}}\left(\mathit{i}\right)\ge 2$, for $\mathit{i}=1,2,\dots ,{\mathbf{NDIM}}$.
6:     ISDIM(NDIM) – INTEGER arrayInput
On entry: indicates which dimensions of TABLE are to be included in the sub-table. If ${\mathbf{ISDIM}}\left(i\right)>0$ the dimension or factor indicated by ${\mathbf{IDIM}}\left(i\right)$ is to be included in the sub-table, otherwise it is excluded.
7:     STABLE(MAXST) – REAL (KIND=nag_wp) arrayOutput
On exit: 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 8.
8:     MAXST – INTEGERInput
On entry: the maximum size of sub-table to be computed.
Constraint: ${\mathbf{MAXST}}\ge \text{}$ the product of the levels of the dimensions of TABLE included in the sub-table, STABLE.
9:     MCELLS – INTEGEROutput
On exit: the number of cells in the sub-table in STABLE.
10:   MDIM – INTEGEROutput
On exit: the number of dimensions to the sub-table in STABLE.
11:   MLEVEL(NDIM) – INTEGER arrayOutput
On exit: the first MDIM elements contain the number of levels for the dimensions of the sub-table in STABLE. The remaining elements are not referenced.
12:   AUXT($*$) – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array AUXT must be at least ${\mathbf{MAXST}}$ if ${\mathbf{STAT}}=\text{'V'}$, and at least $1$ otherwise.
On exit: if ${\mathbf{STAT}}=\text{'V'}$ AUXT contains the sub-table of means corresponding to the sub-table of variances in STABLE. Otherwise AUXT is not referenced.
13:   IWK($3×{\mathbf{NDIM}}$) – INTEGER arrayWorkspace
14:   WK(NCELLS) – REAL (KIND=nag_wp) arrayWorkspace
15:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{NDIM}}<2$, or ${\mathbf{STAT}}\ne \text{'T'}$, $\text{'A'}$, $\text{'M'}$, $\text{'V'}$, $\text{'L'}$ or $\text{'S'}$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{IDIM}}\left(i\right)\le 1$, for some $i=1,2,\dots ,{\mathbf{NDIM}}$, or NCELLS is incompatible with IDIM, or the requested sub-table is of dimension $0$, or the requested sub-table is the full table, or MAXST is too small, the minimum value is returned in MDIM.

## 7  Accuracy

Only applicable when ${\mathbf{STAT}}=\text{'V'}$. In this case a one pass algorithm is used as describe in West (1979).

The sub-tables created by G11BCF and stored in STABLE and, depending on STAT, also in AUXT are stored in the following way. Let there be $m$ dimensions defining the table with dimension $k$ having ${l}_{k}$ levels, then the cell defined by the levels ${i}_{1},{i}_{2},\dots ,{i}_{m}$ of the factors is stored in $s$th cell given by
 $s=1+∑k=1mik-1ck,$
where
 $cj=∏k=j+ 1m lk for ​ j= 1, 2,…, n- 1 and cm=1.$

## 9  Example

The data, given by John and Quenouille (1977), is for 3 blocks of a $3×6$ factorial experiment. The data can be considered as a $3×6×3$ table (i.e., blocks $×$ treatment with $6$ levels $×$ treatment with $3$ levels). This table is input and the $6×3$ table of treatment means for over blocks is computed and printed.

### 9.1  Program Text

Program Text (g11bcfe.f90)

### 9.2  Program Data

Program Data (g11bcfe.d)

### 9.3  Program Results

Program Results (g11bcfe.r)