Optimizing an external function of the predictors

It may be that I have not entirely understood what I have researched online but is there an example of how to include a user defined function in brms, where the function is of the predictor variable(s) and there is a parameter to be optimized. The function f() consumes one of the predictor variables in a regression and there is a parameter p1 that I need to optimize during fitting. Is this possible?


Specifically, if it helps, I am looking to optimize the adstock function:

adstock_x<- vector(mode=“numeric”, length=length(x))

for (i in 2:length(x))




Is the best way to generate the stan code and then try and alter it to add this function in?

Could be one option if you don’t want to write the Stan code from scratch.