Skip to content

Error in impacts() after lagsarlm (spdep package)

2 messages · Denys Dukhovnov, Roger Bivand

#
I posted this question on StackOverflow a while back but received no answer.?

I have 9,150 polygons in my data set. I was trying to run a spatial autoregressive model (SAR) in?spdep?to test spatial dependence of my outcome variable. After running the model, I wanted to examine the direct/indirect impacts, but encountered an error that seems to have something to do with the length of neighbors in the weights matrix not being equal to?n. I tried running the very same equation as SLX model (Spatial Lag X), and?impacts()?worked fine, even though there were some polygons in my set that had no neighbors.?
? ? length(listweights$neighbours) == n is not TRUE

What am I doing wrong? I am running Windows 10 machine with R 3.5.3 with the most up-to-date spdep package, if it helps.

Thank you very much.

Regards,
Denys Dukhovnov
#
On Wed, 13 Nov 2019, Denys Dukhovnov via R-sig-Geo wrote:

            
I maintain the spatialreg package to which I think you are referring. I 
never visit SO, both to save time and because the signal/noise ratio there 
is not encouraging (with exceptions where reproducible examples are used).

While your post was pain text (thanks), what you copied from SO got rather 
mangled. The spdep package does warn you that the functions you are using 
are deprecated and are actually to be called from spatialreg.
You are completely unnecessarily using the "eigen" method. If your weights 
are symmetric, use Cholesky decomposition ("Matrix"), much faster, same 
output.
Never, ever, do this. Did you read LeSage & Pace? Use traces, not the 
weights themselves. With the listw object, you need to invert an nxn 
matrix once in this case, 1+R times if you run Monte Carlo simulations.

If you provide a reproducible example using built-in data, I can try to 
provide a more informative error message.
R is at 3.6.1.

Hope this clarifies,

Roger