Statistics/Chi-squared distribution: Difference between revisions

m
m (→‎{{header|Python}}: cdf function)
Line 308:
def χ2(x, k):
''' Chi-squared function, the probability distribution function (pdf) for chi-squared '''
return x ** (k/2 - 1) * exp(-x/2) / (2 ** (k/2) * gamma(k / 2)) if x > 0 and k > 0 else 0.0
 
 
def gamma_cdf(k, x):
''' lower incomplete gamma by series formula with gamma '''
return x**k * exp(-x) * sum(x**m / gamma(k + m + 1) for m in range(100))
 
 
def cdf_χ2(x, k):
''' Cumulative probability function (cdf) for chi-squared '''
return gamma_cdf(k / 2, x / 2) if x <=> 0 orand k <=> 0: else 0.0
return 0
return gammainc(k / 2, x / 2)
 
 
4,108

edits