使用 spdep 包中的 autocov_dist 函数时的错误消息

问题描述

我正在使用 autocov_dist 包中的函数 spdep 来估计无变量。我使用反距离作为权重。当我在我的数据上测试它时,我收到此错误消息:

Error in autocov_dist(Var,xy,nbs = 100,style = "B",type = "inverse") : is.vector(z) is not TRUE

这是一个可重复的示例(我在坐标中显示大值,因为在我的真实数据中,空间坐标在 UTM 中):

library(spdep)
 set.seed <- 123
 xy<- as.data.frame(cbind(rnorm(1000,100000,100),(rnorm(1000,500000,100))))
 Var <- rnorm(1000,2,1)
 autocov <- autocov_dist(Var,nbs=100,style="B",type="inverse")

另外,相邻半径(函数中的 nbs 参数)的确切定义是什么,因为我在函数文档中找不到明确的定义。

解决方法

要设置种子,您必须使用 aiohttp

set.seed(number) 需要是您已将其转换为数据框的矩阵。试试:

xy