My “problem” is that the model fit the median behavior of the data and does not capture peaks and low values. Do you have any suggestions? Possibly on how to include random effects or others? I already tried with splines and Gaussian processes.

Hi,
note that you can use triple backticks ``` to start and end code blocks to make laid out in monospace font, please edit your question accordingly.

It is very hard to give a general advice, as it would depend heavily on what the data actually represent. Could you elaborate more on the type/source of the data and the question you are trying to answer? It is generally advisable to try to write a code that would simulate new reasonable data as this often improves your intuition about how to build your model.

Hi Martino and thanks a lot for your reply. I have modified the code as you suggested, thanks.
I ma trying to model big data count (fatalities) they are not continuous in time. I am using the log transformation in the non linear model. Whereas I also tried with a negative binomial distribution with log link and in this case the model provides a good fit only for higher values of the response variable.