raphaelvallat / pingouin

Statistical package in Python based on Pandas
https://pingouin-stats.org/
GNU General Public License v3.0
1.61k stars 138 forks source link

clip r values #342

Closed remrama closed 1 year ago

remrama commented 1 year ago

Fixes #340

I added np.clip to pg.corr, right after where all the r values are calculated and before being passed to power_corr, so I think this should catch all similar cases. Rather than always clipping, I only do it if the r value exceeds -1 or 1 and np.isclose to abs(1). I don't imagine getting r values exceeding those bounds, but this felt safer to prevent accidentally clipping something super-high down to 1.

Re-running the original code that produced the error will work now:

import numpy as np
import pingouin as pg
pg.corr([1, np.nan, 2, 4], [1, 2, np.nan, 3], method='bicor')
# bicor  2  1.0  [1.0, 1.0]    NaN      1