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

Code before:
    return y[()] if y.ndim == 0 else y


def _cvm_result_to_tuple(res, _):
    return res.statistic, res.pvalue


@xp_capabilities(cpu_only=True,  # needs special function `kv`
                 skip_backends=[('dask.array', 'typical dask issues')], jax_jit=False)
@_axis_nan_policy_factory(CramerVonMisesResult, n_samples=1, too_small=1,
                          result_to_tuple=_cvm_result_to_tuple)
def cramervonmises(rvs, cdf, args=(), *, axis=0):
    r"""Perform the one-sample Cramér-von Mises test for goodness of fit.

    This performs a test of the goodness of fit of a cumulative distribution
    function (cdf) :math:`F` compared to the empirical distribution function
    :math:`F_n` of observed random variates :math:`X_1, ..., X_n` that are
    assumed to be independent and identically distributed ([1]_).
    The null hypothesis is that the :math:`X_i` have cumulative distribution
    :math:`F`.

    The test statistic :math:`T` is defined as:

    .. math::
        T = n\omega^2 =
        \frac{1}{12n} + \sum_{i=1}^n \left[ \frac{2i-1}{2n} - F(x_i) \right]^2

    Parameters
    ----------
    rvs : array_like
        A 1-D array of observed values of the random variables :math:`X_i`.
        The sample must contain at least two observations.
    cdf : str or callable
        The cumulative distribution function :math:`F` to test the
        observations against. If a string, it should be the name of a
        distribution in `scipy.stats`. If a callable, that callable is used
        to calculate the cdf: ``cdf(x, *args) -> float``.
    args : tuple, optional
        Distribution parameters. These are assumed to be known; see Notes.
    axis : int or tuple of ints, default: 0
        If an int or tuple of ints, the axis or axes of the input along which
        to compute the statistic. The statistic of each axis-slice (e.g. row)
        of the input will appear in a corresponding element of the output.
        If ``None``, the input will be raveled before computing the statistic.

    Returns
    -------
    res : object with attributes
        statistic : float
            Cramér-von Mises statistic :math:`T`.
        pvalue : float

Review comment (suggestion):
One could say that $\omega$ and $x_i$ are undefined.

Code after:


def _cvm_result_to_tuple(res, _):
    return res.statistic, res.pvalue


@xp_capabilities(cpu_only=True,  # needs special function `kv`
                 skip_backends=[('dask.array', 'typical dask issues')], jax_jit=False)
@_axis_nan_policy_factory(CramerVonMisesResult, n_samples=1, too_small=1,
                          result_to_tuple=_cvm_result_to_tuple)
def cramervonmises(rvs, cdf, args=(), *, axis=0):
    r"""Perform the one-sample Cramér-von Mises test for goodness of fit.

    This performs a test of the goodness of fit of a cumulative distribution
    function (cdf) :math:`F` compared to the empirical distribution function
    :math:`F_n` of observed random variates :math:`X_1, ..., X_n` that are
    assumed to be independent and identically distributed ([1]_).
    The null hypothesis is that the :math:`X_i` have cumulative distribution
    :math:`F`.

    The test statistic :math:`T` is defined as in [1]_, where :math:`\omega^2`
    is the Cramér-von Mises criterion and :math:`x_i` are the observed values.

    .. math::
        T = n\omega^2 =
        \frac{1}{12n} + \sum_{i=1}^n \left[ \frac{2i-1}{2n} - F(x_i) \right]^2

    Parameters
    ----------
    rvs : array_like
        A 1-D array of observed values of the random variables :math:`X_i`.
        The sample must contain at least two observations.
    cdf : str or callable
        The cumulative distribution function :math:`F` to test the
        observations against. If a string, it should be the name of a
        distribution in `scipy.stats`. If a callable, that callable is used
        to calculate the cdf: ``cdf(x, *args) -> float``.
    args : tuple, optional
        Distribution parameters. These are assumed to be known; see Notes.
    axis : int or tuple of ints, default: 0
        If an int or tuple of ints, the axis or axes of the input along which
        to compute the statistic. The statistic of each axis-slice (e.g. row)
        of the input will appear in a corresponding element of the output.
        If ``None``, the input will be raveled before computing the statistic.

    Returns
    -------
    res : object with attributes
        statistic : float
            Cramér-von Mises statistic :math:`T`.
        pvalue : float