Sorry, I've spotted a school-boy error in that second test -- the proportionSignicant were closer to p = 0.05 when I corrected it. I'd still be interested to be corrected on my first post. (And apologies for having a conversation with myself on the comments board.)

I've just tested this program with some random numbers, on the assumption that it should give significant (p<.05) results just on 1/20 of the trials. I get significant results on 1/3 of trials. Unless someone corrects me, I'm going to assume that this code does not do what it claims to do.

Here's my test code, in one ugly line:
counter=0; N=10000; for ii=1:N; [ppos,pneg,either]=Fisherextest(ceil(rand*20),ceil(rand*20),ceil(rand*20),ceil(rand*20)); if either<=.05; counter=counter+1; end; end; proportionSignificant=counter/N

Am I misunderstanding something, or is there a serious bug in the 1-tailed tests? The following two lines give the same outputs:
[ppos,pneg]=Fisherextest(1,10,10,1)
[ppos,pneg]=Fisherextest(10,1,1,10)
In fact, ppos seems to be always greater or equal to pneg, whereas it should be possible to have significant 1-sided results on both sides.

Again, there seems to be a problem with one sided tests:
Fisher's exact test P-values for cells:
a = 10, b = 1, c = 1, d = 10
----------------------------------------------
P-value
----------------------------------------------
Left tail Right tail 2-tail
(negative) (positive) (both)
----------------------------------------------
0.0001729437 0.9999985824 0.0003458873
----------------------------------------------
>> Fisherextest(1,10,10,1)
Fisher's exact test P-values for cells:
a = 1, b = 10, c = 10, d = 1
----------------------------------------------
P-value
----------------------------------------------
Left tail Right tail 2-tail
(negative) (positive) (both)
----------------------------------------------
0.0001729437 0.9999985824 0.0003458873
----------------------------------------------

Sorry, I've spotted a school-boy error in that second test -- the proportionSignicant were closer to p = 0.05 when I corrected it. I'd still be interested to be corrected on my first post. (And apologies for having a conversation with myself on the comments board.)

I've just tested this program with some random numbers, on the assumption that it should give significant (p<.05) results just on 1/20 of the trials. I get significant results on 1/3 of trials. Unless someone corrects me, I'm going to assume that this code does not do what it claims to do.
Here's my test code, in one ugly line:
counter=0; N=10000; for ii=1:N; [ppos,pneg,either]=Fisherextest(ceil(rand*20),ceil(rand*20),ceil(rand*20),ceil(rand*20)); if either<=.05; counter=counter+1; end; end; proportionSignificant=counter/N

Comment only