`mne.stats.f_oneway` returns wrong (even negative) F for small integer dtypes
Los mantenedores suelen responder en 1 día
@darshpatel1052 ya está trabajando en esto.
Desde el 3/11/2026.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
Línea de trabajo
El error está en f_oneway en mne/stats/parametric.py, donde la suma de cuadrados se calcula en el tipo de dato de la entrada (la línea ss_alldata). Empieza ejecutando la reproducción con int16 del issue y compárala con el resultado en float64 y con scipy.stats.f_oneway. Está terminado cuando las entradas enteras dan la misma F no negativa que las entradas en punto flotante y se añade una prueba de regresión junto a las pruebas existentes de f_oneway.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description of the problem
mne.stats.f_oneway squares the input in its own dtype (np.sum(a**2, axis=0)). For integer arrays whose squares do not fit the dtype (int16 from values above 181, uint8 from values above 15, int32 from values above 46340) the squares wrap around silently, and the F statistic is wrong; it can even be negative, which is impossible for an F ratio. The same data cast to float gives the correct value.
Steps to reproduce
import numpy as np
from mne.stats import f_oneway
from scipy.stats import f_oneway as scipy_f_oneway
a = np.array([[182], [180]], dtype=np.int16)
b = np.array([[181], [178]], dtype=np.int16)
print(f_oneway(a, b)) # [-6.86713618e-05]
print(f_oneway(a.astype(float), b.astype(float))) # [0.69230769]
print(scipy_f_oneway(a[:, 0], b[:, 0]).statistic) # 0.6923076923076923
A more typical case (raw ADC counts around 1000, 10 and 12 samples per group, three columns):
rng = np.random.RandomState(0)
x = rng.randint(900, 1100, (10, 3)).astype(np.int16)
y = rng.randint(950, 1150, (12, 3)).astype(np.int16)
print(f_oneway(x, y)) # [-0.00168 -0.04556 -0.01694]
print(f_oneway(x.astype(float), y.astype(float))) # [ 0.5919 12.8788 6.3488]
Link to data
No response
Expected results
The same F as for the float64 data (and as scipy.stats.f_oneway): non-negative and independent of the storage dtype.
Actual results
Wrapped-around sums of squares: F values near zero or negative, with no warning.
Additional information
I think the cause is in mne/stats/parametric.py (f_oneway):
ss_alldata = reduce(lambda x, y: x + y, [np.sum(a**2, axis=0) for a in args])
- Lenguaje dominante
- Python
- Estrellas
- 3.6k
- Forks
- 1.6k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 74
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de mne-tools/mne-python
-
BUG
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
mne-tools/mne-python#14478 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
ENH: Add `description` filter parameter to `Raw.crop_by_annotations()`Posiblemente ocupada @aman-coder03 la tomó hace 212 días. AbiertoENH
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
mne-tools/mne-python#13743 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Wrong exponent in the denominator of the transfer function in the filtering background tutorialPosiblemente ocupada @qxzzxq la tomó hace 2 días. AbiertoDOC
Dificultad 1/5 Menos de una hora Aptitud para principiantes 20/100
mne-tools/mne-python#14486 ·
Los mantenedores suelen responder en 1 día
-
cannot plot into matplotlib subfigurePosiblemente ocupada @ishaaaan17 la tomó hace 2 días. AbiertoBUG
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
mne-tools/mne-python#14481 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
BUG: One layer BEM construction fails for current ANTS6-0Months3T templatePosiblemente ocupada @sruthisureshkumar-arch la tomó hace 3 días. AbiertoBUG
Dificultad 3/5 1-2 días Aptitud para principiantes 57/100
mne-tools/mne-python#14468 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de mne-tools/mne-python
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
autowarefoundation/autoware_carla_scenario#1485 ·
Los mantenedores suelen responder en 1 día
-
needs-area-label
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 2 días
-
enhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Official-Space-AI/OpenPhysGraspGen#114 ·
Los mantenedores suelen responder en 2 días
-
changelog investigate
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
ramnes/notion-sdk-py#441 ·
-
copy_tree splits same-file errors into charactersPosiblemente ocupada @Gambit-Checkmate la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 14 días