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

ObsSIDcSIDValue
1L50L451
2L32L351
3L50L251
4L45L361
5L10L81
6L44L481
7L7L61
8L36L151
9L5L191
10L37L461


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

The CSPATIALREG Procedure

Parameter Estimates
ParameterDFEstimateStandard
Error
t ValueApprox
Pr > |t|
Intercept11.7806500.09870318.04<.0001
x110.5733290.04739512.10<.0001
x210.7070480.05718112.37<.0001
x31-0.9028430.053314-16.93<.0001
_rho1-0.4737130.063008-7.52<.0001
_sigma210.1315090.0263504.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

The CSPATIALREG Procedure

Parameter Estimates
ParameterDFEstimateStandard
Error
t ValueApprox
Pr > |t|
Intercept11.1662890.02951439.52<.0001
x110.4879750.0490869.94<.0001
x210.6344420.06177610.27<.0001
x31-0.8312500.054780-15.17<.0001
_lambda1-0.9648260.132514-7.28<.0001
_sigma210.1474340.0313184.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

The CSPATIALREG Procedure

Parameter Estimates
ParameterDFEstimateStandard
Error
t ValueApprox
Pr > |t|
Intercept11.7219370.11172015.41<.0001
x110.5767520.04743212.16<.0001
x210.6941000.05811811.94<.0001
x31-0.9108290.053061-17.17<.0001
_rho1-0.4348400.079844-5.45<.0001
_lambda10.3934320.3429121.150.2512
_sigma210.1332870.0279844.76<.0001


Output 13.3.5: Parameter Estimates of an SAC Model with Compact Representation

The CSPATIALREG Procedure

Parameter Estimates
ParameterDFEstimateStandard
Error
t ValueApprox
Pr > |t|
Intercept11.7451400.10896916.01<.0001
x110.5746300.04748112.10<.0001
x210.6998480.05754712.16<.0001
x31-0.9094160.053365-17.04<.0001
_rho1-0.4497440.075425-5.96<.0001
_lambda1-0.2359710.277450-0.850.3950
_sigma210.1288450.0259384.97<.0001


Last updated: July 09, 2026