I am currently try to analyse differences in the number of individuals of certain insect species (factor: 2 levels - HA, AP) that reached a particular life-stage from the egg stage (e.g. 1st instar) at a range of different temperatures (factor: 5 levels - 20, 23, 26, 29, 32 degrees Celsius). I have data on the numbers of dead vs survived as well as the proportions of individuals that survived to each life stage.

I am trying to understand which analysis method I should use with this data and, given that both explanatory variables are factors, I thought that I should use a contingency table and Chi-squared test. However, I have only ever tried using a Chi-squared test with one factor and I am wondering if it is possible to complete a Chi-squared test when there are two explanatory variables (and also how might I do this in R). I did think that perhaps I should combine them into a single explanatory variable but I am not sure.

Also, if I can do this test, is there a way I can determine if the interaction between the two factors is significant. Also, is there a way I could gain within and between species comparisons between temperatures.

Any help that could be provided would be greatly appreciated.

Edit 1:

Here is a sample of the data for the duration of the egg stage to give a better understanding. Prop.egg.to.1st is the proportion of the added eggs that hatched into 1st instar larvae. I have similar data sets for the proportion reaching the 2nd instar from the egg stage, 3rd instar from the egg stage etc. I also have similar data (not shown) detailing the proportion moving from the egg to the 1st instar, 1st instar to 2nd instar, 2nd instar to 3rd instar etc.

Temperature  Species No.eggs.added No.hatched Prop.egg.to.1st
20           AP      56            37                    0.66
23           AP      69            61                    0.88
26           AP      139           65                    0.47
29           AP      162           94                    0.58
  • 1
    $\begingroup$ I haven't read your question very carefully, but it seems to me that you want to fit a glm with Poisson, negative binomial, or (quasi)binomial family. Fitting an interaction effect is then straightforward. Maybe posting a toy example dataset would help people answer. $\endgroup$
    – dariober
    Nov 10, 2022 at 15:00
  • $\begingroup$ Is there more than one life-stage transition involved here? That would make a difference in how you could approach this. It would help to show some example data. A chi-square test can be used for overall evaluation of multiple-dimension contingency tables, but you need further analysis for evaluating specific interactions. As @dariober said you want to use a regression model of some type, but details depend on the nature of your data. $\endgroup$
    – EdM
    Nov 10, 2022 at 17:51
  • $\begingroup$ @EdM I have added a sample of the data if this helps $\endgroup$ Nov 10, 2022 at 19:43

1 Answer 1


For each of the transitions, you are asking how the combinations of temperature and species influence the probability of moving to the next stage. Binomial regression can evaluate how variables are associated with the probability of an event. There are several flavors of binomial regression, with logistic regression the usual choice. This UCLA web page shows how to implement that in R.

A form you might use for the data you display would be:

yourModel <- glm(cbind(No.hatched,No.eggs.added-No.hatched) ~ 
  Temperature * Species, data=yourData,
   family = binomial(link="logit"))

That uses the actual numbers of successes and failures in each situation as the outcomes. It's important to keep track of the numbers, as the reliability of an estimated proportion increases with the number of observations.

The model evaluates the associations of Temperature, Species, and their combination (an interaction term) with the log-odds of success. It turns out that the test of overall significance of that model is closely related to what you would get with a chi-square test on a multi-dimensional contingency table, but the regression gives you the information needed to explore the model predictions in detail. Regression also allows you to evaluate continuous predictors--for example, if you wanted to model Temperature as continuous rather than as as a factor.

As these are successive transitions to higher states of development, you might consider ordinal logistic regression if you started with a certain number of eggs in each condition and kept track of how many got to each successive stage. That might require some reformatting of your data, but it might be more efficient if you think that the combined effects of Temperature and Species are similar for each successive transition.

You then can use post-modeling tools like those in the R emmeans package to examine specific combinations of Temperature and Species and to express results in terms of probabilities instead of in the log-odds scale used in logistic regression.

  • $\begingroup$ For each combination of species and temperatures I have data on the numbers reaching each lifestage from the egg stage as well as the number of individuals reaching next life stage from the previous e.g. no moving from egg to 1st, 1st to 2nd etc. If I were to complete an ordinal logistic regression would this mean treating life-stage transitions as a third explanatory variable that is ordinal or would this involve treating each transition as a separate explanatory variable and analysing them simultaneously? $\endgroup$ Nov 12, 2022 at 19:53
  • $\begingroup$ Also, would this enable me to extract information on the effects of temperature and sex on each life-stage transition individually? $\endgroup$ Nov 12, 2022 at 19:55
  • 1
    $\begingroup$ @Ladybird_biologist if you set this up as an ordinal regression, you would use the stage reached as the outcome variable, coded as an ordered factor. That would, however, give you a single set of coefficients that are the same for all transitions. If you want to model each transition separately, set up a series of logistic regressions similar to what I show, with the successes and failures restricted to the numbers that were available to make each transition. See "sequence of binary models" on this Penn State STAT 504 web page. $\endgroup$
    – EdM
    Nov 13, 2022 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.