# How does one calculate the p value for a two tailed chi square test with degree freedom of 1?

How does one calculate the p value for a two tailed chi square test with degree freedom of 1?

prop.test(matrix(c(9,17,5,13), nrow = 2), correct = F)
2-sample test for equality of proportions without continuity correction

data:  matrix(c(9, 17, 5, 13), nrow = 2)
X-squared = 0.22922, df = 1, p-value = 0.6321
alternative hypothesis: two.sided
95 percent confidence interval:
-0.2311216  0.3835026
sample estimates:
prop 1    prop 2
0.6428571 0.5666667


With chisquare statistic of 0.22922 I get a cumulative distribution density of 0.36 with this code

pchisq(0.22922, df=1, lower.tail = T)


I don't think I could just 2*0.36 since it's not a normal distribution... how do I find the complementary of the upper tail so that the number will be equal to 0.6321 as shown by prop.test?

• Did you try pchisq(0.22922, df=1, lower.tail = F) ? Commented Apr 14, 2023 at 18:42

In most cases, one does not calculate the p-value for a two-tailed chi-square test. In most cases, one computes two-tailed p-values from PDFs symmetric around the mean (e.g., normal or Student's t). Exceptions are provided in comments below.

With df $$< 90$$ the chi-square PDF is not symmetric, it is skewed to the right. To get the 0.6321 (the upper tail), one would do:

1 - pchisq(0.22922, df=1, lower.tail = T)

which yields an identical result as:

pchisq(0.22922, df=1, lower.tail = F).

That is, upper and lower tail add up to 1, by definition.

In response to your comment below, about the prop.test function giving a different result for the following 2x2 table of counts (successes in 1st, failures in 2nd column; group 1 in 1st, group 2 in 2nd row):

O <- matrix(c(9, 5, 17, 13), nrow = 2)
O
[,1] [,2]
[1,]    9   17
[2,]    5   13


With prop.test, this can be tested in a one-sided manner (prop. in first group is larger than in second group, vice versa), or in a two-sided manner (proportions are not equal between groups). The latter can be tested using a chi-square distribution, where the expected counts (given the null hypothesis of equal group counts) are compared with observed counts ($$\sum \frac{(O-E)^2}{E}$$). Expected counts under a null-hypothesis of equal proportions (14 successes out of 44 trials, 26 trials out of 44 in first group) would be:

E <- matrix(c((14/44)*c(26, 18), (30/44)*c(26, 18)), nrow = 2)
E
[,1]     [,2]
[1,] 8.272727 17.72727
[2,] 5.727273 12.27273

sum((O - E)^2/E)
[1] 0.2292226


Note how this quantity evaluates the difference between expected and observed (thus, a two-sided test), not whether the observed number of successes is higher or lower in one group than the other (a one-sided test). It thus yields the same result as:

prop.test(O, nrow = 2), correct = F, alternative = "two.sided")

2-sample test for equality of proportions without continuity correction

data:  O
X-squared = 0.22922, df = 1, p-value = 0.6321
alternative hypothesis: two.sided
95 percent confidence interval:
-0.2077665  0.3445186
sample estimates:
prop 1    prop 2
0.3461538 0.2777778


Note that if one specifies a one-sided test for equal proportions (alternative = "less" of alternative = "greater"), the same test statistic is used (i.e., same value for X-squared is reported). However, under the hood the code then uses the square root of the test statistic and a normal distribution to obtain the p-value:

pnorm(sqrt(0.22922), lower.tail = TRUE)
[1] 0.6839486
pnorm(sqrt(0.22922), lower.tail = FALSE)
[1] 0.3160514


Because if $$Z$$ follows a standard normal distribution, then $$Z^2$$ follows a chi-square distribution with one degree of freedom.

• A good answer in general, but the following statement seems to me to be incorrect: "One can compute two-tailed p-values only from PDFs symmetric around the mean...".
– Ben
Commented Apr 14, 2023 at 23:30
• -1. The first three sentences do not make much sense to me. You can obtain a two-tailed p-value for an asymmetric distribution (including $\chi^2$) and the $\chi^2$ distribution does have two tails. Commented Apr 15, 2023 at 8:08
• @RichardHardy Indeed you can but usually you do not do so in most chi squared tests, unless your alternative hypothesis is that the experimenter cheated and fixed the results to be closer to the assumed distribution than were actually observed Commented Apr 15, 2023 at 17:34
• @Henry, I have used two-tailed chi-squared tests when assessing i.i.d. random number generators (RNGs). A RNG that generates numbers forming certain patterns are no good, but so are those that output number without patterns that would occur naturally (too good to be true). E.g. a "coin" that delivers exactly 50% heads in every sample is suspect. I bet there are other sensible uses of two-tailed chi-squared tests, too. Commented Apr 15, 2023 at 18:19
• @Richard The symmetry I refer to is not symmetry in shape, but symmetry in probabilities. The critical region in such cases is chosen to include half the probability in the upper tail and half in the lower tail.
– whuber
Commented Apr 16, 2023 at 19:11