[R-sig-Geo] Create listw or nb object from binary edge matrix
Roger Bivand
Roger.Bivand at nhh.no
Sat Feb 28 22:07:45 CET 2015
On Sat, 28 Feb 2015, jcoyle wrote:
> I am trying to create an nb or listw object for use with spdep functions from
> a binary matrix with 1 indicating that two 'regions' are neighbors. However,
> the following code does not produce a neighbors list as I think it should
> after reading this previous post
> <https://stat.ethz.ch/pipermail/r-sig-geo/2009-February/005070.html> :mat =
> matrix(0, 4, 4)mat[1,2] = 1mat[2,1] = 1mat[3,4] = 1mat[4,3] = 1lw =
> mat2listw(mat)lw$neighborsWhat am I doing wrong?Thanks!Jes
>
I suppose you meant:
library(spdep)
mat = matrix(0, 4, 4)
mat[1,2] = 1
mat[2,1] = 1
mat[3,4] = 1
mat[4,3] = 1
mat
lw = mat2listw(mat)
lw$neighbors
but
lw$neighbours
is OK, as:
all.equal(nb2mat(lw$neighbours, style="B"), mat, check.attributes=FALSE)
shows. Use of British English spelling is rooted in usage in Cliff & Ord
(1973).
Roger
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Create-listw-or-nb-object-from-binary-edge-matrix-tp7587849.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list