How can I calculate what observation characterizes the relationship of two variables?

I have two variables.

1. The prevalences of infection with Schistosoma (positive, negative)
2. Different occupations in a rural area in central Africa (Fishermen, Farmers, Traders, Craftsmen)

I found that there is an association between risk of infection and occupation with a chi-squared test. My question is: Which occupation mainly contributes to the association? How can I find it?

The table with data is:

           Fishermen    Farmers  Traders  Craftsmen
positive          21         20       17         16
negative          15         23       43         15

• One small point: in displaying contingency tables, distinctions are made between the response (ve) and the predictors (occupation). Responses are typically displayed in the column with predictors in the rows. – Mike Hunter Nov 16 '15 at 12:18
• @DJohnson: Making a contingency table doesn't imply you're thinking of one variable as a response & the other as a predictor. And why not predict occupation from infection? – Scortchi - Reinstate Monica Nov 16 '15 at 16:05
• @scortchi I agree that these features are theoretically reversible but I would be surprised that anyone would attempt the analysis you're proposing since it simply doesn't make any sense. Having worked with contingency tables for some time, I was merely pointing to a convention or rule of thumb that I've observed over the years. – Mike Hunter Nov 16 '15 at 16:08
• @DJohnson: Makes sense, though less likely: my point's rather that a convention that relies on you deciding which variable should be the predictor & which the response in a regression you may have no intention of performing is perhaps not worth following. I wasn't aware of a convention in any case - when I Googled I found that Miller & Brewer, The A-Z of Social Research, p46, say the opposite:-"The convention in presenting a contingency table is that the independent variable is placed along the top as the column variable & that the dependent variable becomes the row variable". – Scortchi - Reinstate Monica Nov 16 '15 at 16:52
• I agree with @scortchi. Banal limitations of space and readability often rule here. For example, a response with few categories and a predictor with several will almost always in my experience be tabulated with the response running across rows. It would be perverse to do it otherwise. A simple and common example is many questions, all of which are answered on a five-point scale. (Even the convention of response on a vertical axis in a scatter plot is not immutable: environmental scientists interested in variations with depth or height will happily use that for vertical axis.) – Nick Cox Nov 16 '15 at 20:15

If you do the calculation by hand, you will be able to identify which cells have the largest values of the chi-square stat (obs - exp)^2 / exp.

In your example, traders will show up as the largest deviation indicating the possible existence of an association when compared to other professions.

• (+1) The signed square root of that quantity is often calculated - it's called the Pearson residual. – Scortchi - Reinstate Monica Nov 17 '15 at 9:27

To produce the output below in SPSS, I arranged the data in two columns (long form), and coded occupations as 1=fishermen, 2=farmers, 3=traders, 4=craftsmen. The variable name is IVOcc (short for "Independent variable, occupation").

Thank you Arun Jose for interpreting it. He wrote: “Any time you use a categorical variable with "n" levels, you only require "n-1" dummy variables as they are compared to one used as a reference. In your example, occupation 4 is taken as a reference and the other three coefficients indicate if the occurrence of infection is higher or lower when compared to craftsmen. Traders with -.993 at a p-value of .031 is the only variable that shows an association in this case. The other two occupations are not significant as they have high p-values.”

Have a look at the answers provided to this question, which poses a similar problem: stats.stackexchange.com/q/82454/95070

• The null hypotheses in a chi-square test: there exists no difference between occupations to the risk of contracting the disease. The chi-square value being large for traders suggests that this group is different compared to the others. On inspection of what the classes actually are, we can infer that this indicates that traders contract the infection "less often" compared to the other professions. – Arun Jose Nov 16 '15 at 14:23
• @Arun is right: the question asks only about an "association," not about whether one or more groups appear to have unusually high positive prevalences. – whuber Nov 16 '15 at 22:03
• Ah, you're right, of course. Hey, can either of you provide some guidance about the output of my regression, above? I arranged the data in two columns, long form, and coded occupations as 1=fishermen, 2=farmers, 3=traders, 4=craftsmen. The variable name is IVOcc (short for "Independent variable, occupation"). I am confused about why I can only see IVOcc 1, 2, and 3. – jUST1N3 Nov 17 '15 at 0:38
• Any time you use a categorical variable with "n" levels, you only require "n-1" dummy variables as they are compared to one used as a reference. In your example, occupation 4 is taken as a reference and the other three coefficients indicate if the occurrence of infection is highler or lower when compared to craftsmen. Traders with -.993 at a p-value of .031 is the only variable that shows an association in this case. The other two occupations are not significant as they have high p-values. – Arun Jose Nov 17 '15 at 8:49
• Thanks, that's helpful! I ran it as logistic regression. – jUST1N3 Nov 18 '15 at 11:15

It isn't necessarily the case that any particular cell "characterizes" the relationship. That isn't what you're doing. The chi-squared test for independence checks to see if the two variables as a whole are associated. It is slightly improper to think of a single cell as unrelated / distinct from the other levels of a given categorical variable, or that that cell is where the association 'exists'. However, it is perfectly reasonable to want to know which cells diverge the most from the counts you would expect under independence and thus contribute the most to the significance of the test. I'm pretty sure that's what you're asking. Bear in mind that if one cell is higher, (an)other cell(s) must be lower to compensate, so in some real sense the effect must exist in multiple cells.

@ArunJose and @Scortchi are correct that Pearson residuals are typically used to examine this. It may be helpful to visualize them, though. A way to do that is to use a mosaic plot that colors the cells based on the residuals. Here is an example using your data, coded in R:

d = read.table(text="stuff      Fishermen    Farmers  Traders  Craftsmen
positive          21         20       17         16
negative          15         23       43         15", header=T)

tab = as.table(as.matrix(d[,2:5]))
rownames(tab) = d[,1]
names(dimnames(tab)) = c("Schistosoma", "Ocupation")
#            Ocupation
# Schistosoma Fishermen Farmers Traders Craftsmen Sum
#    positive        21      20      17        16  74
#    negative        15      23      43        15  96
#    Sum             36      43      60        31 170
chisq.test(tab)
#   Pearson's Chi-squared test
#
# data:  tab
# X-squared = 9.8257, df = 3, p-value = 0.02011
chisq.test(tab)\$residuals
#            Ocupation
# Schistosoma  Fishermen    Farmers    Traders  Craftsmen
#    positive  1.3462838  0.2964026 -1.7840859  0.6821634
#    negative -1.1819983 -0.2602329  1.5663759 -0.5989198
windows()