`quantile`

returns estimates of underlying distribution quantiles
based on one or two order statistics from the supplied elements in
`x`

at probabilities in `probs`

. One of the nine quantile
algorithms discussed in Hyndman and Fan (1996), selected by
`type`

, is employed.

All sample quantiles are defined as weighted averages of
consecutive order statistics. Sample quantiles of type \(i\)
are defined by:
$$Q_{i}(p) = (1 - \gamma)x_{j} + \gamma x_{j+1}$$
where \(1 \le i \le 9\),
\(\frac{j - m}{n} \le p < \frac{j - m + 1}{n}\),
\(x_{j}\) is the \(j\)th order statistic, \(n\) is the
sample size, the value of \(\gamma\) is a function of
\(j = \lfloor np + m\rfloor\) and \(g = np + m - j\),
and \(m\) is a constant determined by the sample quantile type.

**Discontinuous sample quantile types 1, 2, and 3**

For types 1, 2 and 3, \(Q_i(p)\) is a discontinuous
function of \(p\), with \(m = 0\) when \(i = 1\) and \(i =
2\), and \(m = -1/2\) when \(i = 3\).

- Type 1
Inverse of empirical distribution function.
\(\gamma = 0\) if \(g = 0\), and 1 otherwise.

- Type 2
Similar to type 1 but with averaging at discontinuities.
\(\gamma = 0.5\) if \(g = 0\), and 1 otherwise.

- Type 3
SAS definition: nearest even order statistic.
\(\gamma = 0\) if \(g = 0\) and \(j\) is even,
and 1 otherwise.

**Continuous sample quantile types 4 through 9**

For types 4 through 9, \(Q_i(p)\) is a continuous function
of \(p\), with \(\gamma = g\) and \(m\) given below. The
sample quantiles can be obtained equivalently by linear interpolation
between the points \((p_k,x_k)\) where \(x_k\)
is the \(k\)th order statistic. Specific expressions for
\(p_k\) are given below.

- Type 4
\(m = 0\). \(p_k = \frac{k}{n}\).
That is, linear interpolation of the empirical cdf.

- Type 5
\(m = 1/2\).
\(p_k = \frac{k - 0.5}{n}\).
That is a piecewise linear function where the knots are the values
midway through the steps of the empirical cdf. This is popular
amongst hydrologists.

- Type 6
\(m = p\). \(p_k = \frac{k}{n + 1}\).
Thus \(p_k = \mbox{E}[F(x_{k})]\).
This is used by Minitab and by SPSS.

- Type 7
\(m = 1-p\).
\(p_k = \frac{k - 1}{n - 1}\).
In this case, \(p_k = \mbox{mode}[F(x_{k})]\).
This is used by S.

- Type 8
\(m = (p+1)/3\).
\(p_k = \frac{k - 1/3}{n + 1/3}\).
Then \(p_k \approx \mbox{median}[F(x_{k})]\).
The resulting quantile estimates are approximately median-unbiased
regardless of the distribution of `x`

.

- Type 9
\(m = p/4 + 3/8\).
\(p_k = \frac{k - 3/8}{n + 1/4}\).
The resulting quantile estimates are approximately unbiased for
the expected order statistics if `x`

is normally distributed.

Further details are provided in Hyndman and Fan (1996) who recommended type 8.
The default method is type 7, as used by S and by R < 2.0.0.