1

当使用该gstat包使用该krige函数进行空间插值时,我只得到样本位置的结果。这不是我所期望的,已经阅读了它如何工作的清晰解释,这里有一个可重复的例子:https ://keen-swartz-3146c4.netlify.app/interpolation.html

有什么想法我哪里出错了吗?我尝试了各种方法但无济于事,因此在这里提出了一个可重复的示例。

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
library(gstat)
library(stars)
#> Loading required package: abind
u = "https://github.com/saferactive/saferactive/releases/download/0.1.1/rnet_lnd_1pcnt.Rds"
rnet_lnd = readRDS(url(u))
rnet_lnd
#> Simple feature collection with 698 features and 9 fields
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: 506201.1 ymin: 157489.3 xmax: 554024 ymax: 197327
#> projected CRS:  OSGB 1936 / British National Grid
#> First 10 features:
#>       local_id bicycle govtarget_slc govnearmkt_slc gendereq_slc dutch_slc
#> 36469    36469       2             8              4            4        38
#> 72154    72154     296           464            509          415       992
#> 13692    13692      64            75             85           99       170
#> 51194    51194      10            10             15           20        38
#> 45023    45023       5            20             14           10        78
#> 14664    14664     140           166            189          198       270
#> 62204    62204      31            41             48           49       118
#> 48161    48161       7            18             16           14        83
#> 37306    37306       2            17             12            3        88
#> 8329      8329      10            34             32           19       144
#>       ebike_slc    length km_cycled_yr                  geometry
#> 36469        40  75.14911     76.05090 POINT (540554.4 184261.5)
#> 72154      1191  21.59051   3233.73959 POINT (532707.7 182641.9)
#> 13692       224  50.93146   1649.36427 POINT (526445.2 177201.8)
#> 51194        50 236.08443   1194.58721 POINT (533507.4 186557.7)
#> 45023        91 211.86509    536.01868 POINT (541408.3 180908.9)
#> 14664       342  14.72725   1043.27843 POINT (532361.8 186576.6)
#> 62204       193 550.77091   8639.39256 POINT (536944.7 176095.4)
#> 48161       104 194.18121    687.78986   POINT (534208 190667.8)
#> 37306        98  52.39301     53.02172 POINT (534251.2 195203.9)
#> 8329        249  81.10461    410.38932 POINT (540147.3 192165.4)
grd = st_bbox(rnet_lnd) %>%
  st_as_stars(dx = 500, dy = 500) %>%
  st_set_crs(27700) %>%
  st_crop(rnet_lnd) 
grd
#> stars object with 2 dimensions and 1 attribute
#> attribute(s):
#>     values     
#>  Min.   :0     
#>  1st Qu.:0     
#>  Median :0     
#>  Mean   :0     
#>  3rd Qu.:0     
#>  Max.   :0     
#>  NA's   :7051  
#> dimension(s):
#>   from to offset delta                       refsys point values    
#> x    1 96 506201   500 OSGB 1936 / British Natio...    NA   NULL [x]
#> y    1 80 197327  -500 OSGB 1936 / British Natio...    NA   NULL [y]
v = variogram(bicycle~1, rnet_lnd, cutoff = 10000)
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
#> = prefer_proj): Discarded datum Unknown based on Airy 1830 ellipsoid in CRS
#> definition
#> Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO", prefer_proj =
#> prefer_proj): Discarded datum OSGB 1936 in CRS definition
plot(v)

vm = fit.variogram(v, vgm(psill = "Sph", model = "Exp", range = 10000, nugget = 1))
plot(vm, cutoff = 10000)

rnet_krige = gstat::krige(bicycle~1, rnet_lnd, grd, vm, nmax = 100)
#> [using ordinary kriging]
plot(rnet_lnd$geometry)
plot(rnet_krige, add = TRUE)

reprex 包(v0.3.0)于 2020 年 10 月 26 日创建

devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       Ubuntu 18.04.5 LTS          
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language en_GB:en                    
#>  collate  en_GB.UTF-8                 
#>  ctype    en_GB.UTF-8                 
#>  tz       Europe/London               
#>  date     2020-10-26                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date       lib source                        
#>  abind       * 1.4-5      2016-07-21 [1] CRAN (R 4.0.2)                
#>  assertthat    0.2.1      2019-03-21 [3] CRAN (R 4.0.0)                
#>  backports     1.1.10     2020-09-15 [1] CRAN (R 4.0.2)                
#>  callr         3.5.1      2020-10-13 [1] CRAN (R 4.0.3)                
#>  class         7.3-17     2020-04-26 [4] CRAN (R 4.0.0)                
#>  classInt      0.4-3      2020-04-07 [1] CRAN (R 4.0.2)                
#>  cli           2.1.0      2020-10-12 [3] CRAN (R 4.0.3)                
#>  crayon        1.3.4      2017-09-16 [3] CRAN (R 4.0.0)                
#>  curl          4.3        2019-12-02 [3] CRAN (R 4.0.0)                
#>  DBI           1.1.0      2019-12-15 [2] CRAN (R 4.0.2)                
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 4.0.2)                
#>  devtools      2.3.2      2020-09-18 [3] CRAN (R 4.0.2)                
#>  digest        0.6.27     2020-10-24 [1] CRAN (R 4.0.3)                
#>  dplyr         1.0.2      2020-08-18 [3] CRAN (R 4.0.2)                
#>  e1071         1.7-4      2020-10-14 [1] CRAN (R 4.0.3)                
#>  ellipsis      0.3.1      2020-05-15 [3] CRAN (R 4.0.0)                
#>  evaluate      0.14       2019-05-28 [3] CRAN (R 4.0.0)                
#>  fansi         0.4.1      2020-01-08 [3] CRAN (R 4.0.0)                
#>  FNN           1.1.3      2019-02-15 [1] CRAN (R 4.0.3)                
#>  fs            1.5.0      2020-07-31 [3] CRAN (R 4.0.2)                
#>  generics      0.0.2      2018-11-29 [3] CRAN (R 4.0.0)                
#>  glue          1.4.2      2020-08-27 [3] CRAN (R 4.0.2)                
#>  gstat       * 2.0-6      2020-05-18 [1] CRAN (R 4.0.3)                
#>  highr         0.8        2019-03-20 [3] CRAN (R 4.0.0)                
#>  htmltools     0.5.0      2020-06-16 [3] CRAN (R 4.0.1)                
#>  httr          1.4.2      2020-07-20 [1] CRAN (R 4.0.2)                
#>  intervals     0.15.2     2020-04-04 [1] CRAN (R 4.0.3)                
#>  KernSmooth    2.23-17    2020-04-26 [4] CRAN (R 4.0.0)                
#>  knitr         1.30       2020-09-22 [3] CRAN (R 4.0.2)                
#>  lattice       0.20-41    2020-04-02 [2] CRAN (R 4.0.2)                
#>  lifecycle     0.2.0      2020-03-06 [3] CRAN (R 4.0.0)                
#>  lwgeom        0.2-5      2020-06-12 [1] CRAN (R 4.0.2)                
#>  magrittr      1.5        2014-11-22 [3] CRAN (R 4.0.0)                
#>  memoise       1.1.0      2017-04-21 [3] CRAN (R 4.0.0)                
#>  mime          0.9        2020-02-04 [3] CRAN (R 4.0.0)                
#>  pillar        1.4.6      2020-07-10 [3] CRAN (R 4.0.2)                
#>  pkgbuild      1.1.0      2020-07-13 [3] CRAN (R 4.0.2)                
#>  pkgconfig     2.0.3      2019-09-22 [3] CRAN (R 4.0.0)                
#>  pkgload       1.1.0      2020-05-29 [3] CRAN (R 4.0.0)                
#>  prettyunits   1.1.1      2020-01-24 [3] CRAN (R 4.0.0)                
#>  processx      3.4.4      2020-09-03 [3] CRAN (R 4.0.2)                
#>  ps            1.4.0      2020-10-07 [3] CRAN (R 4.0.2)                
#>  purrr         0.3.4      2020-04-17 [3] CRAN (R 4.0.0)                
#>  R6            2.4.1      2019-11-12 [3] CRAN (R 4.0.0)                
#>  Rcpp          1.0.5      2020-07-06 [3] CRAN (R 4.0.2)                
#>  remotes       2.2.0      2020-07-21 [1] CRAN (R 4.0.2)                
#>  rgdal         1.5-18     2020-10-13 [1] CRAN (R 4.0.3)                
#>  rlang         0.4.8      2020-10-08 [3] CRAN (R 4.0.2)                
#>  rmarkdown     2.5        2020-10-21 [1] CRAN (R 4.0.3)                
#>  rprojroot     1.3-2      2018-01-03 [3] CRAN (R 4.0.0)                
#>  sessioninfo   1.1.1      2018-11-05 [3] CRAN (R 4.0.0)                
#>  sf          * 0.9-6      2020-09-13 [1] CRAN (R 4.0.2)                
#>  sp            1.4-4      2020-10-07 [2] CRAN (R 4.0.2)                
#>  spacetime     1.2-3      2020-01-21 [1] CRAN (R 4.0.3)                
#>  stars       * 0.4-3      2020-07-08 [1] CRAN (R 4.0.2)                
#>  stringi       1.5.3      2020-09-09 [1] CRAN (R 4.0.2)                
#>  stringr       1.4.0      2019-02-10 [3] CRAN (R 4.0.0)                
#>  testthat      2.3.2      2020-03-02 [3] CRAN (R 4.0.0)                
#>  tibble        3.0.4      2020-10-12 [3] CRAN (R 4.0.3)                
#>  tidyselect    1.1.0      2020-05-11 [3] CRAN (R 4.0.0)                
#>  units         0.6-7      2020-06-13 [1] CRAN (R 4.0.2)                
#>  usethis       1.9.0.9000 2020-10-23 [1] Github (r-lib/usethis@297c9a2)
#>  vctrs         0.3.4      2020-08-29 [3] CRAN (R 4.0.2)                
#>  withr         2.3.0      2020-09-22 [3] CRAN (R 4.0.2)                
#>  xfun          0.18       2020-09-29 [1] CRAN (R 4.0.2)                
#>  xml2          1.3.2      2020-04-23 [3] CRAN (R 4.0.0)                
#>  xts           0.12.1     2020-09-09 [1] CRAN (R 4.0.3)                
#>  yaml          2.2.1      2020-02-01 [3] CRAN (R 4.0.0)                
#>  zoo           1.8-8      2020-05-02 [1] CRAN (R 4.0.2)                
#> 
#> [1] /home/robin/R/x86_64-pc-linux-gnu-library/4.0
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
4

1 回答 1

1

答:它确实已经提供了空间广泛的预测,如下所述:https ://github.com/Robinlovelace/geocompr/issues/585#issuecomment-716780818

于 2020-10-26T19:45:44.170 回答