I know that I can determine the correlation / association / dependency between two variables (X= smoker, and Y=cancer) using chi-squared with a 2x2 contingency table:

        Y=yes   Y=no
X=yes     n11    n12
X=no      n21    n22


  • n11 is the number of times when X happened, Y also happened
  • n12 is the number of times only X happened
  • n21 is the number of times only Y happened
  • n22 is the number of times when X did not happen, Y also did not happen

Then I follow the chi-squared calculation:
$$ \chi^2 = \sum\frac{(\rm observed - expected)^2}{\rm expected} $$

But what if: instead of one outcome Y, I have more than one outcome? For example: y1=cancer, y2=irregular heartbeat, y3=High blood pressure, etc. How can I represent these in contingent table?


This is actually a pretty advanced topic. There are a couple of possible shortcuts. If all Y variables are independent, you could simply run several chi-squared tests. You could also collapse your Y variables into a single new Y variable with 8 levels (y1-no; y2-no; y3-no, y1-no; y2-no; y3-yes, y1-no; y2-yes; y3-no, etc.) and run a chi-squared test on the 2x8 contingency table. Neither of these are likely to be very satisfactory, however.

The preferred analysis is to construct a multi-way contingency table, and fit a log-linear model. The contingency table that you present is a two-way table with counts in rows and columns. With one X and three Y variables, you would have a four-way contingency table, where each cell holds the count of the number of times that combination of X, Y1, Y2, and Y3 values happened. Since it is hard to visualize a four-way table, it might also be convenient to display it as a flat table:

x-no;  y1-no;  y2-no;  y3-no:   n1111
x-no;  y1-no;  y2-no;  y3-yes:  n1112
x-no;  y1-no;  y2-yes; y3-no:   n1121
x-no;  y1-no;  y2-yes; y3-yes:  n1122
x-no;  y1-yes; y2-no;  y3-no:   n1211
x-no;  y1-yes; y2-no;  y3-yes:  n1212
x-no;  y1-yes; y2-yes; y3-no:   n1221
x-no;  y1-yes; y2-yes; y3-yes:  n1222
x-yes; y1-no;  y2-no;  y3-no:   n2111
x-yes; y1-no;  y2-no;  y3-yes:  n2112
x-yes; y1-no;  y2-yes; y3-no:   n2121
x-yes; y1-no;  y2-yes; y3-yes:  n2122
x-yes; y1-yes; y2-no;  y3-no:   n2211
x-yes; y1-yes; y2-no;  y3-yes:  n2212
x-yes; y1-yes; y2-yes; y3-no:   n2221
x-yes; y1-yes; y2-yes; y3-yes:  n2222

A log-linear model is essentially a Poisson regression model that compares models that take various combinations of the variables into account and compares their fit to the saturated model. If you use R, there is a nice tutorial here.

  • $\begingroup$ Thank you so much for all your help and useful information. What I did is: I built 2x2 contingency table, x-yes; (y1, and y2, and y3)-yes: n11 x-yes; (y1, and y2, and y3)-no: n12 x-no; (y1, and y2, and y3)-yes: n21 x-no; (y1, and y2, and y3)-no: n22 I guess i did wrong $\endgroup$ – phoenix Mar 29 '15 at 14:32
  • $\begingroup$ @phoenix, that's right: a chi-squared test is not appropriate for your data. You need to use a log-linear model. What software are you using? $\endgroup$ – gung - Reinstate Monica Mar 29 '15 at 14:37
  • $\begingroup$ I wrote my program using Java $\endgroup$ – phoenix Mar 29 '15 at 14:40
  • $\begingroup$ @phoenix, Oh, OK. I don't know if there are statistical libraries in Java for log-linear models. You may have to code it up from scratch (which will be very difficult). Or you could use some other software (like R). $\endgroup$ – gung - Reinstate Monica Mar 29 '15 at 14:43
  • $\begingroup$ Thank you, the reason I did that, I read a paper and they gave a solution using a chi-squared test for combined (X's), so I thought it will be the same (statistically) for combined (Y's): [1]: store2.up-00.com/2015-03/1427642138361.png $\endgroup$ – phoenix Mar 29 '15 at 15:19

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.