The CNTSELECT Procedure

Example 9.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 = 10000 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 9.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 9.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%
Intercept100001.99390.01971.95541.98081.99392.00672.0350
group 110000-1.44200.0367-1.5075-1.4696-1.4439-1.4159-1.3682
x1100000.28620.01550.25710.27560.28590.29670.3158
x2100000.41820.01460.38830.40820.41870.42850.4470
x3100000.21470.01620.18260.20400.21470.22650.2454
x4100000.40350.01410.37440.39460.40420.41310.4293
x510000-0.29890.0185-0.3349-0.3123-0.2978-0.2853-0.2654
x610000-0.51060.0137-0.5374-0.5210-0.5097-0.5009-0.4863
x710000-0.30560.0147-0.3347-0.3157-0.3059-0.2954-0.2767
Inf_Intercept10000-1.05110.0932-1.2210-1.1136-1.0517-0.9953-0.8465
Inf_z110000-0.62250.0952-0.8018-0.6884-0.6240-0.5592-0.4266
Inf_z2100000.39590.09200.22280.33760.39000.46330.5777
Inf_z3100000.28240.08820.11760.22240.27830.34950.4428

The CNTSELECT Procedure

MCMC Diagnostic Summaries
ParameterMCSEMCSE/SDESSAutocorrelation
Time
ESS/N
Intercept*0.002850.144447.9410208.60.00479
group 1*0.005980.162937.7059265.20.00377
x1*0.002120.137452.9928188.70.00530
x2*0.001540.105390.1485110.90.00901
x3*0.002170.133456.1771178.00.00562
x4*0.001880.133456.1891178.00.00562
x5*0.003020.162837.7233265.10.00377
x6*0.001810.131957.4459174.10.00574
x7*0.001370.0936114.187.66910.0114
Inf_Intercept 0.009400.100898.3253101.70.00983
Inf_z1*0.01220.128660.4869165.30.00605
Inf_z2*0.007580.0824147.367.89040.0147
Inf_z3 0.007360.0835143.369.78570.0143
 *Autocorrelation Remains


Last updated: September 15, 2022