Hướng dẫn wilcoxon test python
Calculate the Wilcoxon signed-rank test. The
Wilcoxon signed-rank test tests the null hypothesis that two related paired samples come from the same distribution. In particular, it tests whether the distribution of the differences Either the first set of measurements (in which case Either the second set of measurements (if There are different conventions for handling pairs of observations with equal values (“zero-differences”, or “zeros”).
If True, apply continuity correction by adjusting the Wilcoxon rank statistic by 0.5 towards the mean value when computing the z-statistic if a normal approximation is used. Default is False. alternative{“two-sided”, “greater”, “less”}, optionalDefines the alternative hypothesis. Default is ‘two-sided’. In the following, let
Method to calculate the p-value, see Notes. Default is “auto”. axisint 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 Defines how to handle input NaNs.
If 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. ReturnsAn object with the following attributes.statisticarray_likeIf alternative is “two-sided”, the sum of the ranks of the differences above or below zero, whichever is smaller. Otherwise the sum of the ranks of the differences above zero. pvaluearray_likeThe p-value for the test depending on alternative and method. zstatisticarray_likeWhen where Notes In the following, let
The presence of “ties” (i.e. not all elements of
Beginning in SciPy 1.9, References 1https://en.wikipedia.org/wiki/Wilcoxon_signed-rank_test 2Conover, W.J., Practical Nonparametric Statistics, 1971. 3Pratt, J.W., Remarks on Zeros and Ties in the Wilcoxon Signed Rank Procedures, Journal of the American Statistical Association, Vol. 54, 1959, pp. 655-667. DOI:10.1080/01621459.1959.10501526 4(1,2)Wilcoxon, F., Individual Comparisons by Ranking Methods, Biometrics Bulletin, Vol. 1, 1945, pp. 80-83. DOI:10.2307/3001968 Cureton, E.E., The Normal Approximation to the Signed-Rank Sampling Distribution When Zero Differences are Present, Journal of the American Statistical Association, Vol. 62, 1967, pp. 1068-1069. DOI:10.1080/01621459.1967.10500917 Examples In [4], the differences in height between cross- and self-fertilized corn plants is given as follows: >>> d = [6, 8, 14, 16, 23, 24, 28, 29, 41, -48, 49, 56, 60, -67, 75] Cross-fertilized plants appear to be be higher. To test the null hypothesis that there is no height difference, we can apply the two-sided test: >>> from scipy.stats import wilcoxon >>> res = wilcoxon(d) >>> res.statistic, res.pvalue (24.0, 0.041259765625) Hence, we would reject the null hypothesis at a confidence level of 5%, concluding that there is a difference in height between the groups. To confirm that the median of the differences can be assumed to be positive, we use: >>> res = wilcoxon(d, alternative='greater') >>> res.statistic, res.pvalue (96.0, 0.0206298828125) This shows that the null hypothesis that the median is negative can be rejected at a confidence level of 5% in favor of the alternative that the median is greater than zero. The p-values above are exact. Using the normal approximation gives very similar values: >>> res = wilcoxon(d, method='approx') >>> res.statistic, res.pvalue (24.0, 0.04088813291185591) Note that the statistic changed to 96 in the one-sided case (the sum of ranks of positive differences) whereas it is 24 in the two-sided case (the minimum of sum of ranks above and below zero). |