Floor as integer?

Is there an easy way to get discrete parameters by applying floor and ceiling to a real value? For context, I have approximated an unknown population size, N, into a real-valued parameter (so I don’t run into any gradient problems) but some data,x, that I have that depend on the population size are discrete. Conceptually, I want to interpolate between the log-likelihood evaluated at floor(N) and ceiling(N) and include this in the log-likelihood as

target +=r*binomia_lpmf(x,floor(N),p) + (1-r)*binomia_lpmf(x,ceiling(N),p)


r=N - floor(N)

…but the documentation says that floor(N) and ceiling(N) gives integers “converted to a real value” which won’t work in the negative binomial.

My suggestions, in the order of whether I’d actually recommend doing them:

  1. Just marginalize over the unknown discrete population size, which would let you work with the actual generative model that you wish to assume.
  2. Use the “continuous binomial distribution” (write your own stan function for it) given by taking the binomial lpmf and replacing the factorials in the normalization constant with gamma functions.
  3. Use the aforementioned continuous binomial distribution to compute the lpmf at the rounded values, and then run your interpolation scheme (not recommended; included here just in case there’s actually some deep and esoteric reason for wanting linear interpolation between the integers and for completeness a solution to your question as posed)
1 Like