[R-sig-Geo] About dnearneight and nb2listw function

Roger Bivand Roger@B|v@nd @end|ng |rom nhh@no
Tue Nov 5 15:20:55 CET 2019


On Mon, 4 Nov 2019, Letícia Dal' Canton wrote:

> I am forwarding the routine used and the part of the database I am 
> interested in, which uses georeferenced agricultural data.
>
> require(spdep)
> require(geoR)
>
> dados = read.geodata("test.txt", header = T)
> dados
>
> coord=dados$coord
>
> max(dist(coord))/2
>
> grid = dnearneigh(dados$coord, 0, 880)
>
> lw=nb2listw(grid,zero.policy=TRUE)
>
>
> From this routine, I will try to explain more clearly what my doubts 
> are:
>
> 1) The "dnearneight" function provides the neighbor list object. Is
>    there any way to numerically visualize who the neighbors are?

"numerically visualize" is not clear. Do you mean "show me who is 
neighbour of whom"?

library(spdep)
example(columbus, package="spData")
col.gal.nb # print method for nb objects
print.default(col.gal.nb) # treating nb as a list
col.gal.nb[[1]] # neighbours of observation 1

See also the package vignette vignette("nb_igraph") or: 
https://r-spatial.github.io/spdep/articles/nb_igraph.html
https://cran.r-project.org/web/packages/spdep/vignettes/nb_igraph.html

>
> 2) The "nb2listw" function provides the "Characteristics of weights list
>    object". When requesting the weights (lw$w in the routine), the n
>    points are listed and values are assigned (who are these values?) And
>    why are not the n values associated to the remaining n-1. Because in
>    "attr (," comp ") $ d" it is noticeable that each point is associated
>    to a different amount of points. For example, with the database used,
>    the first point is associated to another 57, the second to another
>    65. Why does this occur?

No idea, your data are not available. If you posted HTML, they were 
certainly discarded as risky. Post plain text only, and provide data on a 
link, not verbatim. If you set the distance threshold to 800, probably 
some observations were further than 800 units apart.

all.equal(attr(nb2listw(col.gal.nb)$weights, "comp")$d, card(col.gal.nb))

shows that in this case (row standardisation), the d vector is the same as 
the neighbour count per observation - it does not have to be so.

Roger

>
> Thankfully,
>
>
> Let???cia Dal' Canton.
>
> Matem???tica.
> Mestre em Engenharia Agr???cola.
> Doutoranda em Engenharia Agr???cola com linha de pesquisa em Estat???stica Espacial.
> Universidade Estadual do Oeste do Paran??? - UNIOESTE.
>
> Curr???culo Lattes: http://lattes.cnpq.br/1085422685501012.
> Contato: (45) 9 9962-7492.
>
> 	[[alternative HTML version deleted]]
>
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand using nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en


More information about the R-sig-Geo mailing list