I try to fit a population time-series model in stan/rstan(2.7.0) where the death rate depends on the generation before (n-1) but the reproduction depends on a unknown generation (n-x). I haven't found a way to estimate x since stan has no options for integer distributions and the floor function returns reals that cannot be used as indices to arrays. Does anyone know a good workaround to estimate integer time lags in stan?
Estimating integer parameters in STAN is impossible. HMC depends on gradient computations of the posterior density. Integer parameters aren't suitable for those computations. Rounding or truncating a real number to an integer won't help because the posterior surface will be flat in a region along that axis, so there will be no information for the sampler about where to go next.
Several alterntatives exist, though.
- Specify the number of lags as data for a range of plausible lags and compare the posterior probabilities of these models. Note that you will have to use the functions which compute the complete posterior probability, rather than the posterior probability up to a constant of proportionality. Please see the STAN manual for more deails.
- Use a standard Metropolis/Gibbs sampling routine.