The CNTSELECT Procedure

Example 8.2 Zero-Inflated Poisson Model with BAYES and PRIOR Statements

This example shows how to use the CNTSELECT procedure to estimate a zero-inflated Poisson model by using Bayesian methods, with user-specified priors. The following DATA step generates 1,000 replicates from the zero-inflated Poisson (ZIP) model. The model contains seven variables and three variables that correspond to the zero-inflated process.

data bayes_ex;
   call streaminit(12345);
   array vars x1-x7;
   array zero_vars z1-z3;
   array parms{7}  (.3 .4 .2 .4 -.3 -.5 -.3);
   array zero_parms{3} (-.6 .3 .2);
   intercept=0.5;
   group=1;
   z_intercept=-1;
   theta=0.5;
   do i=1 to 1000;
      sum_xb=0;
      sum_gz=0;
      if i>500 then do;
         intercept=2;
         group=2;
      end;
      do j=1 to 7;
         vars[j]=rand('NORMAL',0,1);
         sum_xb=sum_xb+parms[j]*vars[j];
      end;
      mu=exp(intercept+sum_xb);
      y_p=rand('POISSON', mu);
      do j=1 to 3;
         zero_vars[j]=rand('NORMAL',0,1);
         sum_gz = sum_gz+zero_parms[j]*zero_vars[j];
      end;
      z_gamma = z_intercept+sum_gz;
      pzero = cdf('LOGISTIC',z_gamma);
      cut=rand('UNIFORM');
      if cut<pzero then y_p=0;
      output;
   end;
   keep y_p group x1-x7 z1-z3;
run;

You can load the bayes_ex data set into your CAS session by naming your CAS engine libref in the first statement of the following DATA step:

data mycas.bayes_ex;
   set bayes_ex;
run;

These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined libref.

The following statements estimate a zero-inflated Poisson model via Bayesian analysis. Note that the BAYES statement controls the settings for the MCMC sampler and determines which Bayesian output to produce. The PRIOR statements set the prior distributions for the parameters.

proc cntselect data=mycas.bayes_ex dist=zip;
   class group;
   model y_p=group x1-x7;
   zeromodel y_p ~ z1-z3;
   bayes seed = 81239 nmc = 2000 sampler = rwm(ntu = 50) priorsummary(shownames);
   prior x1-x7 ~ normal(mean = 0, sd = 10);
   prior group_1 ~ normal(mean = 0, sd = 10, upper = 0);
   prior z1-z3 ~ normal(mean = 0, sd = 1);
   prior Intercept ~ normal(mean = 0, sd = 10);
run;

Output 8.2.1 shows the results for the zero-inflated Poisson model. The "Prior Summary" table shows detailed information about prior distributions for the parameters in the model. The "Posterior Summaries" table contains two point estimates of the parameters from the posterior samples: the posterior mean and the posterior median (50th percentile). The "MCMC Diagnostic Summaries" table contains basic convergence diagnostics to check whether the Markov chain has converged and whether the sample size is sufficient.

Output 8.2.1: Bayesian Estimation of Zero-Inflated Poisson Model

The CNTSELECT Procedure

Prior Summary
ParameterNamePriorBoundsHyperparameters
LowerUpperNameValueNameValue
InterceptInterceptNormal-InftyInftyMean0Variance100
group 1group_1Truncated Normal-Infty0Mean0Variance100
x1x1Normal-InftyInftyMean0Variance100
x2x2Normal-InftyInftyMean0Variance100
x3x3Normal-InftyInftyMean0Variance100
x4x4Normal-InftyInftyMean0Variance100
x5x5Normal-InftyInftyMean0Variance100
x6x6Normal-InftyInftyMean0Variance100
x7x7Normal-InftyInftyMean0Variance100
Inf_InterceptInf_InterceptNormal-InftyInftyMean0Variance1000000
Inf_z1Inf_z1Normal-InftyInftyMean0Variance1000000
Inf_z2Inf_z2Normal-InftyInftyMean0Variance1000000
Inf_z3Inf_z3Normal-InftyInftyMean0Variance1000000

The CNTSELECT Procedure

Posterior Summaries
ParameterNMeanStandard
Deviation
Percentiles
2.5%25%50%75%97.5%
Intercept20001.99060.01711.95541.97911.99192.00212.0228
group 12000-1.45420.0315-1.5069-1.4811-1.4539-1.4299-1.3908
x120000.28470.01210.26180.27650.28470.29440.3041
x220000.42340.01260.40200.41540.42330.43160.4506
x320000.21690.01350.19340.20770.21810.22650.2442
x420000.40940.01110.38900.40100.40930.41760.4293
x52000-0.29910.0148-0.3270-0.3080-0.2983-0.2903-0.2699
x62000-0.52190.0121-0.5448-0.5298-0.5238-0.5137-0.4956
x72000-0.31060.0135-0.3378-0.3198-0.3096-0.3026-0.2825
Inf_Intercept2000-1.05030.0874-1.2665-1.1010-1.0477-0.9899-0.8906
Inf_z12000-0.67150.0735-0.8250-0.7131-0.6804-0.6280-0.5134
Inf_z220000.40150.08270.25880.34370.39280.46950.5427
Inf_z320000.30000.08220.13750.24150.29530.35990.4424

The CNTSELECT Procedure

MCMC Diagnostic Summaries
ParameterMCSEMCSE/SDESSAutocorrelation
Time
ESS/N
Intercept*0.005580.32679.3679213.50.00468
group 1*0.01100.35028.1518245.30.00408
x1 0.002680.221120.454597.77810.0102
x2 0.002110.166636.031255.50740.0180
x3*0.003240.240917.2263116.10.00861
x4 0.002160.193926.592175.21030.0133
x5 0.004310.290111.8834168.30.00594
x6 0.002680.222220.258098.72630.0101
x7 0.001570.116773.463227.22450.0367
Inf_Intercept 0.02050.234918.1186110.40.00906
Inf_z1*0.01470.200324.926880.23500.0125
Inf_z2*0.01810.218520.943395.49610.0105
Inf_z3 0.01370.167035.842455.79990.0179
 *Autocorrelation Remains


Last updated: April 15, 2021