Algebraic notation of complex nonlinear brms models

Hello!

I need help writing the algebraic notation of complex nonlinear brms models. I have already fitted the models with success. I now need to “translate” the brms notation I wrote to algebraic notation, to better understand the difference between the models I have fitted.

The database to which I fitted the models is structured as follows:

   sample  phase  SC   gamma   tau
1 A020102      2  60  70.030  3164
2 A020102      2  60  38.490  2810
3 A020102      2  60  20.480  2522

In which “phase” and “SC” are categorized grouping factors, “gamma” is the independent variable and "tau"is the response variable.

I am fitting the following nonlinear equation to my data:

\tau = a + b\gamma^c
With a, b and c as the model parameters.

Here are the models set up in brms syntax:

model_A <- brms::bf(tau ~ a + b * (gamma^c),
                    a ~ 1 + (1|SC|phase),
                    b ~ 1 + (1|SC|phase),
                    c ~ 1 + (1|SC|phase),
                    nl = TRUE)

model_B <- brms::bf(tau ~ a + b * (gamma^c),
                    a ~ 1 + (1|SC) + (1|SC:phase),
                    b ~ 1 + (1|SC) + (1|SC:phase),
                    c ~ 1 + (1|SC) + (1|SC:phase),
                    nl = TRUE)

model_C <- brms::bf(tau ~ a + b * (gamma^c),
                    a ~ 1 + (1|SC) + (1|phase),
                    b ~ 1 + (1|SC) + (1|phase),
                    c ~ 1 + (1|SC) + (1|phase),
                    nl = TRUE)

I now need to write these models in algebraic notation, using the correct index notation. I’m specially confused about how to describe nested random effects, the meaning of the : operator and the difference between (1|SC) + (1|phase) and (1|SC|phase).

This StackExchange question helped a lot, but does not answer all I need. There are also a few similar topics (1, 2, 3) already on Stan Forums, but none of them deal with the : operator. Also, the equatiomatic package was removed from the CRAN repository, thus I’m assuming it’s not entirely reliable to use.

Can anyone please help me?
Any help is deeply appreciated.

Hey @Fonseps , just a couple points I can think of for now:
In model_A, you use (1|SC|phase) which normally that middle ID variable (taken here by SC) is like an arbitrary identifier that tells brms that the varying intercepts across phase for a, b, and c are also correlated. You could have also made up anything there, e.g., (1|P|phase), even though P isn’t a data variable. Check out the ‘Group-level terms’ section in the brmsformula help page.
That said, I don’t really know what’s happening in model_A if SC is actually a variable but it might not be doing what you think. One feature model_A might have which the other two models might lack (not 100% sure) is the correlation in random effects across the 3 nonlinear parameters.

I’m not the best with nested random effects (the : operator on right-hand side of the |) like in model_B, but I find this FAQ page Ben Bolker put together very helpful.

I just tried out installing equatiomatic and it seems all fine on my end (v. 0.3.3) – in future you could also try out the version on github.

1 Like