Resources

Compact representation of the spatial weights matrix

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

                    SAS Sample Library

        Name: sprex04.sas
 Description: Example program from SAS/ETS User's Guide,
              The SPATIALREG Procedure
       Title: Compact representation of the spatial weights matrix
     Product: SAS/ETS Software
        Keys: Compact representation
        PROC: SPATIALREG
       Notes:

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

data simdata;
  input SID $ x1 x2 x3 y;
datalines;
L50 -1.080192664    -0.391837255    2.6720532843    -1.939942256
L34 -0.401471135    0.3513199155    0.3771476344    0.7230873618
L46 0.1314452577    1.5626892891    -0.273442927    1.9925135176
L13 0.7920110978    0.3900768864    -0.780730106    2.4143089527
L11 -0.496266788    -1.161049655    -0.462676297    0.6529367412
L8  0.4673733309    0.7449099388    -0.557031886    2.0709143796
L1  1.0747268604    0.8179241213    -0.552774504    3.7404686845
L44 -0.969128513    -0.532027463    0.6119455357    0.3207327491
L6  1.4849682178    1.6632191757    -1.682192731    4.7136835044
L31 1.6539456214    0.529697017     1.0312325223    2.2623271467
L49 0.4021394645    -1.200222916    -1.690597188    2.3671651538
L26 -0.49813637     -1.7692711      0.4273909093    -1.193951993
L48 -1.974680775    -1.04760534     -0.702733763    0.2958880072
L29 -0.85707891     -0.330706762    0.1059158623    -0.717334237
L37 0.3464385033    -0.256593889    -0.497110119    1.9438614251
L4  -0.482548243    -0.452974096    0.2738674886    0.4065525795
L3  1.2252590297    -0.148304138    0.2901232752    1.5669797681
L40 0.1026758193    -0.982447991    1.8173650332    -1.157783179
L19 1.3368393023    -0.874235931    -0.081595457    2.3832830417
L17 -1.035661208    -0.028786903    0.2457009705    0.069929007
L45 1.3204304867    -0.863550062    0.9757917861    -0.503511316
L47 0.8799907753    -1.107299467    -1.884480816    1.7385015825
L15 -0.097991569    1.1407931953    -1.178890318    2.7025763571
L39 0.5000595821    -1.801018572    1.0955076204    -0.651873723
L41 -0.085590063    -0.95495114     -1.181589807    1.6048483869
L32 -2.452319337    -0.707313442    -0.945681396    0.8784455245
L22 0.5366215036    0.68496118      -0.702203856    3.6422129211
L18 -1.913065732    0.0561821805    -1.289341948    0.811460829
L36 1.1176441189    0.4849829922    -0.633740565    2.6825944244
L16 -1.010013544    0.1501684675    0.6892721371    0.4285848788
L35 0.7746020606    -2.57257665     0.3777694392    -0.952147054
L9  0.0842232867    -1.313573502    -1.931519517    1.1484312409
L38 -0.610859299    0.1587061823    0.9739440971    0.2886113928
L7  0.629140588     1.4323343516    0.3604963698    2.6856130381
L43 0.1869868108    0.1469053516    0.0298671298    1.5537924279
L23 -1.917034243    2.4034547166    -2.447004851    4.6922590646
L24 0.5057919358    -0.675375524    1.0080312836    -1.385196867
L10 0.8171785858    1.0450583561    -0.997780737    2.8727332473
L12 -1.973530252    -0.431360634    0.0467521192    0.1143714659
L14 1.4026821472    0.7753985164    1.3277971886    1.1660025894
L27 1.4020780432    -0.206033167    0.3428467454    1.7546642589
L20 -1.390736973    0.719254447     0.4442360706    -0.023710168
L5  0.218553009     -0.420015176    0.2463559954    0.8474411587
L2  -1.233821987    -0.141535384    1.0420036424    -1.045870218
L42 0.4346834817    -0.59685783     -0.123448644    0.5801302381
L30 -2.227219374    -0.358401709    -0.055078668    -1.209077026
L21 1.1920958462    0.2146500105    -0.050886065    2.2176859357
L25 0.0197744321    0.298455422     -0.361649662    1.7591096992
L33 0.3388960631    0.81292813      -0.087180185    2.4823505199
L28 0.9464460905    0.5921500617    -0.133987881    2.0493385224
;

data simw;
  input SID $ L1   L2  L3  L4  L5  L6  L7  L8  L9  L10 L11 L12 L13 L14 L15 L16 L17 L18 L19 L20 L21 L22 L23 L24 L25 L26 L27 L28 L29 L30 L31 L32 L33 L34 L35 L36 L37 L38 L39 L40 L41 L42 L43 L44 L45 L46 L47 L48 L49 L50;
  datalines;
