Repository: scipy/scipy
File: scipy/stats/_distribution_infrastructure.py (Python)

Code before:
    r"""Probability distribution of an order statistic.

    An instance of this class represents a random variable that follows the
    distribution of the :math:`r^{\text{th}}` order statistic of a
    sample of :math:`n` observations of a random variable :math:`X`.

    Parameters
    ----------
    dist : `ContinuousDistribution`
        The random variable :math:`X`.
    n : array_like
        The (positive integer) sample size :math:`n`.
    r : array_like
        The (positive integer) rank of the order statistic :math:`r`,
        satisfying ``1 <= r <= n``.


    Notes
    -----
    If we make :math:`n` observations of a continuous random variable
    :math:`X` and sort them in increasing order
    :math:`X_{(1)}, \dots, X_{(r)}, \dots, X_{(n)}`,
    :math:`X_{(r)}` is known as the :math:`r^{\text{th}}` order statistic.

    If the PDF, CDF, and CCDF of :math:`X` are denoted by :math:`f`,
    :math:`F`, and :math:`\\bar F = 1 - F`, respectively, then the PDF of
    :math:`X_{(r)}` is given by:

    .. math::

        f_r(x) = \frac{n!}{(r-1)! (n-r)!} f(x) F(x)^{r-1} \\bar F(x)^{n - r}

    The CDF and other methods of the distribution of :math:`X_{(r)}`
    are calculated using the fact that :math:`X = F^{-1}(U)`, where
    :math:`U \\sim \\mathrm{Uniform}(0, 1)`, together with the fact that the order
    statistics of i.i.d. uniform random variables follow a beta distribution,
    :math:`\\mathrm{Beta}(r, n - r + 1)`.

    References
    ----------
    .. [1] Order statistic. *Wikipedia*. https://en.wikipedia.org/wiki/Order_statistic

    Examples
    --------
    Suppose we are interested in order statistics of samples of size five drawn
    from the standard normal distribution. Plot the PDF of the fourth
    order statistic and compare with a normalized histogram from simulation.

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy import stats

Review comment (suggestion):
This is not rendering properly.
<img width="716" height="384" alt="image" src="https://github.com/user-attachments/assets/46e35f93-d938-47cd-a107-042fe969ba3c" />

Maybe because the docstring is already a raw string.

In any case, let's use $G$ instead of $\bar{F}$, since that's what we use for the CCDF in related documentation.

Code after:
    r"""Probability distribution of an order statistic.

    An instance of this class represents a random variable that follows the
    distribution of the :math:`r^{\text{th}}` order statistic of a
    sample of :math:`n` observations of a random variable :math:`X`.

    Parameters
    ----------
    dist : `ContinuousDistribution`
        The random variable :math:`X`.
    n : array_like
        The (positive integer) sample size :math:`n`.
    r : array_like
        The (positive integer) rank of the order statistic :math:`r`,
        satisfying :math:`1 \leq r \leq n`.


    Notes
    -----
    If we make :math:`n` observations of a continuous random variable
    :math:`X` and sort them in increasing order
    :math:`X_{(1)}, \dots, X_{(r)}, \dots, X_{(n)}`, then :math:`X_{(r)}`
    is known as the :math:`r^{\text{th}}` order statistic.

    If the PDF, CDF, and CCDF of :math:`X` are denoted by :math:`f`,
    :math:`F`, and :math:`G = 1 - F`, respectively, then the PDF of
    :math:`X_{(r)}` is given by:

    .. math::

        f_r(x) = \frac{n!}{(r-1)! (n-r)!} f(x) F(x)^{r-1} G(x)^{n - r}

    The CDF and other methods of the distribution of :math:`X_{(r)}`
    are calculated using the fact that :math:`X = F^{-1}(U)`, where :math:`U` is a
    standard uniform random variable, together with the fact that the order statistics
    of i.i.d. uniform random variables follow a beta distribution
    :math:`B(r, n - r + 1)`.

    References
    ----------
    .. [1] Order statistic. *Wikipedia*. https://en.wikipedia.org/wiki/Order_statistic

    Examples
    --------
    Suppose we are interested in order statistics of samples of size five drawn
    from the standard normal distribution. Plot the PDF of the fourth
    order statistic and compare with a normalized histogram from simulation.

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy import stats