Search code examples
pythonconfidence-intervalscipy.stats

Is there support for computing confidence intervals for Wilcoxon Test in Python?


Introduction/Summary of Problem I'm working on a project with an intention of computing one-sample confidence intervals about the mean for several variables of interest in my dataset. After performing qualitative and quantitative approaches to assessing normality, I believe that the analyses can benefit from using both parametric and non-parametric hypothesis testing methods. However, I have been unable to locate Python routines that compute the confidence interval about the mean for a Wilcoxon Test.

Efforts to Identify Solutions Now, with regards to implementation of hypothesis testing methods in Python, I have identified the following:

scipy.stats.ttest_1samp().confidence interval(confidence_level=arg)

which performs an independent t-test and returns the test statistic, p-value, and bounds of the confidence interval for a specified confidence level. With respect to the non-parametric Wilcoxon Test, there are near identical methods for performing the test provided by scipy.stats and pingouin that are scipy.stats.wilcoxon/ scipy.stats.mannwhitneyu and pingouin.wilcoxon/pingouin.mwu, respectively. However, none of these methods appear to offer support for computing confidence intervals. I've also searched both Stackoverflow and Stack Exchange thoroughly and have not been able to come across any submissions with solutions on this concern.

I'm aware of the formula for a one-sample confidence interval about a population mean. However, I have not been able to locate a Python routine or a formula for computing the critical value (with df = n - 1) for a Wilcoxon Test in Python given a specific level of confidence and given the tailed condition of the test.

Conclusion Therefore, I'm inquiring about whether Python offers support for computing confidence intervals about the mean for a Wilcoxon Test and the formula for computing the critical value of a Wilcoxon Test statistic that would permit me to compute the confidence interval manually.

Brief disclaimer: The author imported their submission from a LaTEX editor in Overleaf, so the submission was only contained within the image attachment. The text above was extracted from that image.

enter image description here


Solution

  • Another option for computing a CI about the median which is nonparametric but avoids bootstrapping is scipy.stats.quantile_test.

    import numpy as np
    from scipy import stats
    rng = np.random.default_rng(39891409235034)
    dist = stats.levy()
    x = dist.rvs(size=100)
    res = stats.quantile_test(x, p=0.5)
    res.confidence_interval()
    # ConfidenceInterval(low=1.3013651046612258, high=3.5638397384022906)
    

    I have no other suggestions for "computing a CI about a population mean using a nonparametric approach" other than using bootstrap, which can of course be used for the mean instead of the median.