0
0
SciPydata~20 mins

Mann-Whitney U test in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Mann-Whitney U Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Mann-Whitney U test on two small samples
What is the output of the Mann-Whitney U test for the following two samples using scipy.stats.mannwhitneyu with default parameters?
SciPy
from scipy.stats import mannwhitneyu
sample1 = [1, 3, 5]
sample2 = [2, 4, 6]
result = mannwhitneyu(sample1, sample2)
print((result.statistic, round(result.pvalue, 4)))
A(4.0, 0.5)
B(3.0, 1.0)
C(4.0, 1.0)
D(3.0, 0.5)
Attempts:
2 left
💡 Hint
Remember that the Mann-Whitney U statistic counts how many times values in one sample exceed values in the other.
data_output
intermediate
1:00remaining
Number of items in the output of mannwhitneyu
How many values are returned by scipy.stats.mannwhitneyu when called on two samples?
SciPy
from scipy.stats import mannwhitneyu
sample1 = [10, 20, 30]
sample2 = [15, 25, 35]
result = mannwhitneyu(sample1, sample2)
print(len(result))
A2
B4
C3
D1
Attempts:
2 left
💡 Hint
Check the type of the result and what attributes it has.
🔧 Debug
advanced
1:30remaining
Identify the error in this Mann-Whitney U test code
What error does the following code raise when run?
SciPy
from scipy.stats import mannwhitneyu
sample1 = [1, 2, 3]
sample2 = [4, 5]
result = mannwhitneyu(sample1, sample2, alternative='greater')
print(result.statistic, result.pvalue)
AValueError: alternative must be 'two-sided', 'less' or 'greater'
BNo error, prints the statistic and p-value
CTypeError: mannwhitneyu() got an unexpected keyword argument 'alternative'
DIndexError: list index out of range
Attempts:
2 left
💡 Hint
Check the scipy.stats.mannwhitneyu documentation for valid parameters.
🧠 Conceptual
advanced
1:30remaining
Interpretation of Mann-Whitney U test p-value
If the Mann-Whitney U test returns a p-value of 0.03 for two independent samples, what does this mean?
AThe samples have exactly the same median values.
BThere is no evidence to reject the null hypothesis that the two samples come from the same distribution.
CThere is strong evidence that the two samples come from populations with different distributions.
DThe test is invalid because p-value must be greater than 0.05.
Attempts:
2 left
💡 Hint
Recall that a p-value below 0.05 usually means rejecting the null hypothesis.
🚀 Application
expert
2:00remaining
Choosing the correct Mann-Whitney U test alternative hypothesis
You want to test if sample A tends to have larger values than sample B. Which 'alternative' parameter should you use in scipy.stats.mannwhitneyu?
A'greater'
B'less'
C'two-sided'
D'equal'
Attempts:
2 left
💡 Hint
Think about the direction of the hypothesis you want to test.