What this calculator does
The chi-squared distribution is one of the most widely used distributions in statistics, underpinning goodness-of-fit tests, contingency-table independence tests, and confidence intervals for a variance. This tool takes a percentile point x and the degrees of freedom \(\nu\) and returns three high-precision quantities: the probability density \(f(x)\), the lower cumulative probability \(P(X \le x)\), and the upper (tail) probability \(Q(X > x)\).
How to use it
Enter a non-negative value for \(x\) and a positive value for the degrees of freedom \(\nu\) (usually a positive integer, though the math also works for non-integer \(\nu\)). Press calculate. The PDF tells you the relative likelihood at exactly \(x\), the lower probability gives the area to the left (the p-value complement for a one-sided lower test), and the upper probability gives the right-tail area, which is the p-value reported by most chi-squared significance tests.
The formula explained
The density is $$f(x;k) = \frac{x^{\frac{k}{2}-1}\,e^{-x/2}}{2^{k/2}\,\Gamma\!\left(\frac{k}{2}\right)}$$ for \(x > 0\), where \(\Gamma\) is the gamma function. The cumulative probability equals the regularized lower incomplete gamma function \(P(k/2,\, x/2)\). We evaluate it numerically using a series expansion when \(x/2 < k/2 + 1\) and a continued-fraction expansion (Lentz's method) otherwise, with the gamma function evaluated through a Lanczos log-gamma approximation for stability.
Worked example
For \(x = 2\) and \(\nu = 3\), set \(a = k/2 = 1.5\) and \(z = x/2 = 1\). The density is $$f = \exp\left[(0.5)\ln 2 - 1 - 1.5\cdot\ln 2 - \ln\Gamma(1.5)\right] \approx 0.20755.$$ The lower probability \(P(X \le 2) = P(1.5, 1) \approx 0.42759\), so the upper tail probability $$Q = 1 - 0.42759 \approx 0.57241.$$
FAQ
What are degrees of freedom? In tests they typically equal the number of categories minus constraints, e.g. \((\text{rows}-1)(\text{cols}-1)\) for a contingency table.
Which value is the p-value? For a standard chi-squared test, the p-value is the upper cumulative probability \(Q(X > x)\).
Can x be zero or negative? At \(x = 0\) the density depends on \(\nu\) and the cumulative probability is 0. Negative \(x\) is outside the support, giving \(f = 0\), \(P = 0\), \(Q = 1\).