[R] Distance matrix for Spatial Filtering {spdep}

Erica Cseko Nolasco ecnolasco at gmail.com
Sat Nov 8 16:16:38 CET 2014


Hi all,

I´m working on a species distribution modeling, and I want to build
eigenvectors to represent my spatial varuable. I´m trying to use
SpatialFiltering(spdep) for it, but I´m having problems to create the nb
object. My weights would be a truncated pairwise distance matrix that I was
pretty able to build. However, I´m going out resources to create a nb
object. Or it doesn´t match the matrix or the R-Studio crashes. Here is the
code I´m trying:

> ###creating the distance matrix

> library(fossil)

> setwd("G:/database/mapas/registros")

> coo=read.table("coordinates16.txt",sep=" ")

> coor1=as.data.frame(coo)

> length(coor1[,1]

[1] 4922

> matriz3=earth.dist(coor1, dist=T)

> length(matriz3)

[1] 12110581

> ###truncating the distance matrix

> matriz3[matriz3>=230]=230
> ###creating the nb object to link to the distance matrix

> library(spdep)

>coord=read.table("coordinates16.txt",sep=" ", header=T)

> coo=cbind(coord[,1],coord[,2])

> length(coo[,1])
[1] 4922

>nb=dnearneigh(coo,0, 10000, longlat=T) ###large nb (4922 elements,92.9Mb)

> nb2listw(nb,glist=matriz3,style="W")

*Error in nb2listw(nb, glist = matriz3, style = "W") : glist wrong length*

>nb=knearneigh(coo,4921,longlat=T) ##second try to create nb, 4921 is the
required number for my project

*R session aborted. R encoutered a fatal error. The session was terminated*

>nb=knearneigh(coo,1000,longlat=T) ##second try to create nb

*R session aborted. R encoutered a fatal error. The session was terminated*

> nb=knearneigh(coo,500,longlat=T) ###tentativa de criar nb

*Error in knearneigh(coo, 500, longlat = T) : too many ties in knearneigh*

>nb=knearneigh(coo,400,longlat=T) #Large knn (5 elements,7.6Mb), I believe
I need the same number of elements as my distance matrix (12110581)

> nb2listw(nb,glist=matriz3,style="W")

*Error in nb2listw(nb, glist = matriz3, style = "W") : *
  *Not a neighbours list*

Any ideas would help a lot! Thanks in advance

*Erica Csekö Nolasco*
Mestranda em Modelagem em Ciências da Terra e do Ambiente
http://lattes.cnpq.br/2117508819823917
Laboratório de Ornitologia - Sala 03, LABIO
Universidade Estadual de Feira de Santana
Avenida Transnordestina s/n, Novo Horizonte
Feira de Santana - BA, Brasil CEP 44.036-900.
Tel/Fax: 55(75)3224-8295

Graduate Student in Modeling of Environmental and Earth Sciences
http://lattes.cnpq.br/2117508819823917
Ornithology Lab - 03 room, LABIO
Universidade Estadual de Feira de Santana
Transnordestina Ave, Novo Horizonte
Feira de Santana - BA, Brazil 44.036-900.
55(75)3224-8295

	[[alternative HTML version deleted]]



More information about the R-help mailing list