How is $\chi^2$ value converted to p-value? I'm brand new to statistics and am studying the math behind split testing (A/B and multivariate). I've learned how to calculate $\chi^2$ with given test data, and I understand how to translate this into a probability via a table, but I'd like to be able to calculate the probability myself. I've read through a couple of explanations online, but I'm not getting it. 
Does anyone know of a resource or book that breaks this down?
 A: The $p$-value is the area under the $\chi^2$ density to the right of the observed test statistic. Therefore, to calculate the $p$-value by hand you need to calculate an integral. 
In particular, a $\chi^2$ random variable with $k$ degrees of freedom has probability density 
$$f(x;\,k) =
\begin{cases}
  \frac{x^{(k/2)-1} e^{-x/2}}{2^{k/2} \Gamma\left(\frac{k}{2}\right)},  & x \geq 0; \\ 0, & \text{otherwise}.
\end{cases}$$
Suppose you observe a test statistic $\lambda$. Then, the $p$-value corresponding to $\lambda$ is 
$$ 
p = \int_{\lambda}^{\infty}
\frac{x^{(k/2)-1} e^{-x/2}}{2^{k/2} \Gamma\left(\frac{k}{2}\right)}
dx $$ 
After trying to evaluate this integral by hand, it may become clear to you why people use tables (and computers) for calculating such things. 
Edit: (This was in the comments but seemed important enough to add here) Note that you can write the $p$-value using special functions: 
$$ p = 1−\frac{γ(k/2,λ/2)}{Γ(k/2)} $$ 
where $\gamma(\cdot,\cdot)$ is the lower incomplete gamma function. 
