Fitting models with known and unknown nonlinear shapes in R

Cross-posting this following a suggestion by a user on Stack Overflow.

Focusing in on the brms side of things discussed in the original post, I am trying to write a model with a nonlinear term, a smooth term, and an over dispersion term. I successfully implemented this in nimble but it struggles / fails to converge even with weakly informative priors – I only have weakly informative expectations / knowledge of the parameters in the process I’m trying to model so applying strong priors is not a good option even if it does solve the problem (which it may not).

brms is a great tool and has helped me more that once writing Stan code but I am struggling to incorporate the nonlinear terms as well as the smooth terms into a single model. Is there some statistical theoretical reason for why I should not be doing this or is there a way that I missed in the brms manual?

Here are the two models I’m trying to fit together expressed with the brms::bf() – first the nonlinear model:

bf( Y ~ intercept + b1 * X1 + b2 * X2 + b3 * ( (pow(X3, b4) - 1) / b4 ),
    int ~ (1|overdispersion), b1 + b2 + b3 + b4 ~ 1, nl = T)

Where b1 and b2 are linear coefficients on predictors X1 and X2. b3 and b4 define a saturating curve in relation to predictor X3. Lastly, intercept is, of course, the intercept term with an additional error component estimated around this global mean for each observation (over-dispersion).
Now, I’m not sure that I have expressed that model correctly, but that aside, the GAM component that I am trying to add looks like this:

bf( Y ~ X1 + X2 + s(Latitude, Longitude, k = someK, bs = "tp") )

Noting that this is not constructed using brms nonlinear model construction algorithm.

So my question is double:
First, is there a way to code both of these into a single model using brms’ formula constructor?
Second, I am thinking that the default nimble samplers are struggling to decide where to attribute the variance int the fully specified model, but am hopeful that Stan will be somewhat more stable. I don’t know about the mechanics of these samplers so I’d appreciate if anyone was able to support or dispel this expectation.

1 Like