0todd0000 / spm1d

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

RuntimeWarning: invalid value encountered in double_scalars #21

Closed 0todd0000 closed 9 years ago

0todd0000 commented 9 years ago

The error described below is copied from issue #19 as a separate issue.

Another notice: When I ran the old anova2RM code on another dataset, laid out in same format, albeit on a subset of the original population, this came up...

C:\Users\14342453\AppData\Local\Enthought\Canopy\User\lib\site-packages\spm1d\stats\anova\solvers.py:117: RuntimeWarning: divide by zero encountered in divide MS,MSE = (SS/df), (SSE/dfE) C:\Users\14342453\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\stats_distn_infrastructure.py:767: RuntimeWarning: invalid value encountered in greater cond = logical_and(cond, (asarray(arg) > 0)) C:\Users\14342453\AppData\Local\Enthought\Canopy\User\lib\site-packages\rft1d\prob.py:69: RuntimeWarning: invalid value encountered in double_scalars p = Q * (pn) C:\Users\14342453\AppData\Local\Enthought\Canopy\User\lib\site-packages\rft1d\prob.py:352: RuntimeWarning: invalid value encountered in double_scalars fn = lambda x : (rft(1, 0, STAT, x[0], df, resels, n, Q, False, version)[0] - aaa)2 C:\Users\14342453\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\optimize\optimize.py:460: RuntimeWarning: invalid value encountered in absolute if (numpy.max(numpy.ravel(numpy.abs(sim[1:] - sim[0]))) <= xtol and C:\Users\14342453\AppData\Local\Enthought\Canopy\User\lib\site-packages\rft1d\geom.py:475: RuntimeWarning: invalid value encountered in greater_equal L,n = bwlabel(y >= u, merge_wrapped=wrap)

0todd0000 commented 9 years ago

Bernard, These numpy errors arise when there are numerical problems like zero variance or empty arrays. It is difficult to know what exactly is causing this problem without more details. Can you please send the script and dataset which produce this error? Todd

bernard-liew commented 9 years ago

Dear Todd,

Sorry for the extremely delayed reply. I was away from school for 3 weeks for personal matters. I will send to your personal email the script and data, and will post the reply here.

Regards, Bernard

0todd0000 commented 9 years ago

Hi Bernard,

No problem for the delay, thank you for sending the data. I found the source of the problem, but I'll need a couple of days to fix it. The issue is that the residuals are zero in two-way repeated-measures designs; this doesn't cause a problem for F statistic computation or for 0D inference, but it does cause a problem for 1D inference because 1D inference needs a smoothness estimate, which is calculated using the residuals. I'll need a day or two to ensure that we can get appropriate residuals for the 1D case.

Sorry about this! Since I didn't have any two-way RM datasets to test I didn't notice this problem before.

I'll reply again within a few days.

Todd

0todd0000 commented 9 years ago

Hi again, Was there just one measurement per subject or are those data averages? If there are multiple measurements for each subject then it is easy to compute the residuals. If you have those data please send them. Todd

0todd0000 commented 9 years ago

Hi Bernard, Thank you for sending the data. I just tried putting all of those data into spm1d.stats.anova2rm and it seems to be working fine. So for now I'd recommend including all trials instead of just means. However, please note that two- and three-way unbalanced designs are not yet supported, so you won't be able to get an answer unless all subjects have the same number of repetitions.

Please try that out and let me know if you encounter any issues. In the meantime I'll try to come up with a solution for the case of just one (mean) observation per subject and condition. Todd

EDIT: Sorry about that, that will not work for the current version (0.3.0.1), but it will work with new version of the code (0.3.1). Version 0.3.1 will be available in the next couple of days.

0todd0000 commented 9 years ago

Hi again Bernard,

The new version of the code is ready (version 0.3.1) both at GitHub and at PyPi.

You should now be able to run spm1d.stats.anova2rm and other repeated-measures designs without errors.

NOTE:

IF (a) the data are 1D and (b) there is only one observation per subject and per condition...

THEN inference is approximate, based on approximated residuals.

TO AVOID THIS PROBLEM: use multiple observations per subject per condition, and the same number of observations across all subjects and conditions.

I'll close this issue for now because it pertains to the previous version (0.3.0.1). If you encounter any new problems please let me know by creating a new issue.

Cheers,

Todd