Sample quantile (source code)

= Sample quantile
{title2=$\widehat F_n^{-1}(p)=X_{(\lceil np\rceil)}$}

= Empirical quantile
{synonym}

For observations $X_1,\ldots,X_n$ and $0<p<1$, the <sample quantile> in the generalized-inverse convention is
$$
\widehat q_p=\inf\{x:\widehat F_n(x)\geq p\}=X_{(\lceil np\rceil)},
$$
where $\widehat F_n$ is the empirical <cumulative distribution function>[distribution function] and the observations are ordered with ties retained. For five observations, the <sample median> in this convention is the third <order statistic>. <linear interpolation>[Interpolated] <sample quantile>[sample-quantile] conventions can give different finite-sample answers.

For the asymptotic statement, assume the observations are <independent and identically distributed> with <cumulative distribution function> $F$. Let $q_p=F^{-1}(p)$ be its unique $p$-quantile, and suppose $F$ has a <probability density function>[density] $f$ continuous and strictly positive at $q_p$. Then
$$
\sqrt n(\widehat q_p-q_p)\ \Longrightarrow
N\left(0,\frac{p(1-p)}{f(q_p)^2}\right).
$$
For a proof, $\{\widehat q_p\leq x\}$ is exactly the <event> that at least $\lceil np\rceil$ observations are at most $x$. At $x=q_p+t/\sqrt n$, the count is binomial with success <probability> $F(x)=p+f(q_p)t/\sqrt n+o(n^{-1/2})$. The <central limit theorem>[binomial central limit theorem] gives the displayed normal limit. A larger <probability density function>[density] at the target <quantile> makes the <quantile> more precisely estimated. The <independence> and local-density hypotheses are needed; the formula cannot be applied unchanged to arbitrary dependent observations or an <atom of a measure>[atom].