2
    library(doParallel)
    library(foreach)
    library(raster)
    library(snow)
    library(spgwr)
    library(maptools)
    library(GWmodel)
    library(e1071)
    library(sp)

我正在尝试指定用于运行地理加权回归的集群数量。我有一堆已转换为数据框的 9 个栅格。我是否收到以下错误(最后)并且不知道如何解释错误,因为我能说的一切看起来都是正确的。示例 df.notmissing:

    #x         y       temperature distance_patches tpi impervious treecanopy ndvi   baylands  buildings percent_patches not_missing
    #-2254439 1895333          42              300 15.6         54       20.1 0.27    13000         4               0        TRUE
    #-2255904 1890878          41             1204 19.7         44       75.2 0.52    18000         0               0        TRUE
    #-2251748 1893330          43             1082  9.5         94       25.9 0.07    14000         6               0        TRUE
    #-2253093 1896021          43              224  9.6         46       20.7 0.29    12000         0               0        TRUE
    #-2249535 1892613          42              539 10.1         81       10.9 0.16    15000         0               0        TRUE
    #-2247891 1895483          43              949  5.9         89       21.7 0.30    12000         0               0        TRUE
    #-2244931 1893181          42              283  4.7         31       30.8 0.37    15000         0               0        TRUE
    #-2253751 1894466          42              500 15.2         38       25.7 0.38    14000         0               0        TRUE
    #-2257399 1897606          42              762 19.0         51       22.5 0.27    12000        25               0        TRUE
    #-2251808 1896858          45             1000  8.3         87        2.2 0.21    11000        35               0        TRUE

我想使用 spgwr 库运行 gwr。没有 clusterR 的 gwr 如下所示:

     gwr.model <- gwr(temperature ~ treecanopy + tpi + impervious + treecanopy + ndvi + percent_patches + distance_patches + baylands + buildings, 
                      data=df.notmissing, 
                      #coords=cbind(x,y), # object is already a spatial object so don't need to specify coords in gwr function
                      adapt=0.5, 
                      bandwidth=300,
                      hatmatrix=TRUE, 
                      se.fit=TRUE)

我创建了以下代码以与 clusterR 一起使用:

    ncores <- detectCores()/2 # detectCores()-1 - number of cores to use if parallel processing
    gwr.formula <- temperature ~ treecanopy + tpi + impervious + treecanopy + ndvi + percent_patches + distance_patches + baylands + buildings

    beginCluster(ncores)
    gwr.model.cluster <- clusterR(x=rasterFromXYZ(df.notmissing[-12]), gwr, arg=list(formula= gwr.formula, data=as.data.frame(x,xy=TRUE), coords= x[1:2], adapt=0.5, bandwidth=300, hatmatrix=TRUE, se.fit=TRUE))
    endCluster()

我在使用 clusterR 时遇到的错误:

    [1] "attempt to set 'colnames' on an object with less than two dimensions"
    attr(,"class")
    [1] "snow-try-error" "try-error"     
    Error in clusterR(x = rasterFromXYZ(df.notmissing[-12]), gwr, arg = list(formula =         gwr.formula,  : 
      cluster error
4

0 回答 0