L1  0   1   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   1   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0
L2  1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1   0   1   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
L3  0   0   0   0   0   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   1   0   0   1   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0
L4  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   0   0   0   0   0   0   0   1   0   0   0   0   1   0   0
L5  0   0   0   0   0   0   0   0   0   0   0   1   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   1   0   0   1   0   0   0   0   1   0
L6  0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   1   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   1   0   1   0   0   0
L7  0   0   0   0   0   1   0   0   1   0   1   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   1   0   0   0   0   0
L8  0   0   0   0   0   0   0   0   0   1   1   0   0   0   0   0   0   0   0   0   1   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
L9  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   1   0   0   0   1   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0
L10 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   1   0   0   0   0
L11 1   0   0   0   0   0   1   1   0   0   0   0   0   1   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   1   0   0   0   0   0   0   0   0   0
L12 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   1   0   0   1   0   0   0   0   0   0   0   1   0   0   0   1
L13 0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   1   0   1   0   0   0   1   0   0   0   0   1   0   0   1   0   0   0   0   0   0   1   0   0   0   0
L14 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   0   0   0   0   0   1   0   0
L15 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   1   1   0   0   0   0   0   0   0   0   0   0   0   1   0   0
L16 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   1   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
L17 0   0   1   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   1   0   0   0   1   0   0   0   0   0   0
L18 0   1   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   1   0   0   0   1   0   0   0   0   0
L19 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   0   0   0   0   0   0   1   0
L20 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   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1   0   0   0   1   0
L21 0   1   0   0   1   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   1   0   1   0   0   0   0   0   0   0
L22 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   1   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
L23 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   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   1
L24 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
L25 0   0   0   0   0   1   1   0   0   0   1   0   1   0   1   1   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   0   0   0   0   1
L26 0   1   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   1   1   0   0   1   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
L27 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   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0
L28 0   1   0   0   0   1   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   1   0   1   0   0   0   0   0   0   0   0   0   0
L29 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   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
L30 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
L31 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   0   0   0   0   0   0   0   1   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0
L32 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   1   0   0   0   0   0   0   0   1   0   1   0   0   1   0   0
L33 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   0   0   0   0   0   0   0   0   0   0   0   0   0
L34 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   1   0   0   0   0   0   0   0   0   0   0   0   0   1   0
L35 0   0   1   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
L36 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   1   0   0   0   0   0   0   0   0   0   1   1   1   0   0   0   0
L37 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   1   0   0   0   0   0   1   0   0   0   0
L38 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   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
L39 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   0
L40 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   1   0   0   0   0   0   0   0   0   0   0   1   0   0
L41 0   0   0   0   1   0   0   0   0   0   1   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
L42 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   1   0   1   0   0   0   0   0   0   0   0   0   0   0   1   0   0   1   0   0   1   0
L43 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   1   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   1   0
L44 0   0   0   0   1   0   0   0   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   1   0   0   0   0   0   0   0   0   0   0   0   1   0   0
L45 0   0   0   0   0   1   1   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   1   0   0   0   0   0   0   0   0   0   0   0   0   1   1
L46 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   0   0   0   0   0   0   0   0   0   1   1   0   0   0   0   1   0   0   0   0   0   0   0   0
L47 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   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
L48 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   1   0   0   0   0   0   0   0   1   0   0   0   1   0   0   0   0   0   0
L49 0   0   0   0   1   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   1   0   0   0   0   0   0   0   1   1   0   1   0   1   0   0   0
L50 0   0   0   0   0   0   0   0   0   0   0   1   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   0   0   0   0   0   1   0   0   0   0   0
;

