BookmarkSubscribeRSS Feed
GVeers
Calcite | Level 5
I'm attempting to implement a snippet of code found at this site:

http://www.ats.ucla.edu/stat/sas/code/zip_zinb.htm

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);
run;

I appreciate any and all help!!
2 REPLIES 2
Dale
Pyrite | Level 9
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 +
       (1-p0_zip)*exp(-(count+(1/k))*log(1+k*lambda));

  /* 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);
run;
StatDave
SAS Super FREQ
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:

http://ftp.sas.com/techsup/download/hotfix/hotfix.html

PROC COUNTREG is production status (no longer experimental) in SAS 9.2. See this note concerning COUNTREG documentation:

http://support.sas.com/kb/31684

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1467 views
  • 0 likes
  • 3 in conversation