Home > Article > Backend Development > How to perform Dunn's test in Python?
Dunn's test is a statistical technique for comparing the means of several samples. When it's required to compare the means of numerous samples to identify which ones are noticeably different from one another, Dunn's test is frequently employed in a range of disciplines, including biology, psychology, and education. We shall examine Dunn's test in−depth in this article, along with a python implementation.
Dunn's test is a statistical analysis method used to compare the means of multiple samples. It is a multiple comparison test method used to compare the means of more than two samples to determine which samples are significantly different from each other.
When the normality assumption is violated, Dunn's nonparametric Kruskal−Wallis test is sometimes used to compare the means of multiple samples. If there were significant differences between sample means, the Kruskal−Wallis test was used to find these differences. Make pairwise comparisons of sample means to determine which samples are significantly different from each other. Then use Dunn's test to compare the sample means.
To run Dunn's test in Python, we can use the posthoc dunn() method of the scikit-posthocs library.
The following code demonstrates how to use this function -
sp.posthoc_dunn(data, p_adjust = 'bonferroni')
Bartlett's test statistic and p-value are returned after this function receives a data array
p_adjust is a p value adjustment method
To demonstrate testing in Python, consider the following scenario: A researcher wishes to discover whether three different fertilizers cause different levels of plant growth. They randomly selected 30 different plants and divided them into three groups of ten plants, each using a different fertilizer. They measured the height of each plant at the end of a month.
Install scikit-posthocs library
Specify the growth data of 10 plants by group
Merge all 3 combinations into one data
Dunn's test for p-values using Bonferonni correction
Running Dunn's tests using the scikit-posthocs library is demonstrated here.
!pip install scikit-posthocs #specify the growth of the 10 plants in each group group1 = [9, 10, 16, 9, 10, 5, 7, 13, 10, 9] group2 = [16, 19, 15, 17, 19, 11, 6, 17, 11, 9] group3 = [7, 9, 5, 8, 8, 14, 11, 9, 14, 8] data = [group1, group2, group3] #perform Dunn's test using a Bonferonni correction for the p-values import scikit_posthocs as sp sp.posthoc_dunn(data, p_adjust = 'bonferroni')
The adjusted p-value for the distinction between groups 1 and 2 is 0.115458. The adjusted p-value for the distinction between groups 1 and 3 is 1.000000. The adjusted p-value for the distinction between groups 2 and 3 is 0.27465.
Dunn's test is widely used in many fields, including biology, psychology, and education, where it is necessary to compare the means of multiple samples to find whether there are significant differences between samples. It is particularly beneficial when the normality assumption is violated because it is a nonparametric test that does not rely on this assumption.
Dunn's test can be used in the field of education to compare the means of many sample data from different schools or classes to determine whether there are significant differences in the means of schools or classrooms. For example, you can use it to compare average test scores in different schools or average scores in different classrooms.
The above is the detailed content of How to perform Dunn's test in Python?. For more information, please follow other related articles on the PHP Chinese website!