<s>[INST] Finding the probability density function of the $n$th largest random variable. Let $X_1,...,X_{25}$ be independent Unif $[0,1]$ random variables. Let $Y$ be the $13$th largest of the $25$ random variables. Find the probability density function of $Y$.
I already know the answer for this one, but the answer that was provided just told me to use a formula to get the answer without much explanation as to why I should use that formula. This was the answer I was given:
Formula: $g(x_\gamma)=\frac{n!}{(\gamma-1)!(n-\gamma)!}[F(x)]^{\gamma-1}\cdot f(x)\cdot[1-F(x)]^{n-\gamma}$
Then since $X_1,X_2,\ldots,X_{25}\sim Unif[0,1]$, we have
$$
f(x)=
\begin{cases} 
1 & \text{if } 0\leq x\leq 1 \\
0 & \text{otherwise}
\end{cases}
$$
and
$$
F(x)=\int^x_01~dx=
\begin{cases}
0 & \text{if } x<0\\
x & \text{if } 0\leq x\leq 1\\
1 &\text{if } x>1
\end{cases}
$$
Then $Y=X_{(13)}$ so
$$f(y)=\frac{25!}{(13-1)!(25-13)!}(x)^{13-1}\cdot1\cdot(1-x)^{25-13}$$
$$={^{25}C_{13}}13(x)^{12}(1-x)^{12}$$
Thus, the p.d.f. is
$$
g(Y)=
\begin{cases}
{^{25}C_{13}}13(x)^{12}(1-x)^{12} & \text{if } 0\leq x\leq 1\\
0 & \text{otherwise}
\end{cases}
$$
Could I get an explanation of why I should use this formula or if there is another way to get the answer that is more clear? Thank you.
 [/INST] First note that the $13$-largest of $25$ is also the $13$-smallest, i.e. $13$th from the bottom:
$$
\begin{array}{rcccl}
& i & & 26-i \\
\hline
\text{smallest} \rightarrow & 1 & & 25 \\ \text{2nd-smallest} \rightarrow & 2 & & 24 \\ \text{3rd-smallest} \rightarrow & 3 & & 23 \\ & 4 & & 22 \\ & \vdots & & \vdots \\
& 11 & & 15 \\ & 12 & & 14 \\ \text{13th-smallest} \rightarrow & 13 & \longleftrightarrow & 13 & \leftarrow \text{13th-largest} \\ & 14 & & 12 \\ & 15 & & 11 \\
& \vdots & & \vdots \\ & 23 & & 3 & \leftarrow \text{3rd-largest} \\ & 24 & & 2 & \leftarrow \text{2nd-largest} \\ & 25 & & 1 & \leftarrow \text{largest}
\end{array}
$$
\begin{align}
F_Y(y) = {} & \Pr(Y\le y) \\[6pt]
= {} & \Pr(\text{13 or more observations are}\le y) \\[6pt]
= {} & \Pr\big({\ge 13 \text{ successes in 25 trials with}} \\
& \qquad\quad\text{probability $y$ of success on each trial} \big) \\[6pt]
= {} & \sum_{i=13}^{25} \binom {25} i y^i (1-y)^{25-i}. \\[6pt]
f_Y(y) = {} & \frac d {dy} F_Y(y) \\[6pt]
= {} & \sum_{i=13}^{25} \binom {25} i \Big( iy^{i-1} (1-y)^{25-i} - y^i(25-i)(1-y)^{25-i-1} \Big) \\[6pt]
= {} & \left( \sum_{j=12}^{24} \binom {25}{j+1} (j+1)y^j(1-y)^{25-j-1} \right. \\
& \quad \text{(where $j=i-1$ and $i= j+1$)} \\
& \left. {} - \sum_{i=13}^{25} \binom{25} i y^i(25-i)(1-y)^{25-i-1} \right) \\[10pt]
= {} & \sum_{j=12}^{24} \binom {25}{j+1} (j+1)y^j(1-y)^{25-j-1} \\
& {} - \sum_{i=13}^{25} \binom{25} {i+1} (i+1) y^i(1-y)^{25-i-1} \\[6pt]
& \qquad \text{(since $\displaystyle \binom{25} i (25-i) = \binom{25}{i+1}(i+1) $)}
\end{align}
And now the two sums cancel each other out except the term $j=12$ and the term $i=25.$ But the term $i=25$ is $0.$ Thus we have
$$
f_Y(y) = \binom{25}{13}13 y^{12} (1-y)^{12}.
$$
</s>