Skip to content
Prev 907 / 29559 Next

inverse distance weights matrix

Thanks Roger,

I've been working on creating inverse distance matrices; and have been
successful in this first step.  However, as you suggested, the
connectedness of these matrices will cause procedures to be slow, even
prohibitive with my computer (P4 3Gz 1GB RAM) (ran out of RAM).

I've tried a simpler first order queen weights matrix to see if I could
get the errorsarlm model to run; but come to a different problem and an
error message:

source("spat.cot.R")
Error in solve.default(asyvar, tol = tol.solve) : 
        system is computationally singular: reciprocal condition number
= 1.16119e-019
6: solve.default(asyvar, tol = tol.solve)
5: solve(asyvar, tol = tol.solve)
4: errorsarlm(YLD02 ~ CLAY + DIST + PEG + ROT + SUN, data = cotton, 
       q1)
3: eval.with.vis(expr, envir, enclos)
2: eval.with.vis(ei, envir)
1: source("spat.cot.R")

where "spat.cot.R" contains:
spatcot.err<-errorsarlm(YLD02~CLAY+DIST+PEG+ROT+SUN,data=cotton, q1)

Do I need to set my tol to a different value or am I having other
issues?

Thank you,

Terry
  



-----Original Message-----
From: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
Sent: Saturday, March 18, 2006 3:07 PM
To: Griffin, Terry W
Cc: r-sig-geo at stat.math.ethz.ch
Subject: RE: [R-sig-Geo] inverse distance weights matrix
On Sat, 18 Mar 2006, Griffin, Terry W wrote:

            
of
OK - it looks like this at the moment:

library(rgdal)
cotton_proj <- readOGR(".", "cotton_proj") # for shapefiles in the
current
			# working directory, first argument
plot(cotton_proj, cex=0.2, axes=TRUE)
library(spdep)
d75 <- dnearneigh(coordinates(cotton_proj), 0, 75)
dlist <- nbdists(d75, coordinates(cotton_proj))
idlist <- lapply(dlist, function(x) 1/x)
w75 <- nb2listw(d75, glist=idlist, style="W")

Characteristics of d75:
Neighbour list object:
Number of regions: 2451 
Number of nonzero links: 1182994 
Percentage nonzero weights: 19.69228 
Average number of links: 482.6577 

But:
+ byrow=TRUE)
[1] 0.8159028 1.9115231
[1] 1 1
[1] 1 1

So something in the construction of your matrix wasn't securing row 
standardisation. The values do differ, this is the upper left corner:
[,1]       [,2]       [,3]       [,4]       [,5]
1 0.00000000 0.06735710 0.03227068 0.02182278 0.01660474
2 0.05975093 0.00000000 0.05493976 0.02863058 0.01954588
3 0.02615210 0.05019078 0.00000000 0.05461937 0.02771729
4 0.01639324 0.02424508 0.05062943 0.00000000 0.05216365
5 0.01172946 0.01556467 0.02416008 0.04905229 0.00000000
[,1]     [,2]     [,3]     [,4]     [,5]
[1,] 0.000000 0.131420 0.061844 0.041726 0.031848
[2,] 0.101440 0.000000 0.090156 0.047180 0.032441
[3,] 0.040305 0.076122 0.000000 0.083545 0.042787
[4,] 0.023708 0.034730 0.072836 0.000000 0.076431
[5,] 0.016296 0.021506 0.033593 0.068830 0.000000
[1] 1.911523 1.658689 1.533153 1.440908 1.379051
1 2 3 4 5 
1 1 1 1 1 

They are not the same matrices, although the differences are very small
- 
here I've used the shapefile points, which are stored as binary floating

point, rather than using the DBF values, which are a possibly rounded 
character representation, and that might be enough to cause the 
difference. I think you should be able to generate w75, and that it
should 
do what you need, but I'd be grateful for feedback on how you get on.

Best wishes,

Roger

PS: with numbers of neighbours between 177 and 678 (both in your matrix 
and in d75), even allowing for the dampening effect of inverse distance,

most analyses will be slow. 75m means that many sites are related to
many 
in your case. Doing:

symbols(408725, 3660800, circles=75, inches=FALSE, fg="red", add=TRUE)

on top of the earlier plot shows your chosen neighbourhood for an 
arbitrary point.
so
error
full
permanent
matrices
in
format
20
error
also
what