CSPATIALREG Procedure
Example 13.3 Compact Representation of a Spatial Weights Matrix
When a spatial weights matrix is sparse, you might want to provide its compact representation rather than the full matrix to the CSPATIALREG procedure. This example shows you how to use the compact representation of a spatial weights matrix in PROC CSPATIALREG. For illustration, the simulated data sets SimData and SimW from Simulated Data Example are used here. The compact representation of the spatial weights matrix in the SimW data set is created and saved in the data set SimW_Compact.
The first 10 observations in the SimW_Compact data set are shown in Output 13.3.1.
Output 13.3.1: SimW_Compact Data Set
| Obs | SID | cSID | Value |
|---|---|---|---|
| 1 | L50 | L45 | 1 |
| 2 | L32 | L35 | 1 |
| 3 | L50 | L25 | 1 |
| 4 | L45 | L36 | 1 |
| 5 | L10 | L8 | 1 |
| 6 | L44 | L48 | 1 |
| 7 | L7 | L6 | 1 |
| 8 | L36 | L15 | 1 |
| 9 | L5 | L19 | 1 |
| 10 | L37 | L46 | 1 |
To fit a spatial autoregressive (SAR) model, you can use the following statements:
/*-- SAR --*/
proc cspatialreg data=mylib.SimData Wmat=mylib.SimW_Compact;
model y=x1-x3 / type=SAR;
spatialid SID;
run;
The parameter estimates for this model are shown in Output 13.3.2.
Output 13.3.2: Parameter Estimates of SAR Model with Compact Representation
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | t Value | Approx Pr > |t| |
| Intercept | 1 | 1.780650 | 0.098703 | 18.04 | <.0001 |
| x1 | 1 | 0.573329 | 0.047395 | 12.10 | <.0001 |
| x2 | 1 | 0.707048 | 0.057181 | 12.37 | <.0001 |
| x3 | 1 | -0.902843 | 0.053314 | -16.93 | <.0001 |
| _rho | 1 | -0.473713 | 0.063008 | -7.52 | <.0001 |
| _sigma2 | 1 | 0.131509 | 0.026350 | 4.99 | <.0001 |
To fit a spatial error model (SEM) instead of a SAR model to the data, you can use the following statements:
/*-- SEM --*/
proc cspatialreg data=mylib.SimData Wmat=mylib.SimW_Compact;
model y=x1-x3 / type=SEM;
spatialid SID;
run;
The parameter estimates for this model are shown in Output 13.3.3.
Output 13.3.3: Parameter Estimates of SEM with Compact Representation
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | t Value | Approx Pr > |t| |
| Intercept | 1 | 1.166289 | 0.029514 | 39.52 | <.0001 |
| x1 | 1 | 0.487975 | 0.049086 | 9.94 | <.0001 |
| x2 | 1 | 0.634442 | 0.061776 | 10.27 | <.0001 |
| x3 | 1 | -0.831250 | 0.054780 | -15.17 | <.0001 |
| _lambda | 1 | -0.964826 | 0.132514 | -7.28 | <.0001 |
| _sigma2 | 1 | 0.147434 | 0.031318 | 4.71 | <.0001 |
If you want to fit another type of model, you need to change the value of the TYPE= option in the MODEL statement. For example, to fit a spatial autoregressive moving average (SARMA) model and a spatial autoregressive confused (SAC) model to the data, you can use the following statements:
/*-- SARMA --*/
proc cspatialreg data=mylib.SimData Wmat=mylib.SimW_Compact;
model y=x1-x3 / type=SARMA;
spatialid SID;
run;
/*-- SAC --*/
proc cspatialreg data=mylib.SimData Wmat=mylib.SimW_Compact;
model y=x1-x3 / type=SAC;
spatialid SID;
run;
The parameter estimates for the SARMA and SAC models are shown in Output 13.3.4 and Output 13.3.5, respectively.
Output 13.3.4: Parameter Estimates of a SARMA Model with Compact Representation
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | t Value | Approx Pr > |t| |
| Intercept | 1 | 1.721937 | 0.111720 | 15.41 | <.0001 |
| x1 | 1 | 0.576752 | 0.047432 | 12.16 | <.0001 |
| x2 | 1 | 0.694100 | 0.058118 | 11.94 | <.0001 |
| x3 | 1 | -0.910829 | 0.053061 | -17.17 | <.0001 |
| _rho | 1 | -0.434840 | 0.079844 | -5.45 | <.0001 |
| _lambda | 1 | 0.393432 | 0.342912 | 1.15 | 0.2512 |
| _sigma2 | 1 | 0.133287 | 0.027984 | 4.76 | <.0001 |
Output 13.3.5: Parameter Estimates of an SAC Model with Compact Representation
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | t Value | Approx Pr > |t| |
| Intercept | 1 | 1.745140 | 0.108969 | 16.01 | <.0001 |
| x1 | 1 | 0.574630 | 0.047481 | 12.10 | <.0001 |
| x2 | 1 | 0.699848 | 0.057547 | 12.16 | <.0001 |
| x3 | 1 | -0.909416 | 0.053365 | -17.04 | <.0001 |
| _rho | 1 | -0.449744 | 0.075425 | -5.96 | <.0001 |
| _lambda | 1 | -0.235971 | 0.277450 | -0.85 | 0.3950 |
| _sigma2 | 1 | 0.128845 | 0.025938 | 4.97 | <.0001 |