# It's Never Obvious: About Percentiles

### It is important to pay attention to the definition of percentile being used – be it when drafting contracts for SLAs or comparative performance analysis and optimization.

Join the DZone community and get the full member experience.

Join For Freein an earlier blog , the evolution of performance metrics – for example, from load time to above the fold to speed index – was discussed. as much as this evolution is warranted in the wake of the dynamic application landscape and changing user expectations, the phenomenon also contributes to the metrics overload (discussed previously here ). this makes systematic, automatic and robust data analysis paramount. detecting sudden change (or trend shift ) or detecting outages are example steps to this end.

some of the common statistics used for data analysis are: arithmetic mean, median, geometric mean and standard deviation. the proper use of the above is discussed
here
. it is pretty common in the ops world to monitor multiple percentiles of a given metric. for instance, the 95
^{
th
}
percentile (commonly referred to as 95p) of document complete is monitored. in addition, 99p (also referred to as two nines) and 99.9p (also referred to as three nines) of document complete are also monitored. in practice, monitoring the aforementioned percentiles corresponds to catering the experience of the users in the right tail. the lower and stable the value of, say, 99p, is, then the higher the overall customer satisfaction will be.

given a time series
*
x
*
with
*
n
*
<timestamp, value> pairs, the 50
^{
th
}
percentile (or the median) is computed via the following steps:

- sort the values in increasing order.
- if n is odd, return the middle value.

if n is even, return the mean of the (n-1)/2-th and (n+1)/2-th values.

in general, given a random variable
*
x
*
, the
*
k
*
-th
*
q
*
-quantile x satisfies the following example.

in practice, for a time series obtained from production, the cumulative distribution function and quantile function of the underlying population is not known. for such cases, one can leverage any one of the several techniques that have been proposed for quantile estimation (see [3]). let,

*
n
*
= sample size

q
_{
p
}
= estimate of the
*
k
*
-th
*
q
*
-quantile

the methods proposed for estimating q
_{
p
}
compute a real-valued index,
*
h
*
. the
*
h
*
-th smallest value of
*
x
*
, denoted by
*
x
_{
h
}
*
, is the quantile estimate if

*h*is an integer; else, the nearest rank or interpolation is commonly used to compute the quantile estimate. for instance, the default method used by the r function quantile uses interpolation and defines

*h*and q

_{ p as }follows:

for the same definition of q
_{
p
}
as above, in [3], hyndman and fan recommend to use the following definition of h (this corresponds to type=8 as an argument to the function quantile in r):

the boundary conditions are handled in the following fashion:

as per
reiss
, the sample quantile mentioned above is optimal in the class of all the estimators that are median unbiased o
*
(n
^{
-1/2
}
)
*
and equivariant under translations (note that shifting the observations, results in the shifting of the distribution of q

_{ p }). also, the aforementioned sample quantile is not sensitive to the distribution of

*x*– this is particularly important as the underlying distribution of production ops data is seldom normal.

let’s consider the following plot chart corresponds to document complete of eight different brokerages in the us. the plot chart below shows a week-long snapshot of document complete, with samples taken every 5 minutes (the data was extracted via the catchpoint portal).

comparative visual analysis of the plot above is not feasible. one could potentially downsample [4], however, one would lose information in the process. in the wake of high-volume and high-velocity data, an algorithmic analysis is no longer nice to have.

the table above lists the mean value of document complete for each time series shown in the plot chart above. however, as it is well known, mean is susceptible to the presence of anomalies (which are indeed present in the plot above). robust measures such as, but not limited to, trimmed mean, median or broadened median, are commonly used. the latter, i.e., broadened median, preserves the resistance of the median with respect to anomalies while also achieving sensitivity to the rounding and grouping of the values. the reader is referred to [1, 2] for further reading about robust measures.

the plot below shows the probability density distribution of the time series shown in the first plot chart.

from the graph above, we note that the distribution of none of the time series follows a normal distribution. this limits the use of certain quantile estimates, e.g., the method corresponding to argument type=8 in the r function quantile.

the table below lists the 50p, 95p, and 99p estimates corresponding to argument type=7 in the r function quantile. from the table, we note that, for instance, although 50p and 95p of etrade are much higher than that of fidelity, 99p of etrade is much higher than that of fidelity. thus, percentiles do not necessarily follow a monotonic trend as exemplified by tdamertitrade and tradeking.

the table below lists the 50p, 95p, and 99p estimates corresponding to argument type=8 in the r function quantile. on comparative analysis of the tables above and below we note that the column corresponding to 50p is the same. however, the columns corresponding to 95p and 99p have different values. this has direct ramifications on multiple fronts. one of these corresponds to how sla agreements are put together (as discussed earlier here , breach of slas can have financial implications of the order of millions). thus, it is important to be very specific about how quantile estimates should be computed.

we also note that the relative ordering of the brokerages does not change for 50p/95/99p between the two tables. however, from the table below we note that the ordering of 99.9p of etrade relative to scottrade and tdamertitrade changed when transitioning from type=7 to type=8.

this demonstrates the impact of the selection of a statistical method on comparative percentile analysis of ops data. this, in turn, can potentially have direct implications on investment of resources towards optimization.

if a reader is interested in learning more about quantile functions, he/she is referred to the evaluation paper by schoojans et al. [5] and the book by gilchrist [6]. in the former, the authors stress the importance of reporting percentiles with their 95% confidence interval, especially in the case of small samples.

to summarize, it is important to pay attention to the definition of percentile being used – be it when drafting contracts for slas or comparative performance analysis and optimization. based on the literature, it is recommended to use the method corresponding to type=8 in r.

**
resources
**

[1] “
*
understanding robust and exploratory data analysis
*
,” by d. c. hoaglin, f. mosteller and j. w. tukey.

[2] “
*
robust statistics
*
,” by p. j. huber and elvezio m. ronchetti.

[3] “
*
sample quantiles in statistical packages
*
,” by r. j. hyndman and y. fan. in
*
american statistician
*
**
50
**
, 361–365, 1996.

[4] “
*
sampling techniques
*
,” w. g. cochran.

[5] “
*
estimation of population percentiles
*
,” by f. schoonjans, d. de bacquer and p. schmid. in epidemiology, 22(5): 750–751, 2011.

Published at DZone with permission of Mehdi Daoudi, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Comments