About dnearneight and nb2listw function

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

About dnearneight and nb2listw function

Leticia Canton
In my Ph.D. I am comparing Lee and Anselin's methodology for estimating bivariate spatial autocorrelation. Lee's methodology led me to the spdep package. My questions are as follows:

1) The weight matrix W, which is part of the  "nb2listw" function. First, is it possible to view all elements of this matrix? Because I could only visualize the elements whose autocorrelation is not null. That would be enough, but I need to present this matrix and visualize the autocorrelation between all points. That is, knowing what are the coordinates of the points where the autocorrelation is nonzero and also where it is null.

2) In the "dnearneight" function, is it possible to view the matrix of neighbors? Because getting this matrix, would be able to standardize and get the matrix of weights W without using the nb2list function.

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]]


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: About dnearneight and nb2listw function

Roger Bivand
Administrator
On Thu, 31 Oct 2019, Letícia Dal' Canton wrote:

> In my Ph.D. I am comparing Lee and Anselin's methodology for estimating
> bivariate spatial autocorrelation. Lee's methodology led me to the spdep
> package. My questions are as follows:
>
> 1) The weight matrix W, which is part of the "nb2listw" function. First,
>    is it possible to view all elements of this matrix? Because I could
>    only visualize the elements whose autocorrelation is not null. That
>    would be enough, but I need to present this matrix and visualize the
>    autocorrelation between all points. That is, knowing what are the
>    coordinates of the points where the autocorrelation is nonzero and
>    also where it is null.
This is very unclear. Yes, nb2mat() gives a dense matrix, but you do not
show how you "visualize the elements whose autocorrelation is not null".
You need to add a reproducible example using a built-in data set. Note
that the matrix showing the variance-covariance of the observations is
dense by definition (I - \rho W)^{-1} - see Melanie Wall's 2004 article.

>
> 2) In the "dnearneight" function, is it possible to view the matrix of
>    neighbors? Because getting this matrix, would be able to standardize
>    and get the matrix of weights W without using the nb2list function.

You do not explain why this makes sense. Of course you can use nb2mat(),
listw2mat() or coerce a listw object to a sparse matrix, but you need to
motivate this (best with an example).

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: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

About dnearneight and nb2listw function

Leticia Canton
In reply to this post by Leticia Canton
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?

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?

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]]


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: About dnearneight and nb2listw function

Roger Bivand
Administrator
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: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway