What is the chi-squared distribution?
The chi-squared (\(\chi^2\)) distribution describes the sum of the squares of independent standard normal variables. It is parameterised by a single value, the degrees of freedom \(\nu\) (Greek letter "nu"), and is fundamental to hypothesis testing, goodness-of-fit tests, contingency-table analysis and confidence intervals for variance. This calculator evaluates three related functions of \(x\) for a chosen \(\nu\): the probability density \(f\), the lower cumulative probability \(P(X \le x)\), and the upper cumulative probability \(Q(X > x)\).
How to use it
Pick which function you want as the headline value, enter the degrees of freedom \(\nu\) (any value greater than 0) and the point \(x\) at which to evaluate. The initial value of \(x\), increment and number of points define a series \(x_k = \text{startX} + k\cdot\text{stepX}\) used to build a table or graph of the chosen function. All inputs are dimensionless, so no unit conversion is needed.
The formula explained
The density is $$f(\text{x};\,\nu) = \frac{\text{x}^{\,\frac{\nu}{2}-1}\,e^{-\frac{\text{x}}{2}}}{2^{\frac{\nu}{2}}\,\Gamma\!\left(\frac{\nu}{2}\right)}$$ for \(x \ge 0\). The cumulative probabilities use the regularized incomplete gamma function: $$F(\text{x};\,\nu) = P\!\left(\frac{\nu}{2},\,\frac{\text{x}}{2}\right) = \frac{\gamma\!\left(\frac{\nu}{2},\,\frac{\text{x}}{2}\right)}{\Gamma\!\left(\frac{\nu}{2}\right)}$$ equals the lower incomplete gamma of \((\nu/2, x/2)\) divided by \(\Gamma(\nu/2)\), and $$Q(\text{x};\,\nu) = 1 - P\!\left(\frac{\nu}{2},\,\frac{\text{x}}{2}\right) = \frac{\Gamma\!\left(\frac{\nu}{2},\,\frac{\text{x}}{2}\right)}{\Gamma\!\left(\frac{\nu}{2}\right)}.$$ We compute everything in log space and use a series expansion or a continued fraction (Lentz's algorithm) for the incomplete gamma, which is exact and avoids overflow.
Worked example
For \(\nu = 3\) and \(x = 2\): \(a = \nu/2 = 1.5\) and \(z = x/2 = 1\). The lower cumulative probability \(P(2,3)\) is about \(0.42759\), so \(Q\) is about \(0.57241\). The density evaluates to $$f(2,3) = \frac{2^{0.5}\cdot e^{-1}}{2^{1.5}\cdot \Gamma(1.5)} \approx 0.20755.$$
FAQ
Why is \(f\) infinite at \(x = 0\) for small \(\nu\)? When \(\nu < 2\) the density diverges to infinity at \(x = 0\); for \(\nu = 2\) it equals \(0.5\), and for \(\nu > 2\) it is \(0\) there.
How do I find a critical value? Set the function to lower cumulative \(P\) and try values of \(x\) until \(P\) reaches your target (for example \(P = 0.95\) with \(\nu = 1\) gives \(x \approx 3.8415\)).
Is the cumulative probability exact? Yes - it uses the closed-form incomplete gamma function rather than numerical integration, so results are accurate to machine precision.