我对带有'spdep'软件包的SAR模型的执行时间有疑问。
我将两个相同维度的不同数据集传递给相同的函数,这需要非常不同的时间(几秒钟对几小时)。
我给您写了我的代码,如果您有任何想法请告诉我。
谢谢 基亚拉
library(spdep)
data(house, package="spData")
hlw<-nb2listw(LO_nb)
system.time( lagsarlm(log(price) ~ age, data=house, listw=hlw, type="lag", method="Matrix", trs=trMat))
#----------------------------------------------
library(spatstat)
d1<-100
d2<-100
n<-25357
coord<- runifpoint(n,win=owin(c(0,d1),c(0,d2)))
mat<-cbind(coord$x,coord$y)
X<-rnorm(n,5,2)
Y<-rnorm(n,5,3)
d<-as.data.frame(cbind(X,Y))
cutoff<- dnearneigh(mat,0,4)
t<-nb2listw(cutoff)
system.time( lagsarlm(Y ~ X, data=d, listw=t, type="lag", method="Matrix"))
答案 0 :(得分:0)
我知道了
[[[1],[2],[3]],[[4],[5],[6]]]
library(spdep)
data(house, package = "spData")
dim(house)
hlw <- nb2listw(LO_nb)
# Number of nonzero links: 74874
system.time(r1 <- lagsarlm(log(price) ~ age, data=house, listw=hlw,
type="lag", method="Matrix", trs=trMat))
# user system elapsed
# 0.50 0.05 0.55
#----------------------------------------------
library(spatstat)
set.seed(21)
d1 <- 100
d2 <- 100
coord <- runifpoint(n, win = owin(c(0, d1), c(0, d2)))
mat <- cbind(coord$x, coord$y)
cutoff <- dnearneigh(mat, 0, 4)
t <- nb2listw(cutoff)
t
# Number of nonzero links: 3119764
n <- 25357
X <- rnorm(n,5,2)
Y <- rnorm(n,5,3)
d <- as.data.frame(cbind(X,Y))
system.time(r2 <- lagsarlm(Y ~ X, listw = t, type = "lag", method = "Matrix"))
# user system elapsed
# 156.47 8.54 168.25
# v2
d1 <- 200
d2 <- 200
coord <- runifpoint(n, win = owin(c(0, d1), c(0, d2)))
mat <- cbind(coord$x, coord$y)
cutoff <- dnearneigh(mat, 0, 4)
t <- nb2listw(cutoff)
t
# Number of nonzero links: 795054
system.time(r2 <- lagsarlm(Y ~ X, listw = t, type = "lag", method = "Matrix"))
# user system elapsed
# 13.42 2.02 15.61
的时间似乎取决于t的非零链接数。