
I applied pdist on a very simple two 1-d arrays of the same values: 1,2,3 and 1,2,3: from import pdist, squareform import pandas as. Note that this function returns a correlation coefficient along with a corresponding p-value: The point-biserial correlation coefficient is 0.21816 and the corresponding p-value is 0.51928. a kendalltau constant input warning potentially in the future and maybe something for the regression functions and other interpolations as well. I used scipy's pdist with the correlation metric to construct a correlation matrix, but the values were not matching the ones I obtained from numpy's corrcoef. We can use the pointbiserialr () function from the scipy.stats library to calculate the point-biserial correlation between the two variables. The only open question that I'd have here is whether we want to have this warning in a hierarchy? I can see e.g. Any other opinions out there?īased on that back and forth, provided we all still agree, I'd say the fix for this PR would be to have a separate constant input warning for the spearmanr() that provides a similar informative warning and is specialized to the function. They are still documented in the pearsonr docstring, and maybe >that's enough. I figured they are part of the public API of scipy.stats, so they should be there. And if/when we >implement a similar behavior for other functions, I don't think there would be anything wrong with >another function, say foo(), having its own FooConstantInputWarning.ĭo we want to show the warnings in the overview generated by init.py? I'd rather not try to generalize this without concrete use-cases. Let's take two sinus with a frequency f0 200 Hz, a sample frequency fs 10000 Hz, playing during 0.1s and with a phase difference of pi.
Scipy correlation how to#
There are probably other functions that could use a similar pattern, but currently, it is specific to >pearsonr. The cross-correlation function seems to be ideal for that but I'm confused on how to interpret scipy cross-correlation. Should we replace PearsonRConstantInputWarning by ConstantInputWarning, I think this could >be a generic warning whereas PearsonRNearConstantInputWarning might be indeed a specific >warning for PearsonR import numpy as np np.ed (100) create array of 50 random integers. Reading back over the thread in #9562 now I see the response from wrote To calculate the correlation between two variables in Python, we can use the Numpy corrcoef () function. Warnings.warn(PearsonRConstantInputWarning()) not use the FFT to compute the convolution in that case, might be preferable. Users/rlucas/scipy-dev/scipy/scipy/stats/stats.py:3508: PearsonRConstantInputWarning: An input array is constant the correlation coefficent is not defined. Cross-correlation of two 1-dimensional sequences. Return (a > myspearman = stats.pearsonr(sequence_1,sequence_2) Users/rlucas/scipy-dev/scipy/scipy/stats/_distn_infrastructure.py:903: RuntimeWarning: invalid value encountered in greater Users/rlucas/anaconda3/envs/scipy-dev/lib/python3.6/site-packages/numpy/lib/function_base.py:2531: RuntimeWarning: invalid value encountered in true_divide Users/rlucas/anaconda3/envs/scipy-dev/lib/python3.6/site-packages/numpy/lib/function_base.py:2530: RuntimeWarning: invalid value encountered in true_divide myspearman = stats.spearmanr(sequence_1,sequence_2)