data simw_compact;
  input SID $ cSID $ Value;
  datalines;
  L50   L45 1
  L30   L22 1
  L42   L46 1
  L32   L35 1
  L7    L25 1
  L33   L25 1
  L50   L25 1
  L23   L50 1
  L9    L7  1
  L45   L36 1
  L32   L9  1
  L27   L13 1
  L10   L8  1
  L18   L6  1
  L50   L23 1
  L44   L48 1
  L8    L43 1
  L28   L6  1
  L7    L6  1
  L34   L36 1
  L44   L17 1
  L36   L15 1
  L39   L13 1
  L16   L38 1
  L5    L19 1
  L15   L4  1
  L19   L2  1
  L37   L46 1
  L4    L43 1
  L45   L7  1
  L3    L17 1
  L29   L42 1
  L12   L35 1
  L25   L26 1
  L47   L27 1
  L31   L8  1
  L38   L16 1
  L3    L37 1
  L1    L2  1
  L31   L35 1
  L19   L49 1
  L36   L45 1
  L36   L46 1
  L8    L11 1
  L47   L6  1
  L20   L11 1
  L6    L28 1
  L18   L10 1
  L21   L8  1
  L32   L4  1
  L27   L47 1
  L33   L18 1
  L48   L15 1
  L11   L41 1
  L6    L25 1
  L49   L5  1
  L3    L35 1
  L28   L22 1
  L26   L25 1
  L42   L31 1
  L14   L11 1
  L48   L44 1
  L2    L28 1
  L31   L42 1
  L46   L36 1
  L5    L41 1
  L16   L34 1
  L9    L28 1
  L1    L29 1
  L43   L49 1
  L7    L11 1
  L49   L42 1
  L38   L12 1
  L3    L13 1
  L10   L46 1
  L26   L22 1
  L6    L18 1
  L22   L24 1
  L9    L37 1
  L26   L44 1
  L16   L25 1
  L32   L45 1
  L23   L3  1
  L10   L18 1
  L49   L45 1
  L20   L45 1
  L46   L12 1
  L8    L21 1
  L32   L48 1
  L21   L2  1
  L45   L6  1
  L38   L28 1
  L21   L43 1
  L34   L16 1
  L18   L45 1
  L25   L7  1
  L7    L17 1
  L19   L5  1
  L12   L50 1
  L25   L15 1
  L34   L26 1
  L50   L12 1
  L24   L22 1
  L37   L3  1
  L22   L30 1
  L4    L48 1
  L47   L23 1
  L13   L46 1
  L25   L16 1
  L34   L49 1
  L20   L44 1
  L48   L32 1
  L46   L10 1
  L20   L49 1
  L30   L1  1
  L6    L7  1
  L11   L36 1
  L28   L2  1
  L42   L14 1
  L12   L27 1
  L43   L8  1
  L35   L3  1
  L9    L32 1
  L46   L13 1
  L17   L3  1
  L14   L42 1
  L13   L27 1
  L25   L11 1
  L26   L34 1
  L7    L9  1
  L6    L45 1
  L46   L37 1
  L41   L5  1
  L11   L8  1
  L28   L9  1
  L1    L11 1
  L2    L21 1
  L12   L46 1
  L37   L40 1
  L15   L36 1
  L48   L14 1
  L17   L40 1
  L25   L33 1
  L11   L14 1
  L2    L19 1
  L1    L30 1
  L5    L44 1
  L5    L12 1
  L36   L11 1
  L6    L47 1
  L13   L20 1
  L35   L12 1
  L27   L12 1
  L26   L21 1
  L48   L4  1
  L18   L2  1
  L48   L40 1
  L17   L4  1
  L40   L17 1
  L27   L31 1
  L21   L5  1
  L5    L21 1
  L15   L25 1
  L11   L7  1
  L49   L19 1
  L35   L31 1
  L26   L8  1
  L49   L47 1
  L12   L5  1
  L28   L38 1
  L4    L32 1
  L22   L26 1
  L28   L23 1
  L3    L23 1
  L11   L1  1
  L43   L32 1
  L49   L34 1
  L46   L42 1
  L7    L45 1
  L32   L43 1
  L43   L21 1
  L8    L26 1
  L5    L23 1
  L28   L40 1
  L6    L29 1
  L40   L28 1
  L35   L32 1
  L8    L10 1
  L29   L1  1
  L2    L18 1
  L2    L26 1
  L13   L25 1
  L31   L27 1
  L17   L44 1
  L22   L28 1
  L2    L1  1
  L32   L3  1
  L12   L38 1
  L35   L15 1
  L36   L34 1
  L42   L49 1
  L29   L6  1
  L36   L44 1
  L31   L13 1
  L45   L20 1
  L18   L33 1
  L41   L11 1
  L1    L42 1
  L29   L22 1
  L3    L32 1
  L5    L49 1
  L45   L18 1
  L14   L48 1
  L21   L41 1
  L8    L31 1
  L45   L49 1
  L44   L20 1
  L11   L25 1
  L21   L26 1
  L40   L37 1
  L15   L48 1
  L4    L15 1
  L17   L7  1
  L13   L36 1
  L40   L48 1
  L43   L4  1
  L25   L6  1
  L26   L2  1
  L44   L5  1
  L23   L28 1
  L18   L41 1
  L37   L9  1
  L42   L43 1
  L15   L35 1
  L13   L3  1
  L13   L31 1
  L23   L47 1
  L49   L20 1
  L42   L1  1
  L4    L17 1
  L45   L32 1
  L11   L20 1
  L49   L43 1
  L42   L29 1
  L25   L50 1
  L25   L13 1
  L13   L39 1
  L44   L36 1
  L45   L50 1
  L22   L29 1
  L41   L18 1
  L20   L13 1
  L23   L5  1
  L43   L42 1
  L44   L26 1
  L36   L13 1
  L47   L49 1
  L41   L21 1
  ;


proc print data=simw_compact(obs=10);
  var SID cSID Value;
run;

/*-- SAR --*/

proc spatialreg data=simdata Wmat=simw_compact;
  model y=x1-x3 / type=SAR;
  spatialid SID;
run;

/*-- SEM --*/

proc spatialreg data=simdata Wmat=simw_compact;
  model y=x1-x3 / type=SEM;
  spatialid SID;
run;