def chi_square(x, p, df=1): """returns the chisquare statistic and it's probability""" N = len(x) end = N sim = numpy.logical_not(numpy.logical_xor(x[0:end - p], x[p:end])) * 1 s = ((numpy.ones((N - p, ), float) - sim)**2).sum() D = s / (N - p) p_val = 1 - igam(df / 2.0, D / 2) return D, p_val
def pdtrc(k, m): """Returns sum of right tail of Poisson distribution, k+1 through infinity. See Cephes docs for details. """ if k < 0: raise ValueError("Poisson k must be >= 0.") if m < 0: raise ValueError("Poisson m must be >= 0.") return igam(k + 1, m)
def chi_low(x, df): """Returns left-hand tail of chi-square distribution (0 to x), given df. x ranges from 0 to infinity. df, the degrees of freedom, ranges from 1 to infinity (assume integers). Typically, df is (r-1)*(c-1) for a r by c table. Result ranges from 0 to 1. See Cephes docs for details. """ x = fix_rounding_error(x) if x < 0: raise ValueError("chi_low: x must be >= 0 (got %s)." % x) if df < 1: raise ValueError("chi_low: df must be >= 1 (got %s)." % df) return igam(df / 2, x / 2)
def gdtr(a, b, x): """Returns integral from 0 to x of Gamma distribution with params a and b. """ if x < 0.0: raise ZeroDivisionError("x must be at least 0.") return igam(b, a * x)