COUNTREG Procedure
Example 11.4 Spatial Effects
(View the complete code for this example.)
This example demonstrates how to use the COUNTREG procedure to model count data with spatial effects. The data set Shigdata contains county-level data related to shigellosis, an infectious bacterial disease. The dependent variable Shigellosis records the number of shigellosis cases reported in each California county in 2011. The data are from the California Department of Public Health. Additional variables include PopDensity (population in thousands per square mile), Hispanic (percentage of Hispanic population), and BigHousehold (percentage of households with six or more persons); these data are from the 2010 United States Census. The following statements compute summary statistics for these variables and the frequency of each observed shigellosis count:
proc means data=Shigdata;
var Shigellosis PopDensity Hispanic BigHousehold;
run;
proc freq data=Shigdata;
table Shigellosis;
run;
The results are presented in Output 11.4.1.
Output 11.4.1: Summary Statistics and Frequency of Counts
| Variable | N | Mean | Std Dev | Minimum | Maximum | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
|
|
|
| Shigellosis | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
|---|---|---|---|---|
| 0 | 18 | 31.03 | 18 | 31.03 |
| 1 | 5 | 8.62 | 23 | 39.66 |
| 2 | 1 | 1.72 | 24 | 41.38 |
| 3 | 4 | 6.90 | 28 | 48.28 |
| 4 | 5 | 8.62 | 33 | 56.90 |
| 5 | 1 | 1.72 | 34 | 58.62 |
| 6 | 1 | 1.72 | 35 | 60.34 |
| 8 | 2 | 3.45 | 37 | 63.79 |
| 9 | 2 | 3.45 | 39 | 67.24 |
| 12 | 1 | 1.72 | 40 | 68.97 |
| 13 | 1 | 1.72 | 41 | 70.69 |
| 15 | 1 | 1.72 | 42 | 72.41 |
| 16 | 2 | 3.45 | 44 | 75.86 |
| 17 | 1 | 1.72 | 45 | 77.59 |
| 18 | 1 | 1.72 | 46 | 79.31 |
| 21 | 2 | 3.45 | 48 | 82.76 |
| 25 | 1 | 1.72 | 49 | 84.48 |
| 26 | 1 | 1.72 | 50 | 86.21 |
| 34 | 1 | 1.72 | 51 | 87.93 |
| 37 | 1 | 1.72 | 52 | 89.66 |
| 39 | 1 | 1.72 | 53 | 91.38 |
| 48 | 1 | 1.72 | 54 | 93.10 |
| 50 | 1 | 1.72 | 55 | 94.83 |
| 64 | 1 | 1.72 | 56 | 96.55 |
| 109 | 1 | 1.72 | 57 | 98.28 |
| 284 | 1 | 1.72 | 58 | 100.00 |
The number of observations is 58, which is the number of California counties. The variance of Shigellosis (1653.99) is much larger than its mean (16.36), suggesting overdispersion. Moreover, the fact that 18 counties (31.03%) have counts of 0 indicates zero-inflation in the data.
A map of California counties that shows their shigellosis counts would help visualize any spatial effects. You can generate such a map by using the following statements:
ods graphics on;
goptions reset=all border;
data ca;
set maps.counties;
where state = 6;
run;
proc sort data=ca out=ca;
by county;
run;
pattern value=mempty color=blue;
/* The COUNTY and COUNTIES data sets are unprojected */
/* Without the gproject procedure, you would get an inverse map */
proc gproject data=ca out=caproj;
id state county;
run;
proc gmap map=caproj data=Shigdata all;
id county;
choro Shigellosis/discrete coutline=black;
run;
The map is shown in Output 11.4.2.
Output 11.4.2: California Map Showing Shigellosis Counts

