# Chi-square using factors with multiple levels in R

I'm not sure if I have the right concept of how to perform the chi-square test. I have a variable called race which is a factor with multiple levels for different races, and I would like to see whether there is a correlation between each race and the response variable (mortality). If I were to perform chi-square like:

chi.race <- chisq.test(mortality, race)


then it gives me an output like:

Pearson's Chi-squared test
data:  mortality and race
X-squared = 4.9626, df = 9, p-value = 0.8376


but it doesn't tell me anything about the correlation between each level in race (e.g. White, Black, Asian, Hispanic, etc.) and mortality.

What am I doing wrong and/or what is wrong with my concept of chi-square? Thanks for the help.

• Can you describe how the mortality variable is organized or give a sample table of counts (doesn't have to be identical to your data)? – Glen_b -Reinstate Monica Nov 20 '13 at 5:25
• You could take a look at chi.race$residuals and chi.race$stdres. See formulas at stat.ethz.ch/R-manual/R-patched/library/stats/html/…. These values are basically going to give you the contribution of each cell to the total chi squared. – Patrick Coulombe Nov 20 '13 at 6:05

The chisquare is a hypothesis test for differences from independence in the counts in your table.

If you want to test that you're probably not doing anything wrong.

You can produce a table of contribution to chi-square or a table of Pearson residuals which help to identify which parts of the table contribute most to the differences.

However, it sounds what you're actually interested in is a different question, perhaps more like an effect size type estimate.

It sounds like mortality may be ordered, is that right? Or is it just two categories (like 'alive, dead')?

In the second case you could order them by proportion in one or the other category and produce a display, including something related to a standard error of proportions, if you wanted to see which ones were most clearly different.

I think you probably want a regression model. Surely mortality is a dependent variable here, and it seems like you want to examine the effect of race on it.

What sort of regression model depends on how mortality is recorded. It could be a (regular) logistic regression, an ordered logistic or possibly a survival model.

As for a simple display, it seems like a mosaic plot would be good.