How can I calculate the p-value given Chi Squared and the Degrees of Freedom? For example, what would be the exact p-value of a Chi Squared = 15 with df = 2?

  • $\begingroup$ To determine a p-value you need to specify whether it is one-sided or two-sided. For two-sided it is P(|X|>15) and for one-sided lower tail it is P(X<-15) and P(X.>15) for one-sided upper tail. X is a chi-square random variable with 2 degrees of freedom. $\endgroup$ – Michael R. Chernick Dec 10 '16 at 19:41
  • $\begingroup$ It is two-sided. What would be the code in R in order to carry this test? $\endgroup$ – mat Dec 10 '16 at 19:44
  • $\begingroup$ I don;t know R very well. I would think there is a a chi-square function that you could call. Aside from R you can get the value from a table of the chi-square distribution which are available in many elementary stat books. The only problem with the table is that 15 may not appear in which case you can get close by intrtpolation. $\endgroup$ – Michael R. Chernick Dec 10 '16 at 19:56
  • $\begingroup$ Let me correct myself. The chi-square doesn't go negative. For a one-sided test you want P(X>15). In my book P(X>13.815) is 0.001. So the p-value is < 0.001. $\endgroup$ – Michael R. Chernick Dec 10 '16 at 20:04
  • 2
    $\begingroup$ (1) It is rare for Chi-squared tests to be two-sided: what is your application? (2) (cc @michael) One would not interpolate into the tails; one would estimate the integral. BTW, this is an elementary integral, because the Chi-squared distribution with 2 DF is an Exponential distribution: you should obtain $e^{-15/2}$ for the upper tail probability. See en.wikipedia.org/wiki/Chi-squared_distribution. $\endgroup$ – whuber Dec 10 '16 at 20:37

In applied statistics, chisquared test statistics arise as sums of squared residuals, or from sums of squared effects or from log-likelihood differences. In all of these applications, the aim is to test whether some vector parameter is zero vs the alternative that it is non-zero and the chisquare statistic is related to the squared size of the observed effect. The required p-value is the right tail probability for the chisquare value, which in R for your example is:

> pchisq(15, df=2, lower.tail=FALSE)
[1] 0.0005530844

For other df or statistic values, you obviously just substitute them into the above code.

All cumulative probability functions in R compute left tail probabilities by default. However they also have a lower.tail argument, and you can always set this FALSE to get the right tail probability. It is good practice to do this rather than to compute $1-p$ as you might see in some elementary textbooks.

  • 1
    $\begingroup$ Is it possible to go backwards? Deriving Chi-Square value using P-value and degrees of freedom using R code? $\endgroup$ – Eric Mar 9 '18 at 0:54
  • 2
    $\begingroup$ @Eric Just type the following in R: help(qchisq) $\endgroup$ – Gordon Smyth Dec 31 '18 at 1:30

R has a suite of probability functions for density or mass in the form d* (e.g., dbeta, dchisq), and distribution in the form p* (e.g., pf, pgamma). You might wish to start there.

  • $\begingroup$ Is it possible to go backwards? Deriving Chi-Square value using P-value and degrees of freedom using R code? $\endgroup$ – Eric Mar 9 '18 at 0:54

Yes, it is possible to calculate the chi-square value for a given p-value (p) and degrees of freedom (df). Below is how to go about it:

For the sake of verification, I first calculate p for a given chi-square value = 1.1 and df=1:


pchisq(1.1, df=1, lower.tail=FALSE)# the answer is p=0.2942661

Now, to go backward by using p and df to calculate chi-square value, I used the p=0.2942661 I obtained from above and df=1 above:


qchisq(0.2942661, 1, lower.tail=FALSE) # the answer is 1.1 as in the first solution.

So using your example of Chi Squared = 15 with df = 2, the solutions are below:

Solution: calculate p-value

pchisq(15, df=2, lower.tail=FALSE)# answer: p= 0.0005530844

use the p= 0.0005530844 and df=2 to get back the chi-square value

qchisq(0.0005530844, 2, lower.tail=FALSE)# answer: chi-square = 15

Hope this helps!!!




in your example,


[1] 0.9994469
  • 1
    $\begingroup$ I don't think this is the p-value. Could it possibly be the cumulative probability? As whuber said the p-value would be exp(-15/2) which is much smaller than 0,999469. $\endgroup$ – Michael R. Chernick Jun 29 '17 at 22:57
  • 6
    $\begingroup$ This is incorrect. It doesn't even pass the smell test. Consider that the expected value of a chi-squared distribution is its df, and that the variance is 2*df (wikipedia), so 15 is ~9 SDs from the mean. That should tell you something is wrong here. In essence, you are using this to perform a 1-tailed test that a fit is 'too good' (cf here). Under the typical usage of the chi-squared, you want pchisq(15, 2, lower.tail=FALSE), or 1-pchisq(15, 2), which is 0.0005530844. $\endgroup$ – gung - Reinstate Monica Jun 30 '17 at 1:23
  • $\begingroup$ (That said, this is an answer, even if incorrect, so it shouldn't be deleted as not an answer. I'm voting looks OK.) $\endgroup$ – gung - Reinstate Monica Jun 30 '17 at 1:25
  • $\begingroup$ @gung +1 I added my own answer today but hadn't read your comment first, which gives the same obvious solution. $\endgroup$ – Gordon Smyth Jun 30 '17 at 4:25
  • $\begingroup$ Is it possible to go backwards? Deriving Chi-Square value using P-value and degrees of freedom using R code? $\endgroup$ – Eric Mar 9 '18 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.