[R-sig-Geo] listw for local Moran in spdep
Agustin Lobo
alobolistas at gmail.com
Tue Feb 8 10:35:41 CET 2011
Thanks. I have problems to understand the order in which I have to
input the data from the matrix.
This is what I'm doing:
require(spdep)
gpclibPermit()
require(ncf)
#data
x <- expand.grid(1:20, 1:5)[,1]
y <- expand.grid(1:20, 1:5)[,2]
zori <- rmvn.spa(x=x, y=y, p=2, method="exp")
z = scale(zori)
dim(z)=c(20,5)
z = t(z)[5:1,]
rz = raster(z)
#weights
wrz = cell2nb(nrow=nrow(rz), ncol=ncol(rz), type="queen", torus=FALSE)
#lisa
lisarz = localmoran(x=rz at data@values, listw=nb2listw(wrz))
(but I do not know if the ordering of the data x and the weights listw
are matching)
l3r = lisarz[,1]
dim(l3r)=c(20,5)
l3r = t(l3r)[5:1,]
l3r = raster(l3r)
plot(l3r)
Agus
2011/2/7 Roger Bivand <Roger.Bivand at nhh.no>:
> On Mon, 7 Feb 2011, Agustin Lobo wrote:
>
>> Hi!
>>
>> I'd like to run localmoran() from spdep on a small grid (matrix). Is
>> there a function to calculate the spatial weights (listw) from
>> the grid (defining 3x3 neighborhoods)?
>
> For a 3x3 neighbourhood on a grid simply defined by numbers of rows and
> columnd, see ?cell2nb. Otherwise, use dnearneigh() with the threshold set to
> the length of the diagonal distance between cell centres giving the cell
> centre coordinates as input.
>
>>
>> (BTW: the definition of LISA in the spdep manual is unformatted)
>>
>
> The LaTeX version looks fine! I'll try to repair the regular page.
>
> Roger
>
>> Thanks
>>
>> Agus
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
More information about the R-sig-Geo
mailing list