【问题标题】:execution time spatial models in rr中的执行时间空间模型
【发布时间】:2018-08-06 17:04:46
【问题描述】:

我对使用“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"))

【问题讨论】:

    标签: r performance statistics spdep


    【解决方案1】:

    我明白了:

    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 
    

    似乎lagsarlm 的时间取决于 t`s Number of nonzero links..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-16
      • 2014-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-26
      相关资源
      最近更新 更多