0
$\begingroup$

I am trying to understand how both temperature (factor: 6 levels - 20, 23, 26, 29, 32, 35 degrees Celsius) and species (factor: 2 levels HA and AP) affects the likelihood of moving from one life stage to the next (in this case from the 2nd instar to the 3rd) using a logistic regression model as below:

X3rdmodelA <- glm(cbind(No.3rd,No.2nd-No.3rd) ~ Temperature * Species, data=X2ndto3rd, weights = No.2nd, family = binomial(link="logit"))

When I try to run the model the following error appears:

Warning message:
glm.fit: algorithm did not converge

Would anyone be able to tell me why this error might be occurring and what I may do to fix it.

Below is the data I am using if this is helpful:

Temperature  Species  No.2nd  No.3rd
20           AP       32      30
23           AP       53      50
26           AP       46      39
29           AP       72      66
32           AP       38      32
35           AP        3       7
20           HA       41      41
23           HA       48      42
26           HA      117     113
29           HA       89      87
32           HA       42      42
35           HA       59      39

Any help anyone could provide would be greatly appreciated.

$\endgroup$
1

1 Answer 1

1
$\begingroup$

Are you sure you've specified the model correctly

library(data.table)
dt <- fread("Temperature  Species  No.2nd  No.3rd
20           AP       32      30
23           AP       53      50
26           AP       46      39
29           AP       72      66
32           AP       38      32
35           AP        3       7
20           HA       41      41
23           HA       48      42
26           HA      117     113
29           HA       89      87
32           HA       42      42
35           HA       59      39")
dt[, Temperature := factor(Temperature)]
mdl <- glm(cbind(No.3rd, No.2nd) ~ Temperature * Species
           , data = dt
           , family = binomial)

works for me.

Note ?glm says

For binomial and quasibinomial families the response can also be specified as a factor (when the first level denotes failure and all others success) or as a two-column matrix with the columns giving the numbers of successes and failures.

For a binomial GLM prior weights are used to give the number of trials when the response is the proportion of successes

$\endgroup$
4
  • $\begingroup$ This explanation is plausible because the row 35 AP 3 7 suggests that OP has 7 successes and $3-7=-4$ failures, according to their code. I don't think this makes sense. Alteratnively, there could be a data entry error in that row (perhaps it's supposed to have 30 or 13 instead of 3), but the code is otherwise correct ("a two-column matrix with the columns giving the numbers of successes and failures"). $\endgroup$
    – Sycorax
    Nov 23, 2022 at 4:40
  • $\begingroup$ @Sycorax My mistake the 7 should actually be a 1 so only 1 individual, out of three that reached the 2nd instar, then went on to reach the 3rd instar. $\endgroup$ Nov 23, 2022 at 16:25
  • $\begingroup$ @Sycorax Unfortunately the error still occurs $\endgroup$ Nov 23, 2022 at 16:38
  • $\begingroup$ @Ladybird_biologist I think the issue is separation. The linked threads address this $\endgroup$
    – Sycorax
    Nov 23, 2022 at 18:08

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