Chi-squared test for equality of proportions

This question is question 12 from Problems 10.3 from Rohatgi's An Introduction to Probability and Statistics.

Of 25 income tax returns audited in a small town, 10 were from low and middle income families and 15 from high-income families. Two of the low-income families and four fo [sic] the high-income families were found to have underpaid their taxes. Are the two proportions of families who underpaid taxes the same?

I have written the observed values: $$\begin{bmatrix}2 & 4 \\ 8 & 11 \end{bmatrix}.$$ The first column is the Lower and Middle income and the second column is High-income familities. The first row is the number who underpaid the taxes and the second row is the number who did not underpay taxes.

I define random variables. Let $$X \sim \text{Bin}(10,p_1)$$, $$Y \sim \text{Bin}(15,p_2)$$ be the number of families who underpaid the taxes (lower-middle and high-income familities respectively). I can frame my problem as the test of hypotheses $$H_0: p_1 = p_2$$ and $$H_1: p_1 \neq p_2$$.

Under $$H_0$$, the MLE of the common proportion $$p$$ is $$\hat{p}=6/25$$. I can then compute the expected values: $$\begin{bmatrix}2.4 & 3.6 \\ 7.6 & 11.4 \end{bmatrix}.$$

Using R code, I computed the Pearson's chi-squared test statistic:

x = c(2,4,8,11)
e = c(2.4,3.6,7.6,11.4)
Q = sum((x-e)^2/e)
Q
pchisq(Q,1,lower.tail = F)
[1] 0.1461988
[1] 0.7021947


I used 1 as the number of degrees of freedom computed from $$(c-1)(r-1) = (2-1)(2-1) = 1$$.

However, the correct p-value using this method should be 0.5447 according to the book.

• What value does the book give for $Q$? Knowing that will help us isolate the discrepancy in either the computation of the statistic or of its p-value. BTW, you can check your result against the built-in chi-squared test with chisq.test(matrix(Q, 2), correct = FALSE).
– whuber
Dec 5, 2022 at 21:38
• It doesn't give a value for $Q$ unfortunately. I tried to run the command and it gave the following: Pearson's Chi-squared test data: matrix(matrix(x, nrow = 2, byrow = TRUE), 2) X-squared = 0.1462, df = 1, p-value = 0.7022 Which seems to match my calculation. Can I ask: why is the input for the first argument matrix(Q,2)? Dec 5, 2022 at 21:54
• Sorry, I see you are using x for your data -- but you figured that out. The manual page for chisq.test explains why you need to format the data as a contingency table rather than as a vector.
– whuber
Dec 5, 2022 at 21:58
• For your matrix, the expected values and p-value are correct. As I interpret the question, your matrix is correct also. It's possible the answer in the book is wrong, or they used a different approach for the analysis. Dec 5, 2022 at 22:20
• Thanks a lot for your help! Dec 5, 2022 at 22:32

For your matrix, the expected values and p-value are correct. As I interpret the question, your matrix is correct also. It's possible the answer in the book is wrong, or they used a different approach for the analysis.

You can check this in R:

Input =("
Payment    Low   High
Underpaid    2      4
Paid         8     11
")

Matrix

###           Low High
### Underpaid   2    4
### Paid        8   11

chisq.test(Matrix, correct=FALSE)

### Pearson's Chi-squared test
###
### X-squared = 0.1462, df = 1, p-value = 0.7022

chisq.test(Matrix)\$expected

###           Low High
### Underpaid 2.4  3.6
### Paid      7.6 11.4


However, in general, for a 2 x 2 table, you may want to use Yates' correction, which is the default in R.

chisq.test(Matrix, correct=TRUE)

### Pearson's Chi-squared test with Yates' continuity correction
### X-squared = 4.3249e-32, df = 1, p-value = 1


Note that R has a chi-square test function specifically for proportions. In this case, it is the same as the 2 x 2 chi-square test of association with Yates' correction.

prop.test(x=c(2, 4), n=c(10, 15))

### 2-sample test for equality of proportions with continuity correction
### X-squared = 1.2535e-31, df = 1, p-value = 1
###
### sample estimates:
###    prop 1    prop 2
### 0.2000000 0.2666667


However, because the expected values are rather small, you may want to use Monte Carlo simulation, Fisher exact test, Barnard test, or Boschloo test.

chisq.test(Matrix, correct=FALSE, simulate.p.value=TRUE, B=10000)

### Pearson's Chi-squared test with simulated p-value (based on 10000 replicates)
###
### X-squared = 0.1462, df = NA, p-value = 1