title: F-Test with P-value in Python
body: <p>R allows us to compute F-test between two population:</p>
  
  <pre><code>&gt; d1 = c(2.5579227634, 1.7774243136, 2.0025207896, 1.9518876366, 0.0, 4.1984191803, 5.6170403364, 0.0)
  &gt; d2 = c(16.93800333, 23.2837045311, 1.2674791828, 1.0889208427, 1.0447584137, 0.8971380534, 0.0, 0.0)
  &gt; var.test(d1,d2)
  
      F test to compare two variances
  
  data:  d1 and d2
  F = 0.0439, num df = 7, denom df = 7, p-value = 0.000523
  alternative hypothesis: true ratio of variances is not equal to 1
  95 percent confidence interval:
   0.008789447 0.219288957
  sample estimates:
  ratio of variances 
          0.04390249 
  </code></pre>
  
  <p>Note there it reports P-value also. </p>
  
  <p>Another example, R gave this:</p>
  
  <pre><code>&gt; x1 = c(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 68.7169110318)
  &gt; x2 = c(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.1863361211)
  &gt; var.test(x1,x2)
  #p-value = 1.223e-09
  </code></pre>
  
  <p>What's the equivalent in Python?
  I checked this <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.f.html" rel="nofollow">documentation</a>, but doesn't seem to give what I want.</p>
  
  <p>This code gives different P-value (especially example 2):</p>
  
  <pre><code>import statistics as stats
  import scipy.stats as ss
  def Ftest_pvalue(d1,d2):
      """docstring for Ftest_pvalue"""
      df1 = len(d1) - 1
      df2 = len(d2) - 1
      F = stats.variance(d1) / stats.variance(d2)
      single_tailed_pval = ss.f.cdf(F,df1,df2)
      double_tailed_pval = single_tailed_pval * 2
      return double_tailed_pval
  </code></pre>
  
  <p>Python gave this:</p>
  
  <pre><code>In [45]: d1 = [2.5579227634, 1.7774243136, 2.0025207896, 1.9518876366, 0.0, 4.1984191803, 5.6170403364, 0.0]
  In [20]: d2 = [16.93800333, 23.2837045311, 1.2674791828, 1.0889208427, 1.0447584137, 0.8971380534, 0.0, 0.0]
  In [64]: x1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 68.7169110318]
  In [65]: x2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.1863361211]
  
  In [69]: Ftest_pvalue(d1,d2)
  Out[69]: 0.00052297887612346176
  
  In [70]: Ftest_pvalue(x1,x2)
  Out[70]: 1.9999999987772916
  </code></pre>