code: function calculateChiSquareProbability(x, df) {
      if (x <= 0.0 || df < 1)
          return 1.0;
  
      var a = 0.5 * x;
  
      if (df > 1)
          var y = calculateExponent(-a);
  
      var s = 2.0 * calculateNormalZProbability(-Math.sqrt(x));
  
      if (df > 2) {
          x = 0.5 * (df - 1.0);
          var z = 0.5;
  
          if (a > BIG_X) {
              var e = LOG_SQRT_PI;
              var c = Math.log(a);
  
              while (z <= x) {
                  e = Math.log(z) + e;
                  s += calculateExponent(c * z - a - e);
                  z += 1.0;
              }
  
              return (s);
          }
          else {
              e = I_SQRT_PI / Math.sqrt(a);
              c = 0.0;
  
              while (z <= x) {
                  e = e * (a / z);
                  c = c + e;
                  z += 1.0;
              }
  
              return (c * y + s);
          }
      }
  
      return s;
  }
docs: Calculates the probability for the results of the Chi-square test.
  
  @param {Number} x Chi-square value.
  @param {Number} df Degrees of freedom.
  @return {Number}