MBB-team / VBA-toolbox

The VBA toolbox
GNU General Public License v3.0
130 stars 67 forks source link

RFT_main.m cannot deal when there is no clear peak in a cluster #83

Open NicolasClairis opened 4 years ago

NicolasClairis commented 4 years ago

In some cases the amount of clusters identified by RFT_main.m (nc line 165) and the number of peaks identified (is line 221) does not match. (If no local maxima could be found in particular because there is no peak in the cluster). Then RFT_main.m and hence also RFT_GLM_contrast.m crashes. Could this case be handled somehow, just by reporting there was no peak eventhough the cluster as a full is significant for example?

NicolasClairis commented 2 years ago

Hi. I just re-experienced this bug when using data that was not smoothed. In summary, what happens is that if too neighbour values of Xare the same, RFT_localmax (line 151) does not extract them which then causes a mismatch between the elements in peaks.ind and those extracted by RFT_clusters (line 164) in clusters.ind. Because of this, when the script extracts the peaks (line 220) with ismember(peaks.ind, clusters.imax)which are then extracted in the variable is (line 221), there is a mismatch between the number of clusters identified in the variable nc and those present in is which makes the script crash.

I would recommend to add a checkup before the for loop to warn the user from this bug as it took me a lot of time to figure. Something simple could be: if nc > length(is) error('Mismatch between number of clusters and number of peaks. Please verify that you smoothed the data in X and try again.'); end

Indeed, in my case, smoothing the data solved the problem, but maybe it would be good to add a more generic way to solve this.