scipy.stats.spearmanr

53

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)

Comments

Submit
0 Comments