bundles / scipy 1.17.1 / scipy / stats / _hypotests / cramervonmises_2samp
function
scipy.stats._hypotests:cramervonmises_2samp
source: /scipy/stats/_hypotests.py :1633
Signature
def cramervonmises_2samp ( x , y , method = auto , * , axis = 0 , nan_policy = propagate , keepdims = False ) Summary
Perform the two-sample Cramér-von Mises test for goodness of fit.
Extended Summary
This is the two-sample version of the Cramér-von Mises test ([1]): for two independent samples and , the null hypothesis is that the samples come from the same (unspecified) continuous distribution.
The test statistic is defined as in [1]:
where is defined as below, and is the Cramér-von Mises criterion. The function here denotes the rank of the observed values and within the pooled sample of size , with ties assigned mid-rank values:
Parameters
x: array_likeA 1-D array of observed values of the random variables . Must contain at least two observations.
y: array_likeA 1-D array of observed values of the random variables . Must contain at least two observations.
method: {'auto', 'asymptotic', 'exact'}, optionalThe method used to compute the p-value, see Notes for details. The default is 'auto'.
axis: int or None, default: 0If an int, the axis 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.nan_policy: {'propagate', 'omit', 'raise'}Defines how to handle input NaNs.
propagate: if a NaN is present in the axis slice (e.g. row) along which the statistic is computed, the corresponding entry of the output will be NaN.omit: NaNs will be omitted when performing the calculation. If insufficient data remains in the axis slice along which the statistic is computed, the corresponding entry of the output will be NaN.raise: if a NaN is present, aValueErrorwill be raised.
keepdims: bool, default: FalseIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
Returns
res: object with attributesstatistic
statistic
pvalue
pvalue
Notes
The statistic is computed according to equation 9 in [2]. The calculation of the p-value depends on the keyword method:
asymptotic: The p-value is approximated by using the limiting distribution of the test statistic.exact: The exact p-value is computed by enumerating all possible combinations of the test statistic, see [2].
If method='auto', the exact approach is used if both samples contain equal to or less than 20 observations, otherwise the asymptotic distribution is used.
If the underlying distribution is not continuous, the p-value is likely to be conservative (Section 6.2 in [3]). When ranking the data to compute the test statistic, midranks are used if there are ties.
Beginning in SciPy 1.9, np.matrix inputs (not recommended for new code) are converted to np.ndarray before the calculation is performed. In this case, the output will be a scalar or np.ndarray of appropriate shape rather than a 2D np.matrix. Similarly, while masked elements of masked arrays are ignored, the output will be a scalar or np.ndarray rather than a masked array with mask=False.
Array API Standard Support
cramervonmises_2samp has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ⛔ PyTorch ✅ ⛔ JAX ⚠️ no JIT ⛔ Dask ⛔ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
Suppose we wish to test whether two samples generated by ``scipy.stats.norm.rvs`` have the same distribution. We choose a significance level of alpha=0.05.import numpy as np from scipy import stats rng = np.random.default_rng() x = stats.norm.rvs(size=100, random_state=rng) y = stats.norm.rvs(size=70, random_state=rng) res = stats.cramervonmises_2samp(x, y)✓
res.statistic, res.pvalue
✗x = stats.norm.rvs(size=7, random_state=rng) y = stats.t.rvs(df=2, size=6, random_state=rng) res = stats.cramervonmises_2samp(x, y, method='exact')✓
res.statistic, res.pvalue
✗res = stats.cramervonmises_2samp(x, y, method='asymptotic')
✓res.statistic, res.pvalue
✗See also
- anderson_ksamp
- cramervonmises
- epps_singleton_2samp
- ks_2samp
Aliases
-
scipy.stats.cramervonmises_2samp