Wilcoxon Signed Rank Test Results: Variations in p-values and z-values Compared to SPSS
11 views (last 30 days)
Show older comments
Hi, I am using the signrank() function from the Matlab library.
1) To verify the p-value, h and z-value. I have compared the results with the Wilcoxon signed rank test in SPSS. I found out that in some cases the Matlab p-value is different and z-value sometimes can't be found in Matlab. May I know what the reasons that lead to these differences? I have attached the result of SPSS for references and codes for three types of cases. Only the 3rd case get the similar p-value and z-value when compared to SPSS.
2) In addition, I found out that in case 1, the result of hypothesis test (h1) gets (0 in double mode)... isn't it should get in the logical mode?
3) Is there anything I should edit in the Matlab code to get more reliable answer?
Thanks in advance.
% Perform Wilcoxon Signed Rank Test
clear
clc
load Workspace_Data_WilcoxonSignedRank
% Compare dataset for Pair1 (1st Case)
[p1,h1,stats1] = signrank(Pair1_A,Pair1_B,'tail','both','alpha',0.05,'method','approximate')
% When I perform the wilcoxon signed Rank test to Pair 1, why does h1 get (0 in double mode?)
% supposely it should get in logical mode like Pair 2 and Pair 3.
% Is p1 is the correct value?
% Compare dataset for Pair2 (2nd Case)
[p2,h2,stats2] = signrank(Pair2_A,Pair2_B,'tail','both','alpha',0.05,'method','approximate')
% Correct compared to
% Compare dataset for Pair3 (3rd Case)
[p3,h3,stats3] = signrank(Pair3_A,Pair3_B,'tail','both','alpha',0.05,'method','approximate')
0 Comments
Answers (1)
Suraj Kumar
on 26 Sep 2024
Hi Wei,
Based on my understanding, you are facing issues in getting the z-value in MATLAB for some cases. To resolve this issue, you can refer the following steps:
The ‘zval’ is not generated in the first case as the values are all identical. Hence, this is a degenerate case of all ties.
Now to generate the ‘zval’ in such cases , we can create a default value for ‘zval’ and generate it like this:
[p1,h1,stats1] = signrank(Pair1_A,Pair1_B,'tail','both','alpha',0.05,'method','approximate') ;
if ~isfield(stats1, 'zval')
stats1.zval = nan;
end
[p,h,statsrnd1] = signrank(Pair1_A,Pair1_B+randn(size(Pair1_B)));
statsvector1 = [stats1;statsrnd1]
Additionally, the type of the hypothesis result being returned as double instead of logical is also due to the values being treated as ties.
‘signrank’ function uses a tolerance defined as ‘epsdiff = eps(x) + eps(y)’. It calculates the absolute differences and considers values with ‘abs(d(i)) < epsdiff’ as ties.
To know more about this, you can refer to the following documentation link:
Hope this answers your query!
0 Comments
See Also
Categories
Find more on Text Analytics Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!