Python-113 Mann-Whitney U Test(W

2021-07-06  本文已影响0人  RashidinAbdu
Whitney U Test(Wilcoxon rank-sum test) in Python

Here are some examples of when you might use a Mann-Whitney U test:


image.png

or :

group1 = [20, 23, 21, 25, 18, 17, 18, 24, 20, 24, 23, 19]
group2 = [24, 25, 21, 22, 23, 18, 17, 28, 24, 27, 21, 23]

#A Mann-Whitney U test (sometimes called the Wilcoxon rank-sum test) is
# used to compare the differences between two samples when the sample distributions
# are not normally distributed and the sample sizes are small (n <30).
# It is considered to be the nonparametric equivalent to the two sample t-test.

#pip install scipy
#pip install openpyxl
import pandas as pd
import numpy as np

# read the data from excel
group1 = np.array(pd.read_excel('C:/Users/Mr.R/Desktop/excels/zm.xlsx', sheet_name='1', usecols='C'))
group2 = np.array(pd.read_excel('C:/Users/Mr.R/Desktop/excels/zm.xlsx', sheet_name='1', usecols='D'))
print(group1, group2)

#First, we’ll create two arrays to hold the mpg values for each group of cars:
# group1 = [20, 23, 21, 25, 18, 17, 18, 24, 20, 24, 23, 19]
# group2 = [24, 25, 21, 22, 23, 18, 17, 28, 24, 27, 21, 23]

import scipy.stats as stats
#perform the Mann-Whitney U test

Mann_Whitney_U_test = stats.mannwhitneyu(group1, group2, alternative='two-sided')

print("\n Mann_Whitney_U_test :\n", Mann_Whitney_U_test)
# Step 3: Interpret the results.
# In this example, the Mann-Whitney U Test uses the following null and alternative hypotheses:
# H0: The mpg is equal between the two groups
# HA: The mpg is not equal between the two groups

# if the p-value is not less than 0.05,
# we fail to reject the null hypothesis.
# We do not have sufficient evidence to say that the true mean mpg is different between the two groups.

image.png

In this example, the Mann-Whitney U Test uses the following null and alternative hypotheses:


上一篇下一篇

猜你喜欢

热点阅读