Dear all,

maybe this is a silly question but I would like to hear your thoughts about a problem I am facing.

I have a series of measures and a function (composed of 4 sub-functions, with a total of 9 parameters) that models the phenomenon using 2 covariates. The final formula of the model is complicated.

I want to code the function in Stan and use HMC to explore the space of the 9 variables to find the combinations of values that minimizes the Residuals Sum of Square.

How can I write down a formulation of the loglikelihood of the RSS?

Are there an example or tutorial to start with or maybe I should prefer some black-block optimizers?

Thanks in advance.