# model two spatial auto correlation in spdep package in r

I hope to fit the spatial autoregressive model : $$y= \gamma_1 Wy + \gamma_2 By + X\beta +\epsilon. \quad (1)$$ where $W, B$ are different weight matrices. However, every references I've found only mention the SAR model that estimates one autocorrelation, i.e. $$y= \gamma_1 Wy + X\beta +\epsilon ,$$ which can be fitted by using lagsarlm function in the R package spdep.

Therefore, I wonder if I could fit the model (1).

I emailed to the author, Roger Bivand, who has developed the spdep package to ask this question.

Prof.Bivand, who kindly answered and gave me more suggestions, said :

"There are no such fitting functions implemented anywhere, to the best of my knowledge."

Thanks for anyone giving interest on this question.

Without knowing more about $W$ and $B$ (or why you would theoretically want to include two different weight matrices), I can't be sure that this directly answers your question. But, Spatial Durbin and Spatial Durbin-Watson models can be estimated with maximum likelihood, without having to use the spdep package. And there are many options in R for MLE. You might also consider some form of a two-stage or simultaneous equation model. For example, fit the model first with with $W$, and then use your predicted values from this in the second model with $B$. But again, the right specification will depend on your theory of the relationship between $y$, $By$, and $Wy$.

• Sure thing. And also$\dots$ you should think through the implications of this, but I'd note that your model with two spatial-lags looks very similar to a model with a spatial-lag + a time-lag, which are not uncommon. And, these models can be estimated with little difficulty, so perhaps worth considering how this might relate to a model with 2x spatial lag? I was assuming that one of your matrices was inverse-distance on $y$ or similar, but I couldn't guess your other matrix. You might get better answers if you updated your question. Jun 2, 2016 at 15:56
• For "inspiration," Franzese and Hays have a number of articles, with very well-worked examples, e.g., Empirical Models of Spatial Interdependence. Though, depending on your field, these examples may be more/less relevant. Jun 2, 2016 at 16:00
• Thanks for your response and comment :) In fact, $W$ is a within-district weight matrix and $B$ is a between-district weight matrix, and I hope to detect within or between effects simultaneously. (I missed editing my answer, sorry) Jun 2, 2016 at 16:01
• Okay, I see your thinking there, and that makes sense. But again, without knowing the details of your data/theory, I'd nevertheless suggest in this case not using the above suggestion (answer) but instead specifying the within-weight not as a spatial-lag but as a random effect. The intra-class correlation (ICC) for within-district will then give you information on within-distict-homogeneity, controlling for between ($B$) dependence. On ICC with random effects, perhaps here is helpful. Jun 2, 2016 at 16:19
• thanks for sharing your ideas. I'd be happy to search those possible models with your kind links. Thanks so much again. Jun 2, 2016 at 16:44