Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

scipy.stats.spearmanr

from scipy import stats
>>> stats.spearmanr([1,2,3,4,5], [5,6,7,8,7])
SpearmanrResult(correlation=0.82078..., pvalue=0.08858...)
>>> rng = np.random.default_rng()
>>> x2n = rng.standard_normal((100, 2))
>>> y2n = rng.standard_normal((100, 2))
>>> stats.spearmanr(x2n)
SpearmanrResult(correlation=-0.07960396039603959, pvalue=0.4311168705769747)
>>> stats.spearmanr(x2n[:,0], x2n[:,1])
SpearmanrResult(correlation=-0.07960396039603959, pvalue=0.4311168705769747)
>>> rho, pval = stats.spearmanr(x2n, y2n)
>>> rho
array([[ 1.        , -0.07960396, -0.08314431,  0.09662166],
       [-0.07960396,  1.        , -0.14448245,  0.16738074],
       [-0.08314431, -0.14448245,  1.        ,  0.03234323],
       [ 0.09662166,  0.16738074,  0.03234323,  1.        ]])
>>> pval
array([[0.        , 0.43111687, 0.41084066, 0.33891628],
       [0.43111687, 0.        , 0.15151618, 0.09600687],
       [0.41084066, 0.15151618, 0.        , 0.74938561],
       [0.33891628, 0.09600687, 0.74938561, 0.        ]])
>>> rho, pval = stats.spearmanr(x2n.T, y2n.T, axis=1)
>>> rho
array([[ 1.        , -0.07960396, -0.08314431,  0.09662166],
       [-0.07960396,  1.        , -0.14448245,  0.16738074],
       [-0.08314431, -0.14448245,  1.        ,  0.03234323],
       [ 0.09662166,  0.16738074,  0.03234323,  1.        ]])
>>> stats.spearmanr(x2n, y2n, axis=None)
SpearmanrResult(correlation=0.044981624540613524, pvalue=0.5270803651336189)
>>> stats.spearmanr(x2n.ravel(), y2n.ravel())
SpearmanrResult(correlation=0.044981624540613524, pvalue=0.5270803651336189)
Comment

PREVIOUS NEXT
Code Example
Python :: pandas data frame from part of excel 
Python :: how to get left click input in pygame 
Python :: truncate spaces in python 
Python :: filter function in python 
Python :: activate venv environment 
Python :: python second element of every tuple in list 
Python :: get image image memeory size in url inpyton requests 
Python :: separate each characters by commas into a single characters separated by commas 
Python :: save standard output in variable python 
Python :: get python ssl certificate location 
Python :: Reducing noise on Data 
Python :: cin python 
Python :: horizontal barplot 
Python :: @methodclass in python 
Python :: dbscan python 
Python :: cannot create group in read-only mode. keras 
Python :: input a number and print even numbers up to that number 
Python :: python print ling line in print 
Python :: python get dir from path 
Python :: python find string in string 
Python :: create an array filled with 0 
Python :: .size pandas 
Python :: Using python-poppler 
Python :: Query a PSQL Database From Python 
Python :: how to put my graph in tkinter interface 
Python :: pyplot x vs y 
Python :: quick sort algorithm in python 
Python :: python calculator source code 
Python :: dataframe rolling window 
Python :: python dictionary get vs setdefault 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =