2

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?

Jon
  • 21
  • 1
  • Ben Bolker’s notes on GLMMs with many-level categorical predictors may also be relevant: https://rstudio-pubs-static.s3.amazonaws.com/109258_9fd5c76643f24ec2894a6a421a4852fe.html – zephryl Feb 21 '22 at 13:56
  • It’s not clear to me what your specific question is. eg, is it “how do I specify the same multi-level model as logistic instead of linear?” in which case, see my answer below; or is it, “how should I specify a logistic model for a continuous outcome?” in which case, I think my answer would still apply, but I wouldn’t swear to it, and you may want to ask at cross validated; or is it, how should I treat a large categorical predictor in a multilevel model? In which case, it would be helpful to say more about what problems you’ve had with approaches you’ve tried so far. – zephryl Feb 21 '22 at 15:55

2 Answers2

1

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.

zephryl
  • 14,633
  • 3
  • 11
  • 30
  • WUE is continuous (water use efficiency of a plant). So the data is not binomial. – Jon Feb 21 '22 at 13:57
  • Since my WUE responses are almost alway curved, I'm trying to fit a logistic function instead of a linear one. – Jon Feb 21 '22 at 15:15
0

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
Robert Long
  • 5,722
  • 5
  • 29
  • 50