spatialreg icon indicating copy to clipboard operation
spatialreg copied to clipboard

SDM indirect and direct effects

Open egrized-alt opened this issue 5 months ago β€’ 6 comments

Hello, I’m working with a Spatial Durbin Model using the spatialreg package. I would like to extract and save the direct and indirect effects for each observation and variable (not just the average effects).

I know this is not a very common request, but could anyone help me with some example scripts or guidance? Thanks a lot! Z

egrized-alt avatar Aug 22 '25 06:08 egrized-alt

Briefly, you may use the full inverse matrix by X-variable (termed by LeSage & Pace Sr(W)), as shown in this talk (see earlier talks for the model being considered) https://rsbivand.github.io/PG_AGII_2sem/11_talk.html#prediction-and-impacts. In that case the use is for prediction, but following Ward & Gleditch: Spatial Regression Models (Sage, 2018, 2nd edition, pp. 58-63) discuss the case you describe. It is also covered in LeSage & Pace: Introduction to Spatial Econometrics (CRC, 2008, pp. 34-39).

rsbivand avatar Aug 22 '25 11:08 rsbivand

Dear Professor Bivand, I would like to thank you in advance for taking the time to consider my question and for your assistance. I would also like to express my gratitude for the package itself, which provides substantial support in carrying out spatial econometric computations.

Within the framework of the Spatial Durbin Model (SDM), I analysed the augmented Solow model, where the dependent variable is gross value added per employee (GVA per worker), and the explanatory variables are physical capital stock, human capital, and population growth. The SDM results are overall satisfactory; I have calculated the average direct, indirect, and total effects.

Furthermore, using the matrix 𝐴(π‘Š)βˆ’1 (πΌπ‘›π›½π‘Ÿ+π‘Šπœƒπ‘Ÿ), I also determined the direct effects at the level of individual observations, as well as the effects originating from each observation. In the latter case, I used the column sums of the matrix and subtracted the diagonal element, in order to assess the extent to which a given observation exerts an effect on the entire sample.

These calculations were performed for both physical capital stock and human capital. However, a problem arose in that the two latter data series displayed perfect collinearity. I am uncertain whether this is the result of a computational error or rather a natural phenomenon. Should the latter be the case, I would appreciate advice on how this issue might best be addressed in the context of a publication. Once again, I am sincerely grateful for your time and for your kind attention to this question.

egrized-alt avatar Sep 02 '25 09:09 egrized-alt

Could you be more specific, and either use a minimal reproducible example from a built-in data set or make your code and data available? This may have happened as W may have led x and Wx to be very close, or Wx_1 to be close to Wx_2.

rsbivand avatar Sep 02 '25 09:09 rsbivand

Thank you for your reply and your time. I am attaching the database (Export2t.shp), the codes (script.txt), a csv and a Excel file (sdm_impacts_by_observation, direct_indirect_total).

My main objective is to model technological dependence across European regions within the framework of the augmented Solow model (reference: Fischer, Spatial Externalities and Growth in a Mankiw-Romer-Weil World: Theory and Evidence).

The dependent variable is gross value added per employee (lngvaemp), the independent variables are capital stock per employee (lncapstock), human capital (lnknow), and population growth (empch). The applied spatial weights matrix is queen contiguity.

In addition to the usual SDM estimation, I also want to model the effects originating from each region for both capital stock and human capital. I have calculated the direct effects by region, as well as the effects originating from each region, also by region, for both indicators. (I did this manually as well, which is contained in the 'direct_indirect_total' Excel file. The region-specific effects extracted by R are included in the 'sdm_impacts_by_observation' CSV file.)

So my main problem is that the effects are in perfect collinearity (r = 1); this can also be seen in the 'direct_indirect_total' Excel file ("correlation" sheet). My specific question is whether this outcome reflects a computational error, or if it is a natural phenomenon. (As you pointed out, part of the problem does exist: the correlation between wX1 and wX2 is indeed high, r = 0.74. Could this explain the perfect collinearity of the region-specific effects?) Thank you again for your time. I apologize in advance if my question reflects a misunderstanding or a trivial issue.

github.zip

egrized-alt avatar Sep 03 '25 07:09 egrized-alt

In practical terms, this is not collinearity but that when rowSums are used, the total impacts are always equal to the average total impacts (as.matrix is redundant). Using colSums appears to calculate unique values for each region (or transpose Mk). With impacts_df calculated with colSums, the averages are the average impacts:

> matrix(apply(impacts_df[,-1], 2, mean), 3, 3, byrow=TRUE)
            [,1]       [,2]       [,3]
[1,]  0.25765753  0.1959955  0.4536530
[2,]  0.37820415  0.2632670  0.6414712
[3,] -0.03855728 -0.3083807 -0.3469379
> impacts(reg6,listw=listw1)
Impact measures (mixed, exact):
                      Direct   Indirect      Total
lncapstock dy/dx  0.25765753  0.1959955  0.4536530
lnknow dy/dx      0.37820415  0.2632670  0.6414712
empch dy/dx      -0.03855728 -0.3083807 -0.3469379

rsbivand avatar Sep 03 '25 08:09 rsbivand

Thank you very much!

egrized-alt avatar Sep 13 '25 14:09 egrized-alt