-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
np.nan in mne.stats.permutation_t_test fails silently #13767
Copy link
Copy link
Open
Description
I've recently encountered a situation where I had a np.nan in the data I was running a permutation_t_test on. This failed (expectedly), however, it did not give me any warning/error! I only realized because a pvalue=0 seemed a bit suspicious in my plot
I think that it should at least print a warning, similar to how it give a RuntimeWarning when one test's observations are all zero (probably due to underlying numpy warnings.)
I assume this is the same for other functions in the stats module. If this is something that should be improved, probably best to do it systematically for all functions?
import mne
import numpy as np
x = np.random.rand(20, 20)
x[:, 0] = np.nan
t_obs, pvals, h0 = mne.stats.permutation_t_test(x)
# Permuting 9999 times...
# no warning printed! But all h0 are np.nan
# when one test is 0 for all observations, there is a warning
x = np.random.rand(20, 20)
x[:, 0] = 0
t_obs, pvals, h0 = mne.stats.permutation_t_test(x)
# Permuting 9999 times...
# /home/simon/anaconda3/envs/default/lib/python3.14/site-packages/mne/stats/permutations.py:20: RuntimeWarning: invalid value encountered in divide
# max_abs = np.max(np.abs(mus) / (stds / sqrt(n_samples)), axis=1) # t-maxReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels