I am working with a dataset the table form of which is as follows

  X                  y1             y2
  1                  68             138
  2                  10              30
  3 or More          11              14

Both Y and X are discrete. Y has two levels y1, y2. X has three levels 1, 2, 3 or more

The data is non-independent.

What is the most appropriate statistical test if my goal is to simply determine if X and Y are related or not ? Thanks.

This is what I mean by data is non-independent.

A person could respond twice or be counted twice. The person's response can be counted once under X=2, Y1 -> 10 and his second response can be counted under X=1, Y2 -> 138 cell.


1 Answer 1


Just from what you say, I would suggest a chi-squared test of independence. I assume you have 271 independently chosen subjects sorted into row and column categories as shown.

TBL = cbind(c(68,10,11),c(138,30,14));  TBL
     [,1] [,2]
[1,]   68  138
[2,]   10   30
[3,]   11   14

A chi-squared test of independence is computed in R statistical software as shown below. The P-value is $0.2824 > 0.05,$ so the null hypothesis (independence) cannot be rejected at the 5% level.

chi.out = chisq.test(TBL);  chi.out

        Pearson's Chi-squared test

data:  TBL
X-squared = 2.5291, df = 2, p-value = 0.2824

Observed counts are the counts in the six cells of TBL.

     [,1] [,2]
[1,]   68  138
[2,]   10   30
[3,]   11   14

Expected counts are computed under the assumption of independence. Look in your textbook or online to see the rationale for how this is done. Briefly, the expected count in the upper-left cell is found as row total times column total divided by grand total. That is. $\frac{206 \cdot 89}{271}\approx 67.65.$ All six, expected counts are shown below:

          [,1]      [,2]
[1,] 67.653137 138.34686
[2,] 13.136531  26.86347
[3,]  8.210332  16.78967

The Pearson residuals are of the form $R_{ij}=\frac{X_{ij} - E_{ij}}{\sqrt{E_{ij}}}.$ Roughly speaking they measure how well the observed counts $X_{ij}$ and the expected counts $E_{ij}$ agree in each of the six cells. The chi-squared statistic $Q = \sum_{i=1}^3\sum_{j=1}^2 R_{ij}^2 \approx 2.53.$ (Denoted X-squared in the output.)

In particular, $R_{11} = (68 - 67.653)/\sqrt{67.653} \approx 0.042.$

            [,1]        [,2]
[1,]  0.04217107 -0.02948994
[2,] -0.86538484  0.60515774
[3,]  0.97358112 -0.68081866

If the null hypothesis is true, then $Q \stackrel{aprx}{\sim} \mathsf{Chisq}(\nu = 2),$ where the degrees of freedom is $\nu = (r-1)(c-1) = (3-1)(2-1) = 2,$ (provided that there is enough data for all expected counts to exceed 5). In order to be significant at the 5% level, the test statistic $Q$ must exceed the critical value $c = 5.99.$

qchisq(.95, 2)
[1] 5.991465

If the null hypothesis were rejected (with $Q \ge 5.99),$ it would be worthwhile to look at the individual residuals. Residuals larger than about 2 in absolute value indicate cells in which there is especially poor agreement between observed and expected counts.

  • $\begingroup$ Is it possible to use a Cochran–Mantel–Haenszel chi-square test here? $\endgroup$
    – Nick
    Nov 20, 2019 at 0:58
  • 1
    $\begingroup$ @BruceET, i apologies the data is not independent. There are 267 unique subjects in this study. Some subjects responded twice. So their response is double counted and I have provided an example by updating my question above. Sorry for not making this obvious. $\endgroup$ Nov 20, 2019 at 3:07
  • $\begingroup$ Suggest you count the 271 - 267 = 4 double-counted subjects only once: Perhaps in the cell with only 10 observed counts, perhaps reduce the cell with 10 and the cell with 128 to 8 and 126 respectively. // Formally, that might make the chi-squared test 'legal', but results still would not be significant. (And in any formal presentation of the data, say what you did.) // In the future, try to plan so such double-counting can't occur. // The time to think about data analysis is before you start taking data. $\endgroup$
    – BruceET
    Nov 20, 2019 at 6:23
  • $\begingroup$ @BruceET, I agree. Thanks Bruce. $\endgroup$ Nov 20, 2019 at 14:18

Your Answer

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

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