# naginterfaces.library.contab.tabulate_​margin¶

naginterfaces.library.contab.tabulate_margin(stat, table, idim, isdim, maxst)[source]

tabulate_margin computes a marginal table from a table computed by tabulate_stat() or tabulate_percentile() using a selected statistic.

For full information please refer to the NAG Library document for g11bc

https://support.nag.com/numeric/nl/nagdoc_30.1/flhtml/g11/g11bcf.html

Parameters
statstr, 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.

tablefloat, array-like, shape

The table as computed by tabulate_stat() or tabulate_percentile().

idimint, array-like, shape

The number of levels for each dimension of as returned by tabulate_stat() or tabulate_percentile().

isdimint, array-like, shape

Indicates which dimensions of 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.

maxstint

The maximum size of sub-table to be computed.

Returns
stablefloat, ndarray, shape

The first elements contain the sub-table computed using the statistic indicated by . The table is stored in a similar way to with the cells stored so that for any two dimensions the index relating to the dimension given later in changes faster. For further details see Further Comments.

mcellsint

The number of cells in the sub-table in .

mdimint

The number of dimensions to the sub-table in .

mlevelint, ndarray, shape

The first elements contain the number of levels for the dimensions of the sub-table in . The remaining elements are not referenced.

auxtfloat, ndarray, shape

If contains the sub-table of means corresponding to the sub-table of variances in . Otherwise is not referenced.

Raises
NagValueError
(errno )

On entry, .

Constraint: , , , , or .

(errno )

On entry, .

Constraint: .

(errno )

On entry, and minimum value for .

Constraint: of the levels of the dimensions of the included in the sub-table, .

(errno )

On entry, all elements of .

(errno )

On entry, no elements of .

(errno )

On entry, is incompatible with .

(errno )

On entry, and .

Constraint: .

Notes

For a dataset containing classification variables (known as factors) the functions tabulate_stat() and tabulate_percentile() 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 tabulate_stat() or tabulate_percentile(), tabulate_margin 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