what is the result of a stats.wilcoxon test?
- User
what is the result of a stats.wilcoxon test?
Assistant
The result of a scipy.stats.wilcoxon test is a WilcoxonResult object. This object contains the key metrics needed to interpret the test: the test statistic and the p-value.Here is a breakdown of what the result object contains and how to interpret it.1. The Output ObjectWhen you run the test:Pythonimport scipy.stats as stats result = stats.wilcoxon(x, y)
result is a WilcoxonResult object
You can access the values via attributes or by unpacking the result:result.statisticresult.pvalue2. Result XXX Statistic.statisticThis is the sum of the signed ranks. • Two-sided (default): It is the smaller of the two sums (sum of positive ranks vs. sum of negative ranks).• One-sided: It is the sum of the ranks of the differences that match the alternative hypothesis (e.g., greater or less).P-Value.pvalueThe probability of observing this test statistic (or one more extreme) if the null hypothesis were true.Export to Sheets(Note: In newer versions of SciPy, the result object may also contain a .zstatistic attribute if the normal approximation method was used).3. How to Interpret the ResultTo interpret the result, you compare the p-value to your chosen significance level (alpha), which is commonly set to 0.05.Null Hypothesis (H0)The Wilcoxon signed-rank test assumes that the distribution of the differences between the two paired samples is symmetric about zero. In simpler terms, it assumes there is no systematic difference (e.g., Median Difference = 0).Decision RuleIf p-value ≤ 0.05:Result: Statistically Significant.Conclusion: Reject the null hypothesis. There is strong evidence that the two samples are different (e.g., the treatment had an effect).If p-value > 0.05:Result: Not Statistically Significant.Conclusion: Fail to reject the null hypothesis. There is insufficient evidence to claim a difference between the groups; the observed differences could likely be due to random chance.ExampleIf you are testing a "Before vs. After" treatment and get the following result: WilcoxonResult(statistic=15.0, pvalue=0.034)Statistic (15.0): This is your calculated rank sum.P-value (0.034): Since 0.034<0.05, you reject the null hypothesis. You conclude there is a significant difference between the "Before" and "After" groups.