`mne.stats.f_oneway` returns wrong (even negative) F for small integer dtypes

Đang mở Phù hợp với người mới
#14,477 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
numpy, python
Lĩnh vực
data

Hướng nghiên cứu

Lỗi nằm ở f_oneway trong mne/stats/parametric.py, nơi tổng bình phương được tính theo dtype của chính đầu vào (dòng ss_alldata). Bắt đầu bằng cách chạy bản tái hiện int16 trong issue và so sánh với kết quả float64 cũng như scipy.stats.f_oneway. Hoàn thành khi đầu vào số nguyên cho cùng một F không âm như đầu vào số thực, và một kiểm thử hồi quy được thêm cạnh các kiểm thử f_oneway hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

BUG
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])
Ngôn ngữ chính
Python
Star
3.6k
Fork
1.6k
Merge trung bình
1 ngày 20 giờ
Pull request đã merge (30 ngày)
73

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của mne-tools/mne-python

Tất cả issue của mne-tools/mne-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.