Получение ошибки в ClusterR: ошибка кластера - PullRequest
1 голос
/ 02 октября 2019
    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

Я хочу запустить gwr с помощью библиотеки spgwr. GWR без clusterR выглядит следующим образом:

     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
...