# Error message in logistic regression model [duplicate]

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.

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

• 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").
– Sycorax
Commented Nov 23, 2022 at 4:40
• @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. Commented Nov 23, 2022 at 16:25
• @Sycorax Unfortunately the error still occurs Commented Nov 23, 2022 at 16:38