How can I incorporate a categorical variable with ~200 levels in a nonlinear mixed effects model in R?

Viewed 78

I am trying to fit a nonlinear mixed effects model with a categorical variable genotype that has around 200 levels.

So this is the linear version of the model.

mlinear <- lmer(WUE ~ moisture * genotype + (1|pot), data = d8)

Now I'm trying to make the same model, but with a logistic function instead of linear

mlogistic <- nlme(WUE ~ SSlogis(moisture, Asym, xmid, scal), data = d8, fixed = Asym + xmid + scal ~ 1, random = Asym + xmid + scal~1|pot)

Problem is, now I don't know how to incorporate genotype into this nonlinear model. Asym, xmid, and scal parameters should be able to vary between each genotype. Anyone know how to do this?

2 Answers

It looks like you’re using lme4::lmer for your linear model and nlme::nlme for the logistic? If you use lme4 for both, you should be able to keep the same model specification, and use lme4::glmer with family = binomial for the logistic model. The whole idea behind a GLM with a link function is that you shouldn’t have to do anything different with your predictor vs a linear model, as the link function takes care of that.

library(lme4)

mlinear <- lmer(WUE ~ moisture * genotype + (1|pot), data = d8)

mlogistic <- glmer(WUE ~ moisture * genotype + (1|pot), family = binomial, data = d8)

All that being said, how is WUE measured? You probably want to use either a logistic model (if binary) or linear (if continuous), not both.

Just to add to the answer by @zephryl, who has explained how you can do this, I would like to focus on:

Since my WUE responses are almost alway curved, I'm trying to fit a logistic function instead of a linear one.

Fitting a logistic model does not really make sense here. The distribution of WUE is not relevant. It is the conditional distribution that matters, and we typically assess this by inspecting the residuals. If the residuals show a nonlinear pattern then there are several ways to model this including

  • transformations
  • nonlinear terms
  • splines
Related