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
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
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 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
. For the
, 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.
- 1: TYP – CHARACTER(1)Input
: 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.
- 2: WEIGHT – CHARACTER(1)Input
: 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.
- 3: N – INTEGERInput
On entry: the number of observations.
- 4: NFAC – INTEGERInput
: the number of classifying factors in IFAC
- 5: ISF(NFAC) – INTEGER arrayInput
: indicates which factors in IFAC
are to be used in the tabulation.
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: LFAC(NFAC) – INTEGER arrayInput
: the number of levels of the classifying factors in IFAC
if , , for .
- 7: IFAC(LDF,NFAC) – INTEGER arrayInput
: the NFAC
coded classification factors for the N
, for and .
- 8: LDF – INTEGERInput
: the first dimension of the array IFAC
as declared in the (sub)program from which G11BBF is called.
- 9: PERCNT – REAL (KIND=nag_wp)Input
On entry: , the percentile to be tabulated.
- 10: Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the variable to be tabulated.
- 11: WT() – REAL (KIND=nag_wp) arrayInput
the dimension of the array WT
must be at least
, and at least
must contain the N
weights. Otherwise WT
is not referenced.
if , , for .
- 12: TABLE(MAXT) – REAL (KIND=nag_wp) arrayOutput
: 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
changes faster. For further details see Section 8
- 13: MAXT – INTEGERInput
On entry: the maximum size of the table to be computed.
product of the levels of the factors included in the tabulation.
- 14: NCELLS – INTEGEROutput
On exit: the number of cells in the table.
- 15: NDIM – INTEGEROutput
On exit: the number of factors defining the table.
- 16: IDIM(NFAC) – INTEGER arrayOutput
: the first NDIM
elements contain the number of levels for the factors defining the table.
- 17: ICOUNT(MAXT) – INTEGER arrayOutput
: a table containing the number of observations contributing to each cell of the table, stored identically to TABLE
- 18: IWK() – INTEGER arrayWorkspace
- 19: WK() – REAL (KIND=nag_wp) arrayWorkspace
- 20: IFAIL – INTEGERInput/Output
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.
unless the routine detects an error or a warning has been flagged (see Section 6
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
The tables created by G11BBF and stored in TABLE
are stored in the following way. Let there be
factors defining the table with factor
levels, then the cell defined by the levels
of the factors is stored in the
th cell given by:
The data, given by John and Quenouille (1977)
, is for a
factorial experiment in
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.