G11BBF computes a table from a set of classification factors using a given percentile or quantile, for example the median.
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
and
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
contingency table
Sex |
Habitat |
|
Inner-city |
Suburban |
Rural |
Male |
|
|
|
Female |
|
|
|
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:
Sex |
Habitat |
|
Inner-city |
Suburban |
Rural |
Male |
24 |
31 |
37 |
Female |
21.5 |
28.5 |
33 |
That is, the median age for all observations for males living in rural areas is
, the median being the 50% 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, it 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.
where
.
- 1: – CHARACTER(1)Input
-
On entry: indicates if 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.
Constraint:
or .
- 2: – CHARACTER(1)Input
-
On entry: indicates if there are weights associated with the variable to be tabulated.
- Weights are not input and unit weights are assumed.
- Weights must be supplied in WT.
Constraint:
or .
- 3: – INTEGERInput
-
On entry: the number of observations.
Constraint:
.
- 4: – INTEGERInput
-
On entry: the number of classifying factors in
IFAC.
Constraint:
.
- 5: – INTEGER arrayInput
-
On entry: indicates which factors in
IFAC are to be used in the tabulation.
If
the
th factor in
IFAC is included in the tabulation.
Note that if
, for then the statistic for the whole sample is calculated and returned in a table.
- 6: – INTEGER arrayInput
-
On entry: the number of levels of the classifying factors in
IFAC.
Constraint:
if , , for .
- 7: – INTEGER arrayInput
-
On entry: the
NFAC coded classification factors for the
N observations.
Constraint:
, for and .
- 8: – INTEGERInput
-
On entry: the first dimension of the array
IFAC as declared in the (sub)program from which G11BBF is called.
Constraint:
.
- 9: – REAL (KIND=nag_wp)Input
-
On entry: , the percentile to be tabulated.
Constraint:
.
- 10: – REAL (KIND=nag_wp) arrayInput
-
On entry: the variable to be tabulated.
- 11: – REAL (KIND=nag_wp) arrayInput
-
Note: the dimension of the array
WT
must be at least
if
, and at least
otherwise.
On entry: if
,
WT must contain the
N weights. Otherwise
WT is not referenced.
Constraint:
if , , for .
- 12: – REAL (KIND=nag_wp) arrayOutput
-
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
IFAC changes faster. For further details see
Section 9.
- 13: – INTEGERInput
-
On entry: the maximum size of the table to be computed.
Constraint:
product of the levels of the factors included in the tabulation.
- 14: – INTEGEROutput
-
On exit: the number of cells in the table.
- 15: – INTEGEROutput
-
On exit: the number of factors defining the table.
- 16: – INTEGER arrayOutput
-
On exit: the first
NDIM elements contain the number of levels for the factors defining the table.
- 17: – INTEGER arrayOutput
-
On exit: a table containing the number of observations contributing to each cell of the table, stored identically to
TABLE.
- 18: – INTEGER arrayWorkspace
- 19: – REAL (KIND=nag_wp) arrayWorkspace
-
- 20: – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Not applicable.
G11BBF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
The tables created by G11BBF and stored in
TABLE and
ICOUNT 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 the
th cell given by:
where
, for
and
.
The data, given by
John and Quenouille (1977), is for a
factorial experiment in
blocks of
units. The data is input in the order, blocks, factor with
levels, factor with
levels, yield, and the
table of treatment medians for yield over blocks is computed and printed.