0todd0000 / spm1d

One-Dimensional Statistical Parametric Mapping in Python
GNU General Public License v3.0
60 stars 21 forks source link

HELP WANTED: No covariance estimated using elm (too small std?) #278

Closed EveCharbie closed 4 months ago

EveCharbie commented 4 months ago

When I try to do

t = spm1d.stats.ttest2(a, b, equal_var=False)

I get the following error message:

  File "/home/charbie/miniconda3/envs/spm/lib/python3.12/site-packages/spm1d/stats/t.py", line 237, in ttest2
    return glm(Y, X, c, Q, roi=roi)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/charbie/miniconda3/envs/spm/lib/python3.12/site-packages/spm1d/stats/t.py", line 62, in glm
    df = _reml.estimate_df_T(Y, X, eij, Q)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/charbie/miniconda3/envs/spm/lib/python3.12/site-packages/spm1d/stats/_reml.py", line 57, in estimate_df_T
    V,h         = reml(YY, X, Q)
    ^^^
TypeError: cannot unpack non-iterable NoneType object

because my data never meet the condition dF < 0.1 l.230 from spm1d/stats/_reml.py, meaning that the function relm returns None. I have a sample with regions of small dispersion (1e-3). The data is attached. Could someone help me fix this issue? data.zip

0todd0000 commented 4 months ago

Thank you for reporting this bug! I have not previously seen a dataset for which reml did not converge, so thank you very much for finding and reporting this problem!

Please find that I have updated the code with a fix that returns the result (rather than None) if the total number of iterations K is reached, where K has a default value of 128.



If you used pip to install spm1d then you can upgrade to the most recent version using:

pip install spm1d --upgrade

After upgrading please confirm that you are using the most recent version (0.4.28)



Additional notes:

EveCharbie commented 4 months ago

Hi :) Thank you very much for the super quick and detailed answer! The fix works as a charm.