[R-sig-Geo] distribution of distance for lags (spdep package)
Roger Bivand
Roger.Bivand at nhh.no
Wed Oct 4 12:34:16 CEST 2006
On Tue, 3 Oct 2006, Horacio wrote:
> Dear R-geo people,
>
> I just discovered the beauty of the spdep package to make spatial
> analysis of point data easier... However, as I am climbing the learning
> curve I have a question regarding the estimation of the the lag in the
> Moran and/or corelogram function.
>
> As I understand, if the you generate a neighbor-list using the
> knearneigh
> <http://finzi.psych.upenn.edu/R/library/spdep/html/knearneigh.html>
> function you get a 'knn' class of the points I k distance apart. Then
> when you calculate the Moran's I (at least that's what I did) you get
> the Lag in terms of the number of links which in practical purposes is
> k. so, the first correlation value (od Moran's I) is the obtained by
> comaring all the sites that have a direct link between them, then, the
> second lag does it in terms of the ones that are 2 links apart and so on...
>
> My question is perhaps very simple... How can I generate a list to plot
> the distribution of distances for each lag? I thought nbdists could do
> it, but are not sure how to go about it...
>
You are on the right track. Here is an example:
data(columbus)
col.lags <- nblag(col.gal.nb, 4)
# to get a list of neighbour lists at increasing lags
ldists <- lapply(col.lags, function(x) nbdists(x, coords))
# to get a list of lists of distances
ldists1 <- lapply(ldists, unlist)
# to flatten the list to contain vectors of distances, as shown by:
str(ldists1)
# but note that each link is included, both i-j and j-i
sapply(ldists1, summary)
# for example will give a summary or more complicated:
dens <- lapply(ldists1, function(x) density(x, bw=0.1, from=0, to=3.1))
plot(c(0,3.1), c(0,max(sapply(dens, function(x) max(x$y)))), type="n",
xlab="distance", ylab="density")
lapply(1:4, function(i) lines(dens[[i]]$x, dens[[i]]$y, lty=i))
for a density plot.
Thanks for the question, I can see that summary.nb() needs a rewrite which
would have made this a bit easier.
Roger
>
> thank you
>
>
>
> Horacio
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list