Resources

Spatial Effects

/*--------------------------------------------------------------

                    SAS Sample Library

        Name: cntex04.sas
 Description: Example program from SAS/ETS User's Guide,
              The COUNTREG Procedure
       Title: Spatial Effects
     Product: SAS/ETS Software
        Keys: countreg spatial effects
        PROC: COUNTREG
       Notes:

--------------------------------------------------------------*/

ods graphics on;

data Shigdata;
input County Shigellosis PopDensity
Hispanic Bighousehold;
datalines;
1   50  2.04361 22.51   5.83
3   0   0.00159 7.15    3.42
5   0   0.06406 12.49   2.31
7   2   0.13444 14.14   3.83
9   1   0.04468 10.32   3.05
11  0   0.01861 55.11   8.93
13  16  1.46524 24.36   5.67
15  0   0.02843 17.80   4.52
17  3   0.10601 12.08   3.44
19  18  0.15617 50.31   11.04
21  0   0.02140 37.48   7.72
23  1   0.03773 9.81    3.12
25  16  0.04179 80.37   11.83
27  0   0.00182 19.40   2.81
29  21  0.10325 49.19   10.95
31  4   0.11010 50.90   10.13
33  0   0.05147 17.15   3.88
35  0   0.00768 17.53   3.80
37  284 2.41964 47.74   9.46
39  4   0.07059 53.69   13.15
41  5   0.48511 15.48   2.59
43  0   0.01260 9.18    2.55
45  1   0.02505 22.20   4.53
47  8   0.13219 54.92   12.67
49  0   0.00247 13.86   3.35
51  0   0.00466 26.49   3.65
53  34  0.12652 55.41   11.94
55  4   0.18238 32.25   6.21
57  3   0.10312 8.54    2.40
59  64  3.80767 33.65   8.62
61  3   0.24764 12.83   3.67
63  0   0.00784 8.02    2.07
65  37  0.30384 45.45   10.80
67  15  1.47080 21.58   6.40
69  3   0.03980 56.43   11.10
71  17  0.10147 49.19   11.70
73  48  0.73582 32.03   6.32
75  109 17.18018 15.12  4.14
77  26  0.49256 38.86   10.30
79  4   0.08174 20.76   3.59
81  25  1.60222 25.40   6.08
83  6   0.15498 42.86   8.36
85  39  1.38101 26.90   7.21
87  9   0.58940 32.05   6.10
89  0   0.04694 8.40    3.71
91  0   0.00340 8.30    1.75
93  1   0.00715 10.28   2.85
95  4   0.50300 24.04   6.63
97  9   0.30706 24.89   4.75
99  13  0.34415 41.92   9.45
101 1   0.15726 28.76   9.10
103 0   0.02152 21.91   5.32
105 0   0.00434 6.96    2.48
107 8   0.09166 60.62   13.15
109 0   0.02493 10.69   2.75
111 12  0.44670 40.27   9.05
113 21  0.19794 30.35   5.56
115 0   0.11420 25.02   8.36
;

