I am learning about chi-squared. It has two steps; a) chi-squared calculation b) critical value

When I calculate chi-squared, the output includes a) chi-squared statistic (220.5) and b) a p-value (1.315...e-48):

chisquare_result = stats.chisquare(df['observed'], df['expected'])
# Output : Power_divergenceResult(statistic=220.5, pvalue=1.3153258948574585e-48)

When I lookup the critical value, my course materials describe my inputs as a) degrees of freedom, and b) a concept described as a p-value (where we used typical threshold 0.05).

# Desired p-value is 0.05, and (1-0.05) = 0.95
p_value =  0.05
critical_value = stats.chi2.ppf(q=(1-p_value), df=2)
# Output: 5.991464547107979

My questions:

  1. Are the bolded "p-values" I mention above; are they both truly p-values?

    a) If they are both p-values, what's the difference between them, why don't they each have the same value?

    b) If they are not both p-values; what's the difference between them?

  2. If I can get a p-value as output when calculating chi-squared, why do I need to calculate a critical value?

    a) In other words; why isn't the p-value from chi-squared sufficient to reject/fail-to-reject Null Hypothesis?

  • 1
    $\begingroup$ The second thing is not a p-value. It's a significance level. You choose it before you see data. A p-value is something you calculate from the data. $\endgroup$
    – Glen_b
    Commented Apr 9, 2019 at 17:44
  • $\begingroup$ @Glen_b ; the second thing is not a p-value; if we subtract it from 1, it produces a p-value, right? In fact, it produces a p-value I could compare to my own "choose before you see the data" p-value, to decide if my chi-squared test is reliable. $\endgroup$ Commented Apr 9, 2019 at 17:56
  • $\begingroup$ In other words, I could compare critical value for an acceptable p, to chi-squared statistic; (black line in attached image): chi-squared value is greater than critical value = can reject null hypothesis. OR I could compare the p-value of a chi-squared calculation, to an acceptable p (purple line in attached image) ; if chi-squared p-value is less than acceptable p, = can reject null hypothesis. These two approaches will always lead to same conclusion.i.postimg.cc/zvvnK69y/2019-04-09-11-54-39-Ins-Chi-square.png $\endgroup$ Commented Apr 9, 2019 at 17:58
  • 1
    $\begingroup$ To be clearer, then: The thing where you say "p_value = 0.05" ... that thing is not a p-value. It is a significance level. $\endgroup$
    – Glen_b
    Commented Apr 9, 2019 at 18:01
  • $\begingroup$ OK, so it's a wording thing? The code should be written like this: # Desired significance level is 0.05, and (1-0.05) = 0.95; significance_level = 0.05; critical_value = stats.chi2.ppf(q=(1-significance_level), df=2); And I can compare this 0.05 which is significance level, to the chi-squared p-value of 0.046 ; since the latter is smaller than the former; I can reject null hypothesis? $\endgroup$ Commented Apr 9, 2019 at 18:06

1 Answer 1


5.99 is the critical value for 2 degrees of freedom and p = 0.05. So any value of $\chi^2$ greater than 5.99 is significant at the 0.05 level.

220.5 is the critical value for 2 degrees of freedom and p = $1.315 \times 10^{-48}$ so any value greater than 220.5 is significant at that level.

The difference is that in one case you are specifying the level first (0.05) and asking what value of $\chi^2$ is significant beyond that level and in the other case you are starting from your obtained value of $\chi^2$ and asking what the critical value would have been.

  • $\begingroup$ So if I calculated the critical value for a p-value of $1.315 \times 10^{-48}$ , that is, same code as above, but a much smaller p-value: stats.chi2.ppf(q = (1-1.3153258948574585e-48), df = 2) - the result would be 220.5 ? In other words, I can skip the critical-value calculation, thanks to Python's giving me the associated p-value for a chi-squared calculation, which allows me to decide if the p-value is sufficiently low; doing the critical-value calculation for a higher p-value is redundant. $\endgroup$ Commented Apr 9, 2019 at 16:28
  • $\begingroup$ But this: stats.chi2.ppf(q = (1-1.3153258948574585e-48), df = 2) produces output of inf ( I was expecting output of 220.5) And this: stats.chi2.cdf(220.5, 2) produces output of 1.0 (I was expecting output of 1.315...e-48 I'm not sure why scipy pdf(...) and cdf(...) cannot calculate the critical value / p-value for a very low p-value (do inf/1 respectively), but the chisquare(...) can calculate it, $\endgroup$ Commented Apr 9, 2019 at 17:05
  • $\begingroup$ Either way I think I understand what @mdewey is saying re: my questions 1) these p-values are both p-values , 1a) They don't have the same value because the 0.05 specifies the acceptable p-value first, whereas the 1.31e-48 produces the p-value, and then you decide if it's acceptable. 2) I can skip the critical value calculation, if I get the p-value of the chi-squared calculation $\endgroup$ Commented Apr 9, 2019 at 17:08
  • 1
    $\begingroup$ Infinity probably means it gave up or is a programming error and the other one is giving you the tail you did not expect. I do not use whatever software it is you are using so cannot help with how you reverse it. $\endgroup$
    – mdewey
    Commented Apr 9, 2019 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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