[R] Distance matrix in SpDep-package
Roger.Bivand at nhh.no
Tue Oct 16 13:28:36 CEST 2007
Elke Moons <elke.moons <at> uhasselt.be> writes:
> Hello everybody,
> I would like to use the SpDep-package (especially the Local Moran index
> analysis and the Getis-Ord statistics) in R for analysing my data. However,
> I don't have x-y coordinates, but my data is in a distance matrix format. Is
> it possible to use the SpDep package with predefined distances as well
> instead of letting the program determining the distance itself by the
> function dnearneigh based on x-y coordinates. Or is there another package
> that can transform a distance matrix into "fake" x-y coordinates, so that
> the SpDep-package can work with it?
If you use the mat2listw() function in spdep on (slices of) your matrix,
you can get to usable listw objects. If the distance matrix is full
(that is all sites to all sites), you could impose very large values on
distances which fall outside a given slice, say outside 0-100m, to create a
listw object corresponding to a dnearneigh(xy, 0, 100) neighbours list.
See the mat2listw help page for more details:
The function converts a square spatial weights matrix to a weights
list object, optionally adding region IDs from the row names of
the matrix, as a sequence of numbers 1:nrow(x), or as given as an
Note that the input matrix is expected to contain spatial weights, so
inverse distances would be closer than distances in their native metric.
You should also look at the glist= argument to nb2listw() if you want
generalised spatial weights.
> Thank you very much for your answer.
> Kind regards,
> Elke Moons
> Elke Moons, PhD
> Transportation Research Institute/
> Instituut voor Mobiliteit (IMOB)
> Universiteit Hasselt
> Wetenschapspark 5, bus 6
> 3590 Diepenbeek
> Tel. +32-11- 26.91.26
> Fax. +32-11-26.91.99
> E-mail: <mailto:elke.moons <at> uhasselt.be> elke.moons <at> uhasselt.be
> [[alternative HTML version deleted]]
> R-help <at> r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help