Very new to R so please pardon my naivety. I am trying to run a sort of mixed effects nominal logistic regression model with my insect response data. I have 2 rearing treatments (hot and cold) and 3 replicates within each treatment (1,2,3,4,5,6) with data (1/0) for both males and females. Each individual was tested at up to 5 different temperatures. To start I am trying to compare responses by Sex, so comparing females across the 2 treatments. Currently I have this:

RandomFemales<-glmer(Called~ Treatment + Temp + Temp*Temp + Temp*Treatment + Temp*Temp*Treatment + DaysFromEclose + Temp*DaysFromEclose +Temp*Temp*DaysFromEclose + (1|Treatment/Rep) + (1|Rep/ID), data = Females, family=binomial, control = glmerControl(optimizer = "bobyqa"))

where temp*temp accounts for the quadratic shape of their activity curves across temperatures. DaysFromEclose is more or less time, since individuals were tested across several days.

Replicates are specific to the treatments (ie, 2,4,6 are Hot, 1,3,5 are Cold), so I assumed replicate would have to be nested within treatment, and individual ID nested within replicate to account for differences in individual response rate. The problem is that now it seems that Treatment is being treated as a random effect which it is not. Any thoughts? thank you! Update RE warnings:

 `Warning messages:
1: In optwrap(optimizer, devfun, start, rho$lower, control = control,  :
  convergence code 1 from bobyqa: bobyqa -- maximum number of function evaluations exceeded
2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
  Model failed to converge with max|grad| = 0.235779 (tol = 0.002, component 1)
3: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv,  :
  Model is nearly unidentifiable: very large eigenvalue
 - Rescale variables?;Model is nearly unidentifiable: large eigenvalue ratio
 - Rescale variables?`
  • $\begingroup$ Does that model converge without warnings ? The random structure does not makes sense. If ID is nested in Rep and Rep is nested in Treatment then you probably want Treatment/Rep/ID unless there is crossing . But then you have Treatment as a fixed effect, so that looks like a problem. I don't see why Treatment should be random, nor Rep for that matter, though I'm happy to be convinced otherwise :) $\endgroup$ – Robert Long Jun 30 '20 at 19:21
  • $\begingroup$ sorry for confusion! Treatment should not be random! Replicate should be because each replicate was from a different rearing incubator where there may have been influences we could not account for. I have updated the original post with the warnings $\endgroup$ – Anthony Macchiano Jun 30 '20 at 19:31
  • $\begingroup$ "Replicate should be [random] because each replicate was from a different rearing incubator where there may have been influences we could not account for". I need convincing that that is a reason for it to be random and not fixed. That reason might be applied to it being a fixed factor, particularly when you have only 3 of them. Also, do the warnings come from the model with or without Treatment as random ? $\endgroup$ – Robert Long Jun 30 '20 at 19:44

Since there is interest in the association of Treatment with the outcome, it should be a fixed factor.

There are repeated measures per subject, and no interest in subject-specific associations with the outcome, so ID should be specified as a random intercept.

By similar reasoning, replicate could also be considered random, however, with only 3 replicates per treatment, the software can't be expected to estimate a variance for it with any reliability.

It is important to note that, when controlling for non-independence of observations within a factor, eg repeated measures and nesting, there is almost always the option to treat the factor as fixed instead. When there are very few levels of it, or if there are problems with model convergence that appear to be related to the random structure, for example a singular fit, these are very good reasons to treat the factor as fixed.

So in this case I would suggest trying both: one model with replicate as fixed and one with it as random. If they both converge then hopefully they will both produce similar answers to the research question(s).

Finally you might want to consider splines, which are far more flexible than quadratic terms, for handling non-linearities.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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