Skip to content
Prev 27265 / 29559 Next

Question spdep package - lagsarlm not terminating

On Mon, 6 May 2019, Raphael Mesaric via R-sig-Geo wrote:

            
No, this is a misunderstanding. All weights matrices used for fitting 
models are square nxn matrices by definition. If your grid had r rows and 
c columns, n = r * c, and the weights matrix has n rows and n columns.
By default, observations with missing values are dropped and the weights 
object is subsetted to match. This may produce no-neighbour observations. 
You can choose to set their spatially lagged values to zero by using 
zero.policy=TRUE, which is the probable cause of your error. It could very 
well be that your weights object itself contains no-neighbour observations 
if not created using spdep::nb2listw() - which will alert you to the 
problem.
Please do not use references online (especially if you do not link to 
them). The information you need is in the help page, referring to the 
tol.solve= argument. Indeed, your covariates are scaled such that their 
are either colinear (unlikely), or that the numerical values of the 
coefficient variances are very different from the spatial coefficient. You 
may need to re-scale the response or covariates in order to invert the 
matrix needed to yield the variances of the coefficients.
spdep::subset.nb() only. Your suggestion only creates a big mess, as 
subsetting reduces the number of rows, and neighbours are indexed between 
1 and n. Consequently, at least some of the remaining vectors will point 
to neighbours with ids > n, and many of the others will point to the wrong 
neighbours. You can convert to a sparse matrix, subset using "[", and then 
convert back, but the subset method should work.
I do not know what you mean, of course it has to remove links in both 
directions.
I always advise against using GWR for anything other than studies 
exploring its weaknesses - do not use in research or production. Just 
showing the error message without a small reproducible example using a 
built-in data set gives nothing to go on. Does the error occur when using 
print() on a fitted object? Maybe NAs in coefficients 
suggests colinearity in your covariates, possibly after weighting.
But it is terribly easy to introduce them numerically, so they are coming 
from what you are doing.

Roger