naginterfaces.library.contab.tabulate_percentile¶
- naginterfaces.library.contab.tabulate_percentile(typ, isf, lfac, ifac, percnt, y, maxt, wt=None)[source]¶
tabulate_percentile
computes a table from a set of classification factors using a given percentile or quantile, for example the median.For full information please refer to the NAG Library document for g11bb
https://support.nag.com/numeric/nl/nagdoc_30.2/flhtml/g11/g11bbf.html
- Parameters
- typstr, length 1
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.
- isfint, array-like, shape
Indicates which factors in are to be used in the tabulation.
If the th factor in is included in the tabulation.
Note that if , for then the statistic for the whole sample is calculated and returned in a table.
- lfacint, array-like, shape
The number of levels of the classifying factors in .
- ifacint, array-like, shape
The coded classification factors for the observations.
- percntfloat
, the percentile to be tabulated.
- yfloat, array-like, shape
The variable to be tabulated.
- maxtint
The maximum size of the table to be computed.
- wtNone or float, array-like, shape , optional
If , must contain the weights. Otherwise is not referenced.
- Returns
- tablefloat, ndarray, shape
The computed table. The cells of the table are stored so that for any two factors the index relating to the factor occurring later in and changes faster. For further details see Further Comments.
- ncellsint
The number of cells in the table.
- ndimint
The number of factors defining the table.
- idimint, ndarray, shape
The first elements contain the number of levels for the factors defining the table.
- icountint, ndarray, shape
A table containing the number of observations contributing to each cell of the table, stored identically to .
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: or .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and minimum value for .
Constraint: of the levels of the factors included in the tabulation.
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, , , and .
Constraint: .
- (errno )
On entry, , and .
Constraint: .
- (errno )
On entry, and .
On entry, .
- (errno )
Some cells of the table are empty.
- Notes
In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.
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
[table omitted]
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:
[table omitted]
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 .
- References
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