Glm model not working. Giving the following errors.

I am trying to run a glm model to check the variation in the mass of cricket which could be affected by age(numeric), altitude(High or low), temperature(two different temperatures) and the incubators(4 different incubators) they are kept it.

I have tried the glm model which seems to be fine theoretically. The data on excel is all checked as well. I am assuming I have to convert some of the data into binary or some sorts.

glm(Mass ~ AltitudeWeighing +crick$Altitudecrick$square(Altitude)+ 1/Nymph.ID + 1/Population + Temperature*Altitude + 1/Incubator, data = crick)

Error in = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, :
NA/NaN/Inf in 'y'
In addition: Warning messages:
1: In Ops.factor(y, mu) : ‘-’ not meaningful for factors
2: In Ops.factor(eta, offset) : ‘-’ not meaningful for factors
3: In Ops.factor(y, mu) : ‘-’ not meaningful for factors

We don't really have enough info to help you out. Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

If you've never heard of a reprex before, you might want to start by reading this FAQ:

1 Like

What is the purpose of the variables in the model like 1/Nymph.ID? That almost looks like the way you'd code a random effect (1|Nymph.ID). The error could be coming from there, since you can't divide by a categorical variable (although I would expect the error to have / and not -).

If those should be random effects you will want to fit a linear mixed model (LMM) instead of the linear model (LM) that you are fitting now. The glm() function doesn't take random effects. A common package to use for complicated random effects in LMM's is lme4. For nested random effects see package nlme.

The other term that looks odd to me is crick$Altitudecrick$square(Altitude). I'm not certain what this term should be, but a binary Altitude variable can be included directly as a factor or a 0/1 variable. Also, you shouldn't need any dollar sign notation in the model, since you are using the data argument. If one of your variables isn't in the same dataset as the others, merging it in is a good idea.

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