# Interpreting residuals in chi-squared test

Newbie statistician looking for help...

I'm trying to determine whether birds in two different area have different diets, based on 8 categories of food items. Running a chi-squared test in R (using chisq.test()) gets me a beautiful, tiny p-value, indicating diet is indeed different between these areas. But I'd like to know how, exactly, they're different. I pulled the standardized residuals from the test using stdres which gets me this:

 corvid      grouse    thrush    mammal   squirrel   unknown       bird       hare
tz  2.065822  0.05288435 -2.659504  2.464809  0.3361617 -1.785988  0.4370721  0.8356943
cs -2.065822 -0.05288435  2.659504 -2.464809 -0.3361617  1.785988 -0.4370721 -0.8356943


First of all, is this the correct way to pinpoint which categories differ between the groups? And, in very plain and applied language, how do I interpret these residuals? Is it accurate, for example, to say that birds in the tz area consume many more corvids than expected? Can I safely say there is no significant difference in the amount of squirrels consumed between the two area? There doesn't seem to be a lot of material about using residuals with chi-squared tests and what's out there uses more technical language like which category "contributes most" which isn't super helpful when I'm trying to make a concrete ecological statement.

Thanks in advance!

Edit to clarify what is being counted: my birds are carnivorous raptors, so each count represents a prey item (like one squirrel or one thrush) eaten by some bird in that zone. Each bird can belong to only one zone, but each bird can consume any number of different prey items. The original dataset looks like this:

   corvid grouse thrush mammal squirrel unknown bird hare
tz     12      6     36     50      248      36   21    2
cs      0      2     24      7       84      20    6    0


p.s. I know the counts for some categories are a bit small, this is just a preliminary look and more data are coming :)

• Difficult to explain this clearly without the $2\times 8$ contingency table of counts you used as input to chisq.test. Can you add it to your question? Nov 11, 2020 at 11:04
• Can you clarify what it is that you are counting? Do you have individual birds that you categorize as “this bird comes from area tz” and “has a diet which consists exclysively of corvid”? Or is it possible that the same bird can have a diet which includes both “corvid” and “mammal”, say? Also, you mentioned “amounts of squirrel” consumed by a bird - can you elaborate more on what you mean by that? The “type of diet” (e.g., corvid, mammal) is quite different from the “amount of diet”. Does your research question involved “type” or “amount” of diet? Nov 11, 2020 at 14:00
• Type of diet doesn't really make sense in this context because diet is diverse and overlap is high. ie, no population eats just squirrels or just thrushes, so you can't say there is a squirrel-type diet or a thrush-type diet. I'm interested in whether the population of one area eats, say, more thrushes and less squirrels than the other area, which could be phrased as amount, though perhaps percent or proportion would be more accurate. Hope that clarifies! Nov 12, 2020 at 17:31

## 1 Answer

Looking at your residuals table you are actually considering more species than birds alone. Nasty little buggers won't let your feeding trays alone?

Seriously though, personally I usually compare the observed table with the expected table directly to see where the changes are (provided of course that I have reasons to reject the null hypothesis of independence). I find that easier to interpret. Both are available in the test output of R. Of course whether a difference is large is hard to tell from absolute counts, but it will give you some sense where the differences are.

The stdres gives you the standardized residuals. They are basically a standardized measure of effect size.

If you think of the standard normal distribution (with mean 0 and standard deviation 1) you probably know that within such a distribution values larger than +2 or smaller than -2 only occur in 5% or less.

If your sample is large enough the stdres follow approximately a standard normal distribution and therefore stdres of value |2| or larger occur in 5% or less of all possible samples. In other words these are the differences that are "large" and have made the p-value of your chi square small.

In your case the dependency seems to be driven mainly by corvid, mammals and thrush.