Zero-truncated poisson model very slow

This might be due to numerical difficulties, depending on the magnitude of the counts. One thing you can do is “compress” the counts. By this I mean you’d count how many times each value occurs in the sample, using, for instance table() in R or the equivalent in Python.
Your program would look something like this:

data {
  int<lower=1> n;
  int<lower=1> y_value[n];
  int<lower=1> y_freq[n];
}

parameters {
  real<lower=0> lambda;
}

model {
  lambda ~ gamma(20, 20);  

  for (a in 1:n) {
      target += y_freq[a] * ( poisson_lpmf(y_value[a] | lambda) - log1m_exp(-lambda));  // truncated poisson
    }
}

Notice that n now will be a much smaller number than the “original” n.

4 Likes