我有一个大约180.000 m ^ 2多边形的shp,我想创建一个女王连续性权重矩阵(行标准化)。
但是我只得到错误:
Error: cannot allocate vector of size 232.4 Gb
我曾尝试使用像这里(R spdep giant weight matrix)这样的biglibrary,但这只是给了我:
Error in big.matrix(n, n, type = "double", init = NULL) :
Error: memory could not be allocated for instance of type big.matrix
有解决方法吗?
我已经在使用具有64 GB Ram的服务器。
尝试了这个:
queen_nb <- poly2nb(shp, row.names=shp$ID, queen=T)
W.list.queen <- nb2listw(queen_nb, style="W", zero.policy = TRUE)
W.queen <- listw2mat(W.list.queen)
这:
my_listw2mat = function (listw)
{
require(bigmemory)
n <- length(listw$neighbours)
if (n < 1)
stop("non-positive number of entities")
cardnb <- card(listw$neighbours)
if (any(is.na(unlist(listw$weights))))
stop("NAs in general weights list")
#res <- matrix(0, nrow = n, ncol = n)
res <- big.matrix(n, n, type='double', init=NULL)
options(bigmemory.allow.dimnames=TRUE)
for (i in 1:n) if (cardnb[i] > 0)
res[i, listw$neighbours[[i]]] <- listw$weights[[i]]
if (!is.null(attr(listw, "region.id")))
row.names(res) <- attr(listw, "region.id")
res
}
test.matrix <- my_listw2mat(neighbours = W.list.queen, style='W',zero.policy = TRUE)