I am testing some non-linear models with nlmer from the lme4 library. But this function assumes normality while my data clearly follows a Gamma distribution.
fit <- lme4::nlmer(y ~ nfun(x, b0, b1, b2) ~
(b0|id),
data = df,
start = start.df, REML=T)
summary(fit)
Is there a way of adding a family group, as for lme4, or any other tips for testing groups within non-linear models when data is not Gaussian?
The options for fitting non-linear generalized mixed models in (pure) R are slim to nonexistent.
brmspackage offers some scope for nonlinear fittingTMB(but you have to do your own programming in an extension of C++)rethinking,greta,rjags, etc. also allow you to build nonlinear mixed effects models — but all (?) in a Bayesian/MCMC frameworkOn the other hand, Gamma-based models can often be adequately substituted by log-Normal-based models (i.e.
log(y) ~ nfun(x, b0, b1, b2)); while the tail shapes of these distributions are very different, the variance-mean relationship for the standard parameterizations is the same, and the results of a (log-link) Gamma GLMM and the corresponding log-Gaussian model are often very similar.Or you could use a fixed effect for the groups (if you have enough data) and use
bbmle::mle2with theparamsargument.