Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract the p-value from the scipy result

Tags:

python

scipy

I have the following code to run Wilcoxon rank-sum test

print stats.ranksums(pre_course_scores, during_course_scores)

RanksumsResult(statistic=8.1341352369246582, pvalue=4.1488919597127145e-16)

However, I am interested in extracting the pvalue from the result. I could not find a tutorial about this. Can someone help?

like image 492
renakre Avatar asked Jan 05 '23 17:01

renakre


1 Answers

Use the pvalue attribute of the returning object:

import scipy.stats as ss
result = ss.ranksums(np.random.randn(10), np.random.randn(10)) 
result.pvalue
Out: 0.44969179796889092

I assigned it to a variable but you can directly use stats.ranksums(pre_course_scores, during_course_scores).pvalue.

like image 116
ayhan Avatar answered Jan 07 '23 08:01

ayhan