【发布时间】:2018-01-02 11:40:19
【问题描述】:
我想根据距离创建一个权重矩阵。我目前的代码如下所示,并且适用于较小的数据样本。但是,对于大型数据集(24077 个位置的 569424 个人),它不会通过。问题出现在 nb2blocknb 函数中。所以我的问题是:如何针对大型数据集优化我的代码?
# load all survey data
DHS <- read.csv("Daten/final.csv")
attach(DHS)
# define coordinates matrix
coormat <- cbind(DHS$location, DHS$lon_s, DHS$lat_s)
coorm <- cbind(DHS$lon_s, DHS$lat_s)
colnames(coormat) <- c("location", "lon_s", "lat_s")
coo <- cbind(unique(coormat))
c <- as.data.frame(coo)
coor <- cbind(c$lon_s, c$lat_s)
# get a list with beneighbored locations thath are inbetween 50 km distance
neighbor <- dnearneigh(coor, d1 = 0, d2 = 50, row.names=c$location, longlat=TRUE, bound=c("GE", "LE"))
# get neighborhood list on individual level
nb <- nb2blocknb(neighbor, as.character(DHS$location)))
# weight matrix in list format
nbweights.lw <- nb2listw(nb, style="B", zero.policy=TRUE)
非常感谢您的帮助!
【问题讨论】:
-
dnearneigh和nb2blocknb函数从何而来?请同时指定使用的包。 -
它们来自 spdep 包
标签: r parallel-processing bigdata gis geospatial