Programming the statistical procedures from SAS

Zero-modified Negative Binomial on SAS 9.1

Posts: 29

Zero-modified Negative Binomial on SAS 9.1

I'm attempting to implement a snippet of code found at this site:

They show a way to fit a zero-modified negative binomial distribution in SAS 9.1. However, I'm getting the following errors:

ERROR: Signal caught by CMP from PROC.
ERROR: Invalid Operation.
ERROR: Termination due to Floating Point Exception

The procedure gets to 6 iterations before returning this error.

This is a bit of a shot in the dark, but while I try to understand the error I was hoping someone else had a similar experience. The code is as follows:

*zero inflated negative binomial, producing the same result as "zinb count child camper persons, inflate(child)" in Stata;;
proc nlmixed data=fish;
parameters b0=0 b1=0 b2=0 b3 = 0
a0=0 a1 = 0 alpha = 1;
/* linear predictor for the inflation probability */
linpinfl = a0 + a1*child;
/* infprob = inflation probability for zeros */
/* = logistic transform of the linear predictor*/
infprob = 1/(1+exp(-linpinfl));
/* negative binomial with mean-dispersion */
lambda = exp(b0 + b1*child + b2*camper + b3*persons );
/* Build the ZIP log likelihood */
m = 1/alpha;
p = 1/(1+alpha*lambda);
if count=0 then
ll = log(infprob + (1-infprob)*(p**m));
else ll = log(1-infprob) + log(gamma(m + count)) - log(gamma(count + 1))
- log(gamma(m)) + m*log(p) + count*log(1-p);
model count ~ general(ll);

I appreciate any and all help!!
Regular Contributor
Posts: 171

Re: Zero-modified Negative Binomial on SAS 9.1

Is this the code that you submitted which produced an error? The code which you show appears to be the zero-inflated negative binomial code directly from the UCLA website. When I run the code shown in your post, there is no error produced.

This leads me to believe that you are probably not showing us the code which generated the errors shown in your post. Without seeing your code, it is extremely difficult to provide assistance. My suspicion is that there might be some portion of the code which you did not properly modify when editing the code for the data for which you need to construct a model. But that is only a guess.

The code from the UCLA website produces results which are identical to the results produced by code for a ZINB model which I demonstrated on SAS-L. Below is my version of ZINB code applied to the FISH data. Note that the overdispersion parameter alpha in the UCLA code is named K in my code.

proc nlmixed data=fish;
  parms b0 b1 b2 b3 a0 a1 0
        k 1;

/* Linear predictor for excess zero probability */
  eta_zip = a0 + a1*child;

  /* Excess zero probability */
  p0_zip = 1 / (1 + exp(-eta_zip));

  /* Linear predictor for N.B. expectation */
  eta_nb = b0 + b1*child + b2*camper + b3*persons;
  /* N.B. expectation */
  lambda = exp(eta_nb);

  /* Probability of zero value: combination of N.B. zero prob and excess zeros prob */
  p0 = p0_zip +

  /* Probabilities of nonzero values obtained from N.B. distribution */
  p_else = (1-p0_zip)*
           exp(lgamma(count+(1/k)) - lgamma(count+1) - lgamma(1/k) +
           count*log(k*lambda) - (count+(1/k))*log(1+k*lambda));

  /* Note that all obs from N.B. distribution have probability which sums to */
  /* sum(P(Y=i) | Y~N.B.) = 1 - P(excess zero value), i=0,1,2,...,inf */

  /* Construct ZINB log-likelihood */
  if count=0 then loglike = log(p0);
  else            loglike = log(p_else);

  /* Fit ZINB model */
  model count ~ general(loglike);
SAS Employee
Posts: 308

Re: Zero-modified Negative Binomial on SAS 9.1

Poisson, negative binomial, and zero-inflated versions of these models can be fit using the experimental PROC COUNTREG which is part of Service Pack 3 or later of SAS 9.1.3 (TS1M3) if you have licensed SAS/ETS software. Service Packs are available from this location:

PROC COUNTREG is production status (no longer experimental) in SAS 9.2. See this note concerning COUNTREG documentation:
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation