Creating a shifted Gamma Distribution: Divergent Transitions



I am completely new to stan and am working on learning the language while attempting to fit a model for a research project. One distribution I need is a shifted Gamma Distribution. I have attempted to implement it using the custom distributions feature. However I consistently get the following message.

There were “N” divergent transitions after warmup. Increasing adapt_delta above 0.8 may help

I have increased the adapt_delta up to .99 and still get the same warning.

I suspect this has something to do with my definition of the log probability function. My guess is that since the log probability uses the shift parameter in it’s evaluation, sometimes the subtraction of the shift will make the generated values too small.

Hence my question is…
1) Whether or not there is a better way to define a shifted distribution (gamma or otherwise)?
2) How much I should be worried about this. The estimates are still accurate but I plan on using this inside a state space model and am unsure as to the possible effects.

I have attached R code that illustrates the stated problem. Thanks in advance for your help.shifted_gamma.R (1.2 KB)


You probably need to add constraint for the shift, because shift has to be smaller than the smallest y

Check this new case study demonstrating user defined probability functions in Stan
as it also demonstrates data dependent constraints on parameters (although not for the shift)


That fixes it. The linked document is also a very useful resource. Thanks for your help.