# Specify NLME model in brms

I would like to fit a nonlinear mixed model (fitted with the R package nlme) in the R package brms.
I am unsure about the correct syntax. The NLME model is fitted using a self-start function (SS3PL) and a three-parameter logistic model:

y_{ijk} = \frac{\phi_{2i}}{1\ +\ exp(\phi_{1i}\ (x_{ijk} - \phi_{3ij}))} + \varepsilon_{ijk},
where i is the indiviual ID, j the number of measurement occasion and k the treatment group (binary) . All three parameters are included as random effects.
The parameters \phi_{3} (D50), \phi_{2} (upper asymptote) and \phi_{1} (slope) vary per individual, but \phi_{3} also varies per treatment group on the population level.

The nlme model is implemented like this:

NLME_model <- nlme(y~ SS3PL(x, phi2, phi3, phi1),
data = daten,
fixed = list(phi2 + phi1 ~ 1, phi3 ~ Subgruppen), # variation of phi3 (fixed effect) among treatment groups
groups = ~ Name, # random variation in phi1, phi2, phi3
start = list(fixed = c(40, 0.1, 87, 0)))

I specified this model in brms like this, but the results aren’t convincing, which is why I would like to know if the specification is correct.

bay_model <- bf(y~ phi2/(1 + exp(phi1 * (x- phi3)))
phi1 ~ 1 + (1 | Name)
phi2 ~ 1 +  (1 | Name)
phi3 ~ 1 + Subgruppen + (1 | Name),
nl = T)

hi Mara,

I’d recommend starting out with a simpler version of your model and getting that to run. More informative priors will often help with issues in non-linear models.

Try this syntax for the formula first:

nl_formula <- bf(y ~ phi2/(1 + exp(phi1 * (x - phi3))),
phi1 ~ 1,
phi2 ~ 1,
phi3 ~ 1,
nl = TRUE)

get_prior(nl_formula,
data = daten,
family = "gaussian")

(Assuming you are using that family)

And then try fitting with some weakly-informative priors before adding in the population and group-level effects.

Edit: also, see this vignette: https://cran.r-project.org/web/packages/brms/vignettes/brms_nonlinear.html

Thank you for your suggestion, franzsf. By using simpler models at first it turned out that the failure occurs when trying to distinguish between the two treatment groups (Subgruppen: 0/1). Reading the brms documentation I could not figure out how to add a dummy variable to the model for the second group. I would like to obtain two different estimates for the parameter “phi3”. Do you have any idea how to implement this?

hi Mara,

If I am understanding correctly, it should be straightforward.

nl_formula <- bf(y ~ phi2/(1 + exp(phi1 * (x - phi3))),
phi1 ~ 1,
phi2 ~ 1,
phi3 ~ 1 + Subgruppen,
nl = TRUE)

You can then set a regularizing prior for class = “b” on nlpar = “phi3” specifically.
What kind of failure are you experiencing?