I think the indent issue was due to copying and pasting also, attached is the code. <br><br><div class="gmail_quote">On Sun, Dec 20, 2009 at 1:05 PM,  <span dir="ltr">&lt;<a href="mailto:josef.pktd@gmail.com">josef.pktd@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">On Sun, Dec 20, 2009 at 3:50 PM, Pete Shepard &lt;<a href="mailto:peter.shepard@gmail.com">peter.shepard@gmail.com</a>&gt; wrote:<br>

&gt; Thanks for the reply Josef,<br>
&gt;<br>
&gt; Numpy version =1:1.3.0-3<br>
&gt; SciPy version=0.7.0-2<br>
&gt;<br>
&gt;<br>
&gt; Here is the code I am using, interstingly line 99 chokes in the<br>
&gt; testFisherExact() : example, don&#39;t know if these problems are related<br>
&gt;<br>
&gt;<br>
&gt; # -*- coding: utf-8 -*-<br>
&gt;<br>
&gt; #!/usr/bin/python<br>
&gt;<br>
&gt;<br>
&gt; import re<br>
&gt; import sys, os<br>
&gt; from scipy.stats import *<br>
&gt; #from scipy import array,searchsorted, histogram<br>
&gt; import re<br>
&gt; import operator<br>
&gt; import matplotlib<br>
&gt; matplotlib.use(&#39;PDF&#39;)<br>
&gt; import pylab<br>
&gt; &quot;<br>
&gt;<br>
&gt; def fisherExact(c) :<br>
&gt;             &quot;&quot;&quot;Performs a Fisher exact test on a 2x2 contingency table in<br>
&gt; list of lists<br>
&gt;                format.  Returns a tuple of (odds ratio, two-tailed P-value).<br>
&gt;<br>
&gt;                Examples:<br>
&gt;                &gt;&gt;&gt; fisherExact([[100, 2], [1000, 5]])<br>
&gt;                (0.25, 0.13007593634330314)<br>
&gt;                &quot;&quot;&quot;<br>
&gt;             oddsRatio = c[0][0] * c[1][1] / float(c[1][0] * c[0][1])<br>
&gt;             n1 = c[0][0] + c[0][1]<br>
&gt;             n2 = c[1][0] + c[1][1]<br>
&gt;             n  = c[0][0] + c[1][0]<br>
&gt;<br>
&gt;             mode = int(float((n + 1) * (n1 + 1)) / (n1 + n2 + 2))<br>
&gt;             pExact = hypergeom.pmf(c[0][0], n1 + n2, n1, n)<br>
&gt;             pMode = hypergeom.pmf(c[0][0], n1 + n2, n1, n)<br>
&gt;<br>
&gt;             if c[0][0] == mode :<br>
&gt;                     return oddsRatio, 1.0<br>
&gt;             elif c[0][0] &lt; mode :<br>
&gt;                     pLower = hypergeom.cdf(c[0][0], n1 + n2, n1, n)<br>
&gt;<br>
&gt;                     # Binary search for where to begin upper half.<br>
&gt;                     min = mode<br>
&gt;                     max = n<br>
&gt;                     guess = -1<br>
&gt;                     while min != max :<br>
&gt;                             guess = max if (max == min + 1 and guess == min)<br>
&gt; else \<br>
&gt;                                             (max + min) / 2<br>
&gt;<br>
&gt;                             pGuess = hypergeom.pmf(guess, n1 + n2, n1, n)<br>
&gt;                             if pGuess &lt;= pExact and hypergeom.pmf(guess - 1,<br>
&gt; n1 + n2, n1, n) &gt; pExact :<br>
&gt;                                     break<br>
&gt;                             elif pGuess &lt; pExact :<br>
&gt;                                     max = guess<br>
&gt;                             else :<br>
&gt;                                     min = guess<br>
&gt;<br>
&gt;                     if guess == -1 and min == max :<br>
&gt;                             guess = min<br>
&gt;<br>
&gt;                     return oddsRatio, pLower + hypergeom.sf(guess - 1, n1 +<br>
&gt; n2, n1, n)<br>
&gt;             else :<br>
&gt;                     pUpper = hypergeom.sf(c[0][0] - 1, n1 + n2, n1, n);<br>
&gt;<br>
&gt;                     # Special case to prevent binary search from getting<br>
&gt; stuck.<br>
&gt;                     if hypergeom.pmf(0, n1 + n2, n1, n) &gt; pExact :<br>
&gt;                             return oddsRatio, pUpper<br>
&gt;<br>
&gt;                     # Binary search for where to begin lower half.<br>
&gt;                     min = 0<br>
&gt;                     max = mode<br>
&gt;                     guess = -1<br>
&gt;                     while min != max :<br>
&gt;                             guess = max if (max == min + 1 and guess == min)<br>
&gt; else \<br>
&gt;                                             (max + min) / 2<br>
&gt;                             pGuess = hypergeom.pmf(guess, n1 + n2, n1, n);<br>
&gt;<br>
&gt;                             if pGuess &lt;= pExact and hypergeom.pmf(guess + 1,<br>
&gt; n1 + n2, n1, n) &gt; pExact :<br>
&gt;                                     break;<br>
&gt;                             elif pGuess &lt;= pExact  :<br>
&gt;                                     min = guess<br>
&gt;                             else :<br>
&gt;                                     max = guess<br>
&gt;<br>
&gt;                     if guess == -1 and min == max :<br>
&gt;                             guess = min<br>
&gt;                         return oddsRatio, pUpper + hypergeom.cdf(guess, n1 +<br>
&gt; n2, n1, n)<br>
<br>
</div></div>this return line has the wrong indent, it should be at the same column<br>
as the   if guess == -1 and min == max :<br>
<br>
Note: I had to reformat the indent to 4 spaces because IDLE<br>
complained. In these cases, it would be better to also attach the<br>
file, then I would be sure I have the same file than with copy and<br>
paste from the mail reader.<br>
<br>
Tell me if that solves the problem, I would think it&#39;s unlikely that<br>
your versions of scipy is to old for this.<br>
<br>
Josef<br>
<div><div></div><div class="h5"><br>
&gt;<br>
&gt; def testFisherExact() :<br>
&gt;     &quot;&quot;&quot;Just some tests to show that fisherExact() works correctly.&quot;&quot;&quot;<br>
&gt;     def approxEqual(n1, n2) :<br>
&gt;         return abs(n1 - n2) &lt; 0.01<br>
&gt;<br>
&gt;     res = fisherExact([[100, 2], [1000, 5]])<br>
&gt;     assert(approxEqual(res[1], 0.1301))<br>
&gt;     assert(approxEqual(res[0], 0.25))<br>
&gt;     res = fisherExact([[2, 7], [8, 2]])<br>
&gt;     assert(approxEqual(res[1], 0.0230141))<br>
&gt;     assert(approxEqual(res[0], 4.0 / 56))<br>
&gt;     res = fisherExact([[100, 2], [1000, 5]])<br>
&gt;     #assert(approxEqual(res[1],  0.1973244))<br>
&gt;         res = fisherExact([[5, 15], [20, 20]])<br>
&gt;     assert(approxEqual(res[1], 0.0958044))<br>
&gt;     res = fisherExact([[5, 16], [20, 25]])<br>
&gt;     assert(approxEqual(res[1], 0.1725862))<br>
&gt;     res = fisherExact([[10, 5], [10, 1]])<br>
&gt;     assert(approxEqual(res[1], 0.1973244))<br>
&gt;<br>
&gt; D=[[6, 1], [1, 6]]<br>
&gt; testFisherExact()<br>
&gt; p=fisherExact(D)<br>
&gt; print p<br>
&gt; On Sun, Dec 20, 2009 at 10:37 AM, &lt;<a href="mailto:josef.pktd@gmail.com">josef.pktd@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; On Sun, Dec 20, 2009 at 12:26 PM, Pete Shepard &lt;<a href="mailto:peter.shepard@gmail.com">peter.shepard@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt; &gt; Hello,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I am using a fisher exact test I got from<br>
&gt;&gt; &gt; <a href="http://projects.scipy.org/scipy/attachment/ticket/956/fisher.py" target="_blank">http://projects.scipy.org/scipy/attachment/ticket/956/fisher.py</a>. This<br>
&gt;&gt; &gt; program takes in two tuples and returns an odds ratio and a  p-value.<br>
&gt;&gt; &gt; Most<br>
&gt;&gt; &gt; tuples are handled nicely by the script but certain tuples eg &quot;[[6, 1],<br>
&gt;&gt; &gt; [1,<br>
&gt;&gt; &gt; 6]]&quot; return &quot;None&quot;. I am wondering if anyone knows why this is true?<br>
&gt;&gt;<br>
&gt;&gt; I get this, with and without the patch of thomas in the comments<br>
&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; fisherExact([[6, 1], [1, 6]])<br>
&gt;&gt; (36.0, 0.029137529137528768)<br>
&gt;&gt;<br>
&gt;&gt; Do you have an exact example? Which version of numpy and scipy?<br>
&gt;&gt; Looking at the code, I don&#39;t see any reason why it should return None.<br>
&gt;&gt;<br>
&gt;&gt; Josef<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; TIA<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; SciPy-User mailing list<br>
&gt;&gt; &gt; <a href="mailto:SciPy-User@scipy.org">SciPy-User@scipy.org</a><br>
&gt;&gt; &gt; <a href="http://mail.scipy.org/mailman/listinfo/scipy-user" target="_blank">http://mail.scipy.org/mailman/listinfo/scipy-user</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; SciPy-User mailing list<br>
&gt;&gt; <a href="mailto:SciPy-User@scipy.org">SciPy-User@scipy.org</a><br>
&gt;&gt; <a href="http://mail.scipy.org/mailman/listinfo/scipy-user" target="_blank">http://mail.scipy.org/mailman/listinfo/scipy-user</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; SciPy-User mailing list<br>
&gt; <a href="mailto:SciPy-User@scipy.org">SciPy-User@scipy.org</a><br>
&gt; <a href="http://mail.scipy.org/mailman/listinfo/scipy-user" target="_blank">http://mail.scipy.org/mailman/listinfo/scipy-user</a><br>
&gt;<br>
&gt;<br>
_______________________________________________<br>
SciPy-User mailing list<br>
<a href="mailto:SciPy-User@scipy.org">SciPy-User@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/scipy-user" target="_blank">http://mail.scipy.org/mailman/listinfo/scipy-user</a><br>
</div></div></blockquote></div><br>