Hello Fellow TDT users,

I’m using permutation testing to test the significance of my first level classification results.

I was confused by the following lines in the stats_permutation function:

```
switch lower(tail)
case 'left'
if exist('bsxfun','builtin') % New method for Matlab 7.4+ (fast)
p = (1/(sz_ref(2)+1))*(sum(bsxfun(@ge,n_correct,reference),2)+1);
else
p = (1/(sz_ref(2)+1))*(sum(repmat(n_correct,1,sz_ref(2))>=reference,2)+1);
end
case 'right'
if exist('bsxfun','builtin') % New method for Matlab 7.4+ (fast)
p = (1/(sz_ref(2)+1))*(sum(bsxfun(@le,n_correct,reference),2)+1);
else
p = (1/(sz_ref(2)+1))*(sum(repmat(n_correct,1,sz_ref(2))<=reference,2)+1);
end
```

Shouldn’t it be the case that for right tail inference we should count the number of permutations that resulted in classification above the true classification value? If so, doesn’t the function @le does the exact opposite?

Also, what is the purpose of adding 1 to the count? As far as I understand the correct permutation is included in the permutation matrix, so the p value can never be 0 anyway. Am I missing something?

Many thanks for this great toolbox and for your help,

-Matan