Truncate neg_binomial_2_log?

Hi,

I’m trying to estimate a count model with over-dispersion for a variable, that only contains positive integers. Therefore, I chose for a NegBin II model, i.e. the neg_binomial_2_log distribution of Stan. My model is as follows:

data {
int<lower=1> N; // no. observations
int<lower=1> P; //no. predictors
int<lower=1> y[N]; //min. 1
matrix[N, P] x;
}

parameters {
real intercept;
vector[P] beta; // one beta for each predictor
real<lower=0> phi; // over-dispersion parameter
}

model {
vector[N] mu;
mu = intercept + x*beta;
for (n in 1:N) {
y[n] ~ neg_binomial_2_log(mu[n], phi) T[1,]; // zero-truncated NegBin II?
}
}

Due to the value range of the DV, I need to use truncation, however, the code does not compile, as there seems to be no CDF for neg_binomial_2_log. Is there an alternative to be still able to estimate this model?

Best regards
Christian

Along the lines of add poisson_log_lcdf and poisson_log_lccdf functions · Issue #2015 · stan-dev/stan · GitHub and Error with Truncation on Negative Binomial Distribution (log alternative parameterization), would changing the code in the for-loop to:

y[n] ~ neg_binomial_2_log(mu[n], phi); // no truncation here
target += - log1m(neg_binomial_2_log_lpmf(0 | mu[n], phi)); // manually adjusting computation of likelihood

be a fruitful avenue?

Yeah, that should be it.

What you’re doing is making sure your new pmf sums to one (and so is actually a pmf).

If your original pmf sums to 1 and you want to exclude some values of the random variable, your new pmf is the old one scaled by a factor of 1 / (1 - probability_of_all_the_stuff_you_removed) so that the probabilities will sum to one (which is what the line you found does).