The following statements fit a Poisson model with spatially weighted regressors:
proc countreg data=Shigdata Wmat=W;
model Shigellosis = PopDensity BigHousehold / dist=poisson;
spatialeffects PopDensity BigHousehold;
run;
The SPATIALEFFECTS statement accounts for spatial effects on regressors in the MODEL statement. Because there might be local spillovers in the two explanatory variables, PopDensity and BigHousehold, both variables are included in the SPATIALEFFECTS statement. The data set W contains the spatial weights matrix. The model fit summary, convergence status, and parameter estimation results are shown in Output 11.4.3.
Output 11.4.3: Poisson Model with Spatially Weighted Regressors
| Model Fit Summary | |
|---|---|
| Dependent Variable | Shigellosis |
| Number of Observations | 58 |
| Data Set | WORK.SHIGDATA |
| Model | Poisson |
| Log Likelihood | -450.76547 |
| Maximum Absolute Gradient | 3.81352E-8 |
| Number of Iterations | 5 |
| Optimization Method | Newton-Raphson |
| AIC | 911.53094 |
| SBC | 921.83315 |
| Algorithm converged. |
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | t Value | Approx Pr > |t| |
| Intercept | 1 | -3.801313 | 0.291041 | -13.06 | <.0001 |
| PopDensity | 1 | 0.257388 | 0.008752 | 29.41 | <.0001 |
| Bighousehold | 1 | 0.147668 | 0.014902 | 9.91 | <.0001 |
| W_PopDensity | 1 | 0.566756 | 0.032005 | 17.71 | <.0001 |
| W_Bighousehold | 1 | 0.567433 | 0.026606 | 21.33 | <.0001 |
As shown in the "Parameter Estimates" table, all estimates are significant at the 5% level. The spatially weighted regressors are labeled with the prefix "W_". Because of the likely overdispersion in the data, you might consider using a negative binomial model. The following statements fit a negative binomial model with spatially weighted regressors:
proc countreg data=Shigdata Wmat=W;
model Shigellosis = PopDensity BigHousehold / dist=negbin;
spatialeffects PopDensity BigHousehold;
run;
The model fit summary, convergence status, and parameter estimation results are listed in Output 11.4.4.
Output 11.4.4: Negative Binomial Model with Spatially Weighted Regressors
| Model Fit Summary | |
|---|---|
| Dependent Variable | Shigellosis |
| Number of Observations | 58 |
| Data Set | WORK.SHIGDATA |
| Model | NegBin(p=2) |
| Log Likelihood | -165.09815 |
| Maximum Absolute Gradient | 3.89549E-8 |
| Number of Iterations | 6 |
| Optimization Method | Newton-Raphson |
| AIC | 342.19629 |
| SBC | 354.55895 |
| Algorithm converged. |
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | t Value | Approx Pr > |t| |
| Intercept | 1 | -2.296188 | 0.541472 | -4.24 | <.0001 |
| PopDensity | 1 | 0.293422 | 0.103991 | 2.82 | 0.0048 |
| Bighousehold | 1 | 0.200243 | 0.063505 | 3.15 | 0.0016 |
| W_PopDensity | 1 | 0.542599 | 0.178125 | 3.05 | 0.0023 |
| W_Bighousehold | 1 | 0.329966 | 0.089232 | 3.70 | 0.0002 |
| _Alpha | 1 | 1.029608 | 0.259475 | 3.97 | <.0001 |
The AIC and SBC values in the "Model Fit Summary" table in Output 11.4.4 are both smaller than those in Output 11.4.3, indicating that the negative binomial model provides a better fit than the Poisson model. The parameter estimate for _Alpha is an estimate of the dispersion parameter in the negative binomial distribution. The null hypothesis that _Alpha is 0 can be tested against the alternative hypothesis that _Alpha is positive, by using the likelihood ratio test. The likelihood ratio test statistic is , where
and
are the log likelihoods for the Poisson (null) and negative binomial (alternative) models, respectively. The likelihood ratio test is highly significant at the 5% level, providing strong evidence of overdispersion.
An alternative model to account for overdispersion is the Conway-Maxwell-Poisson (CMP) model, which uses dispersion regressors to model the parameter that controls the degree of dispersion. The following statements fit a CMP model that accounts for local spillovers in both model regressors and includes a DISPMODEL statement for the dispersion model:
proc countreg data=Shigdata Wmat=W;
model Shigellosis = PopDensity / dist=compoisson;
spatialeffects PopDensity;
dispmodel Shigellosis ~ Hispanic;
spatialdispeffects Hispanic;
run;
The model fit summary, convergence status, and parameter estimation results are provided in Output 11.4.5.
Output 11.4.5: CMP Model with Spatially Weighted Regressors
| Model Fit Summary | |
|---|---|
| Dependent Variable | Shigellosis |
| Number of Observations | 58 |
| Data Set | WORK.SHIGDATA |
| Model | CMPoisson |
| Parameterization | Mu |
| Log Likelihood | -175.88177 |
| Maximum Absolute Gradient | 6.7876E-10 |
| Number of Iterations | 21 |
| Optimization Method | Newton-Raphson |
| AIC | 363.76354 |
| SBC | 376.12620 |
| Algorithm converged. |
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | t Value | Approx Pr > |t| |
| Intercept | 1 | -16.687824 | 26.882100 | -0.62 | 0.5347 |
| PopDensity | 1 | 0.965827 | 1.192338 | 0.81 | 0.4179 |
| W_PopDensity | 1 | 3.309434 | 4.352853 | 0.76 | 0.4471 |
| Dsp_Intercept | 1 | 1.715179 | 1.717222 | 1.00 | 0.3179 |
| Dsp_Hispanic | 1 | 0.036919 | 0.015175 | 2.43 | 0.0150 |
| Dsp_W_Hispanic | 1 | 0.068771 | 0.018894 | 3.64 | 0.0003 |
The regression coefficients in the DISPMODEL statement are labeled with the prefix "Dsp_", and their spatially weighted counterparts in the DISPSPATIALEFFECTS statement are labeled with the prefix "Dsp_W". Both coefficients—Dsp_Hispanic and Dsp_W_Hispanic—are significant at the 5% level. The AIC and SBC values in Output 11.4.5 are both slightly higher than those from the previous negative binomial model. Therefore, the negative binomial model with spatially weighted regressors provides the best fit thus far.
Because 31% of observations have counts of 0, you might consider a zero-inflated negative binomial (ZINB) model. The following statements fit a ZINB model with local spillovers in the model regressors, with a ZEROMODEL statement to model zero inflation:
proc countreg data=Shigdata Wmat=W;
model Shigellosis = PopDensity BigHousehold / dist=ZINB;
zeromodel Shigellosis ~ Hispanic;
spatialeffects PopDensity BigHousehold;
spatialzeroeffects Hispanic;
run;
The model fit summary, convergence status, and parameter estimation results are shown in Output 11.4.6.
Output 11.4.6: ZINB Model with Spatially Weighted Regressors
| Model Fit Summary | |
|---|---|
| Dependent Variable | Shigellosis |
| Number of Observations | 58 |
| Data Set | WORK.SHIGDATA |
| Model | ZINB |
| ZI Link Function | Logistic |
| Log Likelihood | -160.43071 |
| Maximum Absolute Gradient | 4.42772E-6 |
| Number of Iterations | 24 |
| Optimization Method | Newton-Raphson |
| AIC | 338.86142 |
| SBC | 357.40541 |
| Algorithm converged. |
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | t Value | Approx Pr > |t| |
| Intercept | 1 | -1.943401 | 0.542508 | -3.58 | 0.0003 |
| PopDensity | 1 | 0.290024 | 0.099347 | 2.92 | 0.0035 |
| Bighousehold | 1 | 0.218002 | 0.062099 | 3.51 | 0.0004 |
| W_PopDensity | 1 | 0.504903 | 0.165523 | 3.05 | 0.0023 |
| W_Bighousehold | 1 | 0.276429 | 0.086860 | 3.18 | 0.0015 |
| Inf_Intercept | 1 | 294.884748 | 38.757075 | 7.61 | <.0001 |
| Inf_Hispanic | 1 | 15.507229 | 192.906525 | 0.08 | 0.9359 |
| Inf_W_Hispanic | 1 | -41.162731 | 217.771061 | -0.19 | 0.8501 |
| _Alpha | 1 | 0.913846 | 0.227689 | 4.01 | <.0001 |
The "Parameter Estimates" table gives the estimate for the spatially weighted regressor from the ZEROMODEL statement, labeled with the prefix "Inf_W_". The estimates of regression coefficients for Inf_Hispanic and Inf_W_Hispanic are insignificant at the 10% level.