fitting a logistic regression model.

rotenone <- data.frame(dose=factor(c("high", "medium", "low")),
                       affected=c(44, 24, 0),
                       total=c(50, 46, 49))
rotenone_logit_mod <- glm(affected ~ 1 + dose, data = rotenone, family = binomial(link = "logit"))

above is my code for comparing the proportion of affected insects in the three groups by fitting a logistic regression model.

but the error is:
"Error in eval(family$initialize) : y values must be 0 <= y <= 1"

can someone please help me fix the problem?
thank you

A logistic regression is for a continuous independent variable(s) and a binary response. Your independent variable is categorical, so logistic regression is not appropriate.

1 Like

the binomial glm generally expects data in an Untable'd form. Instead of affected and total, you would want a long data structure with two variables: dose and affected where affected is 0/1 for affected (1) or unaffected (0) with 44 affected and 6 unaffected for high, etc.. But, in this case, you have "separation", low is going to have an infinite "slope" because it perfectly predicts unaffected (0). Firth (1993) is the canonical solution for that part of the problem though there is other work on the question of separation.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.