data W;
input COL1  COL2    COL3    COL4    COL5    COL6    COL7
COL8    COL9    COL10   COL11   COL12   COL13   COL14   COL15
COL16   COL17   COL18   COL19   COL20   COL21   COL22   COL23
COL24   COL25   COL26   COL27   COL28   COL29   COL30   COL31
COL32   COL33   COL34   COL35   COL36   COL37   COL38   COL39
COL40   COL41   COL42   COL43   COL44   COL45   COL46   COL47
COL48   COL49   COL50   COL51   COL52   COL53   COL54   COL55
COL56   COL57   COL58;
datalines;
0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   1   1   0   1   0   1   0   0   0   0   0
0   1   0   0   0   0   0   0   0   0
0   0   1   0   1   0   0   0   1   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   1   0   0   0
0   1   0   0   1   0   0   0   1   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   1   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   1   0   0   0   0   1   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   1   1   0   0   0   0   0   1
0   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   1   0   0   0
0   0   0   1   0   0   0   0   0   0   1   0   0   0   0   0
1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   1   0   0   0   0   0   1   0
1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0
0   1   0   0   0   1   1   0   0   0   0   0   0   0   0   1
1   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
0   0   0   0   0   0   0   0   0   0
0   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   1
0   0   0   1   0   0   0   1   0   1   1   0   0   0   0   0
0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   1   0   0   0   0
0   0   0   1   0   1   0   0   0   0   0   0   0   0   0   0
1   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   1   0   0   0   0   0   0
0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0
0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
0   0   0   0   1   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
1   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   1   0   0   0   0   1   0
0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0
0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   1   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   1
0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   1   0   0   0   1   0   1   0   0   0   0   0   0
0   0   0   0   0   1   0   1   0   0
0   0   0   0   0   0   0   0   0   1   0   0   0   0   1   0
0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0
0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0
0   0   0   0   0   1   0   0   0   0
0   0   0   0   0   1   0   0   0   0   1   0   0   0   0   0
0   0   0   0   0   0   1   0   1   0   0   1   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
1   0   0   0   0   0   0   0   1   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   1
0   0   0   0   0   0   0   0   0   0   0   0   1   1   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0
0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   1   0   0
0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0
0   0   0   0   0   1   0   1   0   1   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   1   0   0   0
0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   1
1   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   1   0   0   0   1   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   1   0   0   0
0   0   0   0   0   0   0   0   0   0   1   1   0   0   0   0
1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
1   0   0   1   1   0   0   0   0   0
0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0
0   0   0   1   0   1   0   0   0   0   0   0   0   0   0   0
0   0   1   0   0   0   0   0   0   0   1   0   0   0   0   0
0   1   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   1   0   1   0
0   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   0   0   0   1   0   0   0   1   0   0
0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   1   0   0   0
0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   1
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   1   0   0   0   0   1   0   0   0   1   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1
1   0   0   0   0   0   0   0   1   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0
0   0   0   0   0   0   0   0   0   1
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0
1   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0
0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   1   0   0   0   0   0   0   1
0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   1   1   0   0
0   0   0   1   0   0   0   0   0   1
0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0
0   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   1   0   0   0   1   0   1   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   1
0   0   1   0   0   0   0   0   1   0
0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0
0   0   0   0   0   0   0   1   0   0   1   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   1   1   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   1   1   0
0   0   1   0   0   0   0   0   0   0   0   0   0   1   0   0
1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0
1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
1   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0
0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
1   0   1   0   1   0   1   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1
0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0
0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   1   0   0   0   0   1   1   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   1   0   0
1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0
0   0   1   0   0   0   0   0   1   0   0   1   0   0   0   0
0   1   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0
0   0   1   0   0   0   0   0   1   0   1   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   0   0   1   0   0   0   0   0   0   1
0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
0   0   0   1   1   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   0   0   0   0   0   0   1   0   0   1
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   1
0   0   0   0   0   0   0   1   0   0   0   1   0   0   0   0
0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0
0   0   0   0   1   0   0   0   0   0
0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0
0   0   0   0   1   0   0   0   0   0   0   1   0   0   0   0
0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
1   0   0   0   0   0   0   0   1   0
0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0
1   0   0   0   1   0   1   0   0   0   0   1   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1
0   0   0   0   0   0   0   0   0   0
1   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   1   0   1   0   0   0   0   0   0   0   0
0   0   0   0   0   0   1   0   0   0   1   0   0   0   0   0
0   0   0   0   0   0   1   0   0   0
0   0   0   1   0   1   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   1   1
0   0   0   1   0   0   0   0   0   0   1   0   0   0   0   0
0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   1
0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0
0   0   0   0   1   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0
0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   1   0   1   0
0   0   0   1   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   1   0   0   0   1   1   1
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   1   0   0   1   0   0   0   0   0   0   0   0   0   0   0
0   0   0   1   0   1   0   0   0   1   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0
1   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0
0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   1
0   0   1   0   0   0   0   0   0   0
0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   1   0   1   1
0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0
0   0   1   0   0   0   0   0   0   0
;

proc means data=Shigdata;
   var Shigellosis PopDensity Hispanic BigHousehold;
run;
proc freq data=Shigdata;
   table Shigellosis;
run;

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;

/* Generate the map */
proc gmap map=caproj data=Shigdata all;
   id county;
   choro Shigellosis/discrete coutline=black
   legend=legend1;
run;

/*-- Poisson Model with Spatially Weighted Regressors --*/

proc countreg data=Shigdata Wmat=W;
   model Shigellosis = PopDensity BigHousehold / dist=poisson;
   spatialeffects PopDensity BigHousehold;
run;

/*--Negative Binomial Model with  Spatially Weighted Regressors --*/

proc countreg data=Shigdata Wmat=W;
   model Shigellosis = PopDensity BigHousehold / dist=negbin;
   spatialeffects PopDensity BigHousehold;
run;

/*--CMP Model with Spatially Weighted Regressors--*/

proc countreg data=Shigdata Wmat=W;
   model Shigellosis =  PopDensity BigHousehold / dist=compoisson;
   spatialeffects PopDensity BigHousehold;
   dispmodel Shigellosis ~ Hispanic;
   spatialdispeffects Hispanic;
run;

/*--ZINB Model with Spatially Weighted Regressors--*/

proc countreg data=Shigdata Wmat=W;
   model Shigellosis = PopDensity BigHousehold / dist=ZINB;
   zeromodel Shigellosis ~  Hispanic;
   spatialeffects PopDensity BigHousehold;
   spatialzeroeffects Hispanic;
run;