title: How do I run a paired t-test in BigQuery. Are there any UDFs available?
body: <p>I am attempting to run a paired t-test in bigquery using the JavaScript statistical.js library and I am getting inconsistent numbers. </p>
  
  <p>My code is as follows;</p>
  
  <pre><code> CREATE TEMPORARY FUNCTION ttest(a ARRAY&lt;FLOAT64&gt;, b ARRAY&lt;FLOAT64&gt;)
   RETURNS FLOAT64
   LANGUAGE js AS
  """
     return statistical.methods.tTestTwoSample(a, b); 
     //statistical.methods.tTestTwoSample(sample1: Array, sample2: Array) 
  """
  OPTIONS (
  library="gs://my_bucket/statistical.js"
  );
  
  
  SELECT 
   ttest([9.96,   3.76,   1.17,   8.66,   5.25,   7.61,   5.8,    1.84,   7.06, 9.4,  2.99,   9.3,    9.01,   4.24,   3.52,   9.6,    7.59,   6.99,   9.62,   2.18] , 
      [3.96,  5.76,   7.17,   7.66,   9.25,   3.61,   4.8,    8.84,   6.06,   4.4,    1.99,   8.3,    9.01,   1.24,   5.52,   8.6,    5.59,   1.99,   7.62,   3.18]  ) ttest 
  </code></pre>
  
  <p>With <code>gs://my_bucket/statistical.js</code> as the location of where the JS package is saved in google storage. </p>
  
  <p>The package is available here <code>https://github.com/adrien2p/statistical-js</code></p>
  
  <p>The two sample t-test <code>statistical.methods.tTestTwoSample(sample1: Array, sample2: Array)</code> should return a p-value. I was unable to find out if the test was paired or otherwise. When I run the code I get 4.099, which as far as I know is not a p-value.  I have ran the test in Excel to validate the result using <code>=T.TEST()</code> and I get a p-value of 0.4871 on a paired two sided test. I have also attempted other t-tests other than paired and attempted treating the 4.099 result as a T-Statistic without any luck of the numbers matching.   </p>
  
  <p>So my question is, how can I run a paired t-test in BigQuery with a resulting p-value? Should I be using other packages?</p>
  
  <p>Thanks in advance for any help.  </p>