biostats.spearman_rank_correlation#

biostats.spearman_rank_correlation(data, x, y)[source]#

Test whether there is a correlation between two numeric variables with nonparametric methods.

Parameters:
datapandas.DataFrame

The input data. Must contain at least two numeric columns.

xstr

The first numeric variable.

ystr

The second numeric variable. Switching the two variables will not change the result.

Returns:
summarypandas.DataFrame

The correlation coefficient.

resultpandas.DataFrame

The degree of freedom, t statistic, and p-value of the test.

See also

correlation

The parametric version of Spearman’s rank correlation.

Examples

>>> import biostats as bs
>>> data = bs.dataset("spearman_rank_correlation.csv")
>>> data
    Volume  Pitch
0     1760    529
1     2040    566
2     2440    473
3     2550    461
4     2730    465
5     2740    532
6     3010    484
7     3080    527
8     3370    488
9     3740    485
10    4910    478
11    5090    434
12    5090    468
13    5380    449
14    5850    425
15    6730    389
16    6990    421
17    7960    416

We want to test whether there is a correlation between Volume and Pitch.

>>> summary, result = bs.spearman_rank_correlation(data=data, x="Volume", y="Pitch")
>>> summary
             Coefficient
Correlation    -0.763036

The correlation coefficient is given.

>>> result
       D.F.  t Statistic  p-value     
Model    16    -4.722075  0.00023  ***

The p-value < 0.001, so there is a significant correlation between Volume and Pitch.