Meaning of Chi-squared test output

I have an interaction table with plants species (column) and the number of time each plant has been found to live in each environment (row).

I'd like to know if there is a differential "preference" for plants species to live in different environment. I guess I should run a chi squared test. I'd need some help to make sense of the output.

The greatest is the residual, the biggest is the "preference" of one plant species to its environment. Is it correct?

The p.value gives the proportion of times that we would find such extreme pattern if all species would have no "preference" of environment. Is it correct?

What if I'd like to have such p.value for each plant species. Should I run a chi-squared test for each plant species independently? Or is there some kind of post-hoc test of the chi-squared test?

I don't think you want chi-square at all. I think you want some form of count regression (possibly Poisson or negative binomial). You have a model

Number of plants ~ environment + species (maybe + interaction)

where both of the independent variables are categorical. The above model would allow you to see overall effects of environment and species as well as the effect at each level of each variable.

• Thanks for your answer. Why would the chi-squared test not be suitable for this kind of data and question? Nov 20, 2013 at 14:18
• First, Chi-square looks for any association between two categorical variables. It doesn't posit a dependent variable, and you have one. Second, chi-square doesn't allow testing which species has which effect (at least, not in its standard form) and this is your question of interest. Nov 20, 2013 at 14:22

Assuming a two-way table of species $\times$ environments, then so-called Pearson residuals can be defined for the frequencies in the table as $(\text{observed} - \text{expected}) / \sqrt{\text{expected}}$, which relate well to a chi-square test because the chi-square statistic is the sum of the squared Pearson residuals. You are perhaps more likely to get these residuals out of a model-fitting command, function or routine than one for cross-tabulation, but that depends on your software. From the definition of the residuals, large positive residuals indicate preference and large negative residuals indicate avoidance, relative to the expectation of no association.

Otherwise:

1. It is difficult to know what you imagine a test for each species would look like.

2. Your interpretation of P-value is essentially right.

3. A more general framework for this analysis is loglinear (Poisson) modelling or some other flavour of count regression, as @Peter Flom points out. That allows more elaborate tests and would be needed to test more complicated hypotheses, especially those specifying interactions between species and environment.