CNTSELECT Procedure
Example 10.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 data set bayes_ex into a data table in your session that is associated with the mylib libref. The DATA step assumes that your libref is named mylib, but you can substitute any appropriately defined libref.
data mylib.bayes_ex;
set bayes_ex;
run;
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=mylib.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 Intercept ~ normal(mean = 0, sd = 10);
prior Inf_z1-Inf_z3 ~ normal(mean = 0, sd = 1);
prior Inf_Intercept ~ normal(mean = 0, sd = 10);
run;
Output 10.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 10.2.1: Bayesian Estimation of Zero-Inflated Poisson Model
| Prior Summary | ||||||||
|---|---|---|---|---|---|---|---|---|
| Parameter | Name | Prior | Bounds | Hyperparameters | ||||
| Lower | Upper | Name | Value | Name | Value | |||
| Intercept | Intercept | Normal | -Infty | Infty | Mean | 0 | Variance | 100 |
| group 1 | group_1 | Truncated Normal | -Infty | 0 | Mean | 0 | Variance | 100 |
| x1 | x1 | Normal | -Infty | Infty | Mean | 0 | Variance | 100 |
| x2 | x2 | Normal | -Infty | Infty | Mean | 0 | Variance | 100 |
| x3 | x3 | Normal | -Infty | Infty | Mean | 0 | Variance | 100 |
| x4 | x4 | Normal | -Infty | Infty | Mean | 0 | Variance | 100 |
| x5 | x5 | Normal | -Infty | Infty | Mean | 0 | Variance | 100 |
| x6 | x6 | Normal | -Infty | Infty | Mean | 0 | Variance | 100 |
| x7 | x7 | Normal | -Infty | Infty | Mean | 0 | Variance | 100 |
| Inf_Intercept | Inf_Intercept | Normal | -Infty | Infty | Mean | 0 | Variance | 100 |
| Inf_z1 | Inf_z1 | Normal | -Infty | Infty | Mean | 0 | Variance | 1 |
| Inf_z2 | Inf_z2 | Normal | -Infty | Infty | Mean | 0 | Variance | 1 |
| Inf_z3 | Inf_z3 | Normal | -Infty | Infty | Mean | 0 | Variance | 1 |
| Posterior Summaries | ||||||||
|---|---|---|---|---|---|---|---|---|
| Parameter | N | Mean | Standard Deviation | Percentiles | ||||
| 2.5% | 25% | 50% | 75% | 97.5% | ||||
| Intercept | 10000 | 1.9800 | 0.0131 | 1.9554 | 1.9707 | 1.9798 | 1.9885 | 2.0070 |
| group 1 | 10000 | -1.4828 | 0.0325 | -1.5405 | -1.5090 | -1.4833 | -1.4584 | -1.4188 |
| x1 | 10000 | 0.2853 | 0.0131 | 0.2605 | 0.2768 | 0.2851 | 0.2940 | 0.3121 |
| x2 | 10000 | 0.4146 | 0.0107 | 0.3930 | 0.4081 | 0.4145 | 0.4219 | 0.4356 |
| x3 | 10000 | 0.2129 | 0.0116 | 0.1901 | 0.2052 | 0.2134 | 0.2208 | 0.2362 |
| x4 | 10000 | 0.4027 | 0.00998 | 0.3819 | 0.3971 | 0.4026 | 0.4088 | 0.4217 |
| x5 | 10000 | -0.3107 | 0.0129 | -0.3358 | -0.3196 | -0.3101 | -0.3022 | -0.2849 |
| x6 | 10000 | -0.5188 | 0.0118 | -0.5427 | -0.5270 | -0.5186 | -0.5109 | -0.4962 |
| x7 | 10000 | -0.2963 | 0.0123 | -0.3186 | -0.3053 | -0.2967 | -0.2882 | -0.2720 |
| Inf_Intercept | 10000 | -1.0055 | 0.0669 | -1.1440 | -1.0509 | -1.0016 | -0.9554 | -0.8867 |
| Inf_z1 | 10000 | -0.5749 | 0.0791 | -0.7243 | -0.6287 | -0.5779 | -0.5268 | -0.3997 |
| Inf_z2 | 10000 | 0.4013 | 0.0914 | 0.2281 | 0.3346 | 0.3999 | 0.4617 | 0.5850 |
| Inf_z3 | 10000 | 0.3761 | 0.0550 | 0.2736 | 0.3342 | 0.3737 | 0.4168 | 0.4807 |
| MCMC Diagnostic Summaries | ||||||
|---|---|---|---|---|---|---|
| Parameter | MCSE | MCSE/SD | ESS | Autocorrelation Time | ESS/N | |
| Intercept | * | 0.00170 | 0.1300 | 59.1948 | 168.9 | 0.00592 |
| group 1 | * | 0.00632 | 0.1943 | 26.4872 | 377.5 | 0.00265 |
| x1 | * | 0.00171 | 0.1307 | 58.4973 | 170.9 | 0.00585 |
| x2 | * | 0.000841 | 0.0787 | 161.6 | 61.8694 | 0.0162 |
| x3 | 0.000726 | 0.0624 | 257.0 | 38.9091 | 0.0257 | |
| x4 | * | 0.00123 | 0.1228 | 66.2673 | 150.9 | 0.00663 |
| x5 | * | 0.00160 | 0.1242 | 64.7892 | 154.3 | 0.00648 |
| x6 | * | 0.00143 | 0.1214 | 67.9022 | 147.3 | 0.00679 |
| x7 | * | 0.00111 | 0.0904 | 122.5 | 81.6416 | 0.0122 |
| Inf_Intercept | * | 0.00967 | 0.1445 | 47.8864 | 208.8 | 0.00479 |
| Inf_z1 | * | 0.0111 | 0.1405 | 50.6374 | 197.5 | 0.00506 |
| Inf_z2 | * | 0.0130 | 0.1418 | 49.7432 | 201.0 | 0.00497 |
| Inf_z3 | * | 0.00961 | 0.1749 | 32.7080 | 305.7 | 0.00327 |
| *Autocorrelation Remains | ||||||