The function may be called by the names: g11bbc, nag_contab_tabulate_percentile or nag_tabulate_percentile.
A dataset may include both classification variables and general variables. The classification variables, known as factors, take a small number of values known as levels. For example, the factor sex would have the levels male and female. These can be coded as 1 and 2 respectively. Given several factors, a multi-way table can be constructed such that each cell of the table represents one level from each factor. For example, the two factors sex and habitat, habitat having three levels: inner-city, suburban and rural, define the 2 by 3 contingency table:
For each cell statistics can be computed. If a third variable in the dataset was age then for each cell the median age could be computed:
That is the median age for all observations for males living in rural areas is . The median being the % quantile. Other quantiles can also be computed: the percent quantile or percentile, , is the estimate of the value such that percent of observations are less than . This is calculated in two different ways depending on whether the tabulated variable is continuous or discrete. Let there be values in a cell and let , be the values for that cell sorted into ascending order. Also, associated with each value there is a weight, , , which could represent the observed frequency for that value, with and . For the percentile let and then the percentiles for the two cases are as given below.
If the variable is discrete, that is takes only a limited number of (usually integer) values then the percentile is defined as:
If the data is continuous then the quantiles are estimated by linear interpolation.
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
1: – Nag_TabulateVarInput
On entry: indicates whether the variable to be tabulated is discrete or continuous.
The percentiles are computed for a discrete variable.
The percentiles are computed for a continuous variable using linear interpolation.
2: – IntegerInput
On entry: the number of observations.
3: – IntegerInput
On entry: the number of classifying factors in factor.
4: – const IntegerInput
On entry: indicates which factors in factor are to be used in the tabulation.
If the th factor in factor is included in the tabulation.
Note that if , for then the statistic for the whole sample is calculated and returned in a 1 by 1 table.
5: – const IntegerInput
On entry: the number of levels of the classifying factors in factor.
, for .
6: – const IntegerInput
On entry: the nfac coded classification factors for the n observations.
if , , for and .
7: – IntegerInput
On entry: the stride separating matrix column elements in the array factor.
8: – doubleInput
On entry: the percentile to be tabulated, .
9: – const doubleInput
On entry: the variable to be tabulated.
10: – const doubleInput
On entry: wt must contain the n weights. Otherwise wt must be set to NULL.
, for .
11: – doubleOutput
On exit: the computed table. The ncells cells of the table are stored so that for any two factors the index relating to the factor occurring later in lfac and factor changes faster. For further details see Section 9.
12: – IntegerInput
On entry: the maximum size of the table to be computed.
product of the levels of the factors included in the tabulation.
13: – Integer *Output
On exit: the number of cells in the table.
14: – Integer *Output
On exit: the number of factors defining the table.
15: – IntegerOutput
On exit: the first ndim elements contain the number of levels for the factors defining the table.
16: – IntegerOutput
On exit: a table containing the number of observations contributing to each cell of the table, stored identically to table.
17: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
The maximum size of the table to be computed, maxt is too small.
On entry, .
On entry, .
Constraint: , for .
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g11bbc is not threaded in any implementation.
The tables created by g11bbc and stored in table and count are stored in the following way. Let there be factors defining the table with factor having levels, then the cell defined by the levels of the factors is stored in th cell given by:
where , for and .
The data, given by John and Quenouille (1977), are for a 3 by 6 factorial experiment in 3 blocks of 18 units. The data is input in the order: blocks, factor with 3 levels, factor with 6 levels, yield, and the 3 by 6 table of treatment medians for yield over blocks is computed and printed.