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
|
Habitat |
Sex |
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:
|
Habitat |
Sex |
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:
– Integer
Input
-
On entry: the number of observations.
Constraint:
.
-
4:
– Integer
Input
-
On entry: the number of classifying factors in
ifac.
Constraint:
.
-
5:
– Integer array
Input
-
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 array
Input
-
On entry: the number of levels of the classifying factors in
ifac.
Constraint:
if , , for .
-
7:
– Integer array
Input
-
On entry: the
nfac coded classification factors for the
n observations.
Constraint:
, for and .
-
8:
– Integer
Input
-
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) array
Input
-
On entry: the variable to be tabulated.
-
11:
– Real (Kind=nag_wp) array
Input
-
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) array
Output
-
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:
– Integer
Input
-
On entry: the maximum size of the table to be computed.
Constraint:
product of the levels of the factors included in the tabulation.
-
14:
– Integer
Output
-
On exit: the number of cells in the table.
-
15:
– Integer
Output
-
On exit: the number of factors defining the table.
-
16:
– Integer array
Output
-
On exit: the first
ndim elements contain the number of levels for the factors defining the table.
-
17:
– Integer array
Output
-
On exit: a table containing the number of observations contributing to each cell of the table, stored identically to
table.
-
18:
– Integer array
Workspace
-
19:
– Real (Kind=nag_wp) array
Workspace
-
-
20:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended.
When the value or 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.