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 argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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.
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.