Wilcoxon Signed Rank Test

23 Aug, 2021
Prerequisites: Parametric and Non-Parametric Methods                         Hypothesis Testing 
Wilcoxon signed-rank test, also known as Wilcoxon matched pair test is a non-parametric hypothesis test that compares the median of two paired groups and tells if they are identically distributed or not. 
We can use this when:
Differences between the pairs of data are non-normally distributed.Independent pairs of data are identical. (or matched) Eg. (Math, English: Both subjects) ; (June, July: Both months) 
Steps involved:
Step 1 - Determine the null (h0) and alternate (ha) hypothesis. 
Step 2 - Find the difference (D) between the two columns. [D = B-A]
Step 3 - Find absolute difference (Abs-D). [Abs-D = |D|]
Step 4 - Assign ranks to Abs-D from lowest (1) to highest (n).
Assigning Ranks: 
If any two or more Abs-D values are same, then assign them consecutive ranks, then find the average of the ranks for each set of duplicate value. Consider the following scenario:
Case I - For Abs-D = 3 
       -> Assign them consecutive possible ranks. (3,4)
       -> Find average of 3,4 => (3+4)/2 = 3.5
       -> Assign the rank = 3.5 to both the 3's present in the table.             
Case II - For Abs-D = 4
        -> Assign them consecutive possible ranks. (5,6,7)
        -> Find average of 5,6,7 => (5+6+7)/3 = 6
        -> Assign the rank = 6 to all the 4's present in the table.
Step 5 - Find the sum of the ranks assigned to positive (T+) and negative (T-) Abs-D values. 
Step 6 - Find the Wilcoxon Rank. (Wcalc = minimum(T+,T-))  
Step 7 - Use the value of n and α and find Wtable in two-tailed section of 
      'Critical values of wilcoxon signed rank test'. 
     (take α = 0.05, if not given)
Step 8 - Interpretation of result.
NOTE : We use two-tailed test when we are dealing with two hypothesis. (null and alternate) 
Interpretation of result
When Wcalc < Wtable :
    -> Reject H0 (null hypothesis) 
     -> The two groups are not identically distributed.

When Wcalc > Wtable :
    -> Accept H0 (null hypothesis)
     -> The two groups are identically distributed.
Example Problem (Step by Step):
Consider the following example. The smog concentration data of 13 states of India were measured. Perform the Wilcoxon signed rank test and determine if there’s a significant difference in the concentrations recorded in May to that in December. [take α = 0.05]
States
Smog concentration in May(A)
Smog concentration in December(B)
Difference[D](B-A)
(Step-2)
Absolute Difference[Abs-D]
(Step-3)
Rank
 
(Step-4)
Delhi
13.3
11.1
-2.2
2.2
5
Mumbai
10.0
16.2
6.2
6.2
9
Chennai
16.5
15.3
-1.2
1.2
3
Kerala 
7.9
19.9
12.0
12.0
11
Karnataka
9.5
10.5
1.0
1.0
2
Tamil Nadu
8.3
15.5
7.2
7.2
10
Orissa
12.6
12.7
0.1
0.1
1
UP
8.9
14.2
5.3
5.3
7
MP
13.6
15.6
2.0
2.0
4
Rajasthan 
8.1
20.4
12.3
12.3
12
Gujarat
18.3
12.7
-5.6
5.6
8
West Bengal
8.1
11.2
3.1
3.1
6
Jammu 
13.4
36.8
23.4
23.4
13
n = 13
α = 0.05

Step 1 - h0 : Cmay = Cdecember (no change in the smog concentration)
     h1 : Cmay ≠ Cdecember (smog concentration changed)
Step 2,3,4 - Refer the table given above.
Step 5 - T+ marked as [ ] in table.  
     T- marked as [ ] in table.
∑T+ = 75
∑T- = 16
Step 6 - Wcalc = minimum(75,16) 
           = 16
Step 7 - Using n = 13 and α = 0.05 in table (click here)
     Wtable = 17
Step 8 - Wcalc < Wtable :
      Rejecting H0. 
     i.e smog concentration have changed from before.
Conclusion: 
Wilcoxon signed-rank test is a very common test in the fields of pharmaceuticals, especially amongst drug researchers, to find out the dominant symptoms of various drugs on humans. Being a non-parametric test, it works as an alternative to T-test which is parametric in nature. For any doubt/query, comment below.  
rs1686740
Machine Learning
Machine Learning
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Introduction to Recurrent Neural Network
Support Vector Machine Algorithm
ML | Monte Carlo Tree Search (MCTS)
Markov Decision Process
DBSCAN Clustering in ML | Density based clustering
Normalization vs Standardization
Bagging vs Boosting in Machine Learning
Principal Component Analysis with Python
Types of Environments in AI
Intuition of Adam Optimizer