TITLE: Comparison of bird diet at two different nests
QUESTION [4 upvotes]: I have a list with the different prey types and quantities that birds at Nest $1$ gave to their fledglings. I also have the same information for another nest of the same bird species.
Suppose I have
NEST 1
Mammals: 500
Arthropods: 200
Birds: 20

NEST 2
Mammals: 180
Arthropods: 50
Birds: 3

Can I use the Chi-squared test to demonstrate the diets are actually very similar (or maybe not similar)?
Of course, my actual data is more complex, with more classes (to family level).

REPLY [2 votes]: Your idea to do a chi-squared test of homogeneity
seems correct. I put the fictitious data of
your question into a contingency table in R:
nest.1 = c(500, 200, 20)
nest.2 = c(100, 50, 3)
TAB = rbind(nest.1, nest.2)
TAB
       [,1] [,2] [,3]
nest.1  500  200   20
nest.2  100   50    3

Then R does the chi-squared test, as shown below.
Or it is not difficult to do on a calculator.
chisq.test(TAB)

        Pearson's Chi-squared test

data:  TAB
X-squared = 1.6849, df = 2, p-value = 0.4307

Warning message:
In chisq.test(TAB) : 
 Chi-squared approximation may be incorrect

As you may know, the chi-squared test statistic
is computed using the observed counts in TAB
along with expected counts computed using the
marginal totals of TAB according to the null
hypothesis that the two nests have the same
proportions of food categories. If any of the
expected counts are smaller than $5$ the chi-squared statistic may not have the intended
chi-squared distribution, and thus the P-value
may be misleading.
For your data the the expected counts can be
displayed as follows:
chisq.test(TAB)$exp
           [,1]      [,2]      [,3]
nest.1 494.8454 206.18557 18.969072
nest.2 105.1546  43.81443  4.030928
Warning message:
In chisq.test(TAB) : 
 Chi-squared approximation may be incorrect

Because only one of the expected counts is
below $5$ and it is above $3$ the P-value
$0.53 > 0.05 = 5\%$ is likely OK, indicating
no evidence that the two nests differ as to
relative frequencies of food categories. (Many statisticians would
trust the P-value, if most counts are below $5,$
but none below $3.)$
However, as implemented in R, chisq.test can
simulate a more accurate P-value when there is an error message. If you need
to do this with your real data, the procedure
is as below. (I would always do the simulation
anytime there is a warning message, just to be
sure. The simulation method in R is carefully
implemented and I have found it to be trustworthy.)
chisq.test(TAB, sim=T)

        Pearson's Chi-squared test 
        with simulated p-value 
        (based on 2000 replicates)

data:  TAB
X-squared = 1.6849, df = NA, p-value = 0.4233

This may be necessary if you have more food
categories (some of which may have low counts).
I am not saying that a chi-squared test of
homogeneity is the only way to analyze your
data, but it is s very commonly used method
and will be understood by most people reading
an account of your study.
Note: As such questions go, I think your project is very well explained (+1) and the best method
of analysis is pretty obvious. However, in future. if you have questions that are more
about statistical practice than about mathematical
statistics, I would suggest posting on
stats.stackexchange.com where experienced
moderators and knowledgeable applied statisticians regularly comment on the validity of Answers.
{"set_name": "stack_exchange", "score": 4, "question_id": 4346784}