# How to make a gradient coefficient depend on a non-linear function

I can get a prior structure and test my formula arg definition for a censored hierarchical linear growth model, grouped by individual by running `brms::get_prior()`:

``````get_prior(data = dataset,
family = gaussian(),
formula = logPD | cens(cen1) ~ 1 + studyday + (1 + studyday | SUBJID)
)
``````

and this returns expected output:

``````                   prior     class      coef  group resp dpar nlpar lb ub       source
(flat)         b                                             default
(flat)         b  studyday                              (vectorized)
lkj(1)       cor                                             default
lkj(1)       cor           SUBJID                       (vectorized)
student_t(3, -0.3, 2.5) Intercept                                             default
student_t(3, 0, 2.5)        sd                                   0         default
student_t(3, 0, 2.5)        sd           SUBJID                  0    (vectorized)
student_t(3, 0, 2.5)        sd Intercept SUBJID                  0    (vectorized)
student_t(3, 0, 2.5)        sd  studyday SUBJID                  0    (vectorized)
student_t(3, 0, 2.5)     sigma                                   0         default
``````

However I would like the population-level gradient coefficient of studyday (now called CLR) to depend on a non-linear function whose parameters (a1, a2, b & h) I’d like to estimate too. `logPD`, `cen1`, `studyday`, `SUBJID` & `totperwkperkg` already exist in `dataset`.

``````get_prior(data = dataset,
family = gaussian(),
formula = bf(logPD | cens(cen1) ~ 1 + CLR*studyday + (1 + studyday | SUBJID)) +
nlf(-CLR ~ (a1 * totperwkperkg^h)/(b + totperwkperkg^h) + a2) +
lf(a1 + b + h + a2 ~ 1) +
set_nl(nl = TRUE)
)
``````

but this oddly only returns the non-linear coefficients I wanted and loses the linear coefficients shown above:

``````                prior class      coef group resp dpar nlpar lb ub       source
student_t(3, 0, 2.5) sigma                                  0         default
(flat)     b                              a1            default
(flat)     b Intercept                    a1       (vectorized)
(flat)     b                              a2            default
(flat)     b Intercept                    a2       (vectorized)
(flat)     b                               b            default
(flat)     b Intercept                     b       (vectorized)
(flat)     b                               h            default
(flat)     b Intercept                     h       (vectorized)
``````

Additionally I’m ignorant on the difference between `bf()` & `lf()`. `bf()` is used to separate functions and seems to always contain the response variable? `nlf()` contains the non-linear function?

Operating System: Ubuntu 22.04 LTS
brms Version: 2.17.0

Think I’ve found a solution, yet to be run.

1. When using set_nl(TRUE) one has to be explicit for all parameters, not just the non-linear ones.
2. Used the `(1|ID1|SUBJID)` syntax to ensure the correlation structure is in there, which is implicit when formulating the linear case (related post).
``````get_prior(data = dataset,
family = gaussian(),
formula = bf(logPD | cens(cen1) ~ popnintercept + CLR*studyday) +
lf(popnintercept + CLR ~ 1 + (1|ID1|SUBJID)) +
nlf(-CLR ~ (a1 * totperwkperkg^h)/(b + totperwkperkg^h) + a2) +
lf(a1 + b + h + a2 ~ 1 + (1|ID1|SUBJID)) +
set_nl(nl = TRUE)
)
``````

The result gives the following, including a warning of `Replacing initial definitions of parameters 'CLR'` as `CLR` is now just a dummy variable.

``````                prior class      coef  group resp dpar         nlpar lb ub       source
lkj(1)   cor                                                     default
lkj(1)   cor           SUBJID                               (vectorized)
student_t(3, 0, 2.5) sigma                                           0         default
(flat)     b                                       a1            default
(flat)     b Intercept                             a1       (vectorized)
student_t(3, 0, 2.5)    sd                                       a1  0         default
student_t(3, 0, 2.5)    sd           SUBJID                      a1  0    (vectorized)
student_t(3, 0, 2.5)    sd Intercept SUBJID                      a1  0    (vectorized)
(flat)     b                                       a2            default
(flat)     b Intercept                             a2       (vectorized)
student_t(3, 0, 2.5)    sd                                       a2  0         default
student_t(3, 0, 2.5)    sd           SUBJID                      a2  0    (vectorized)
student_t(3, 0, 2.5)    sd Intercept SUBJID                      a2  0    (vectorized)
(flat)     b                                        b            default
(flat)     b Intercept                              b       (vectorized)
student_t(3, 0, 2.5)    sd                                        b  0         default
student_t(3, 0, 2.5)    sd           SUBJID                       b  0    (vectorized)
student_t(3, 0, 2.5)    sd Intercept SUBJID                       b  0    (vectorized)
(flat)     b                                        h            default
(flat)     b Intercept                              h       (vectorized)
student_t(3, 0, 2.5)    sd                                        h  0         default
student_t(3, 0, 2.5)    sd           SUBJID                       h  0    (vectorized)
student_t(3, 0, 2.5)    sd Intercept SUBJID                       h  0    (vectorized)
(flat)     b                            popnintercept            default
(flat)     b Intercept                  popnintercept       (vectorized)
student_t(3, 0, 2.5)    sd                            popnintercept  0         default
student_t(3, 0, 2.5)    sd           SUBJID           popnintercept  0    (vectorized)
student_t(3, 0, 2.5)    sd Intercept SUBJID           popnintercept  0    (vectorized)
``````