简体   繁体   English

Foxall Jfox 的信封在 R spatstat 中给出“Hest 中的错误”

[英]envelope for Foxall Jfox giving "error in Hest" in R spatstat

I want to explore the distance of points in a point pattern to the nearest polygon in a polygon shapefile.我想探索点模式中的点到多边形 shapefile 中最近多边形的距离。

Using the R package spatstat , my approach is to calculate the envelope for the function Jfox that consider the distance of my points to the polygons.使用 R 包spatstat ,我的方法是计算考虑点到多边形距离的函数Jfoxenvelope

My full dataset include point patterns from multiple sites, and I have been successfully using this approach with several sites.我的完整数据集包括来自多个站点的点模式,并且我已经成功地将这种方法用于多个站点。

However, when running the envelope on a particular site I get this error:但是,在特定站点上运行信封时,我收到此错误:

Generating 99 simulations of CSR with fixed number of points  ...
Error : in Hest(X,r) the successive r values must be finely spaced: given spacing = 0.0043766; required spacing <=  0.00393
In addition: Warning messages:
1: In resolve.foxall.window(X, Y, W) :
  Trimming the window of X to be a subset of the Frame of Y
2: In resolve.foxall.window(X, Y, W) :
  Trimming the window of X to be a subset of the Frame of Y
[retrying]
Error : in Hest(X,r) the successive r values must be finely spaced: given spacing = 0.0043766; required spacing <=  0.00393
In addition: Warning message:
In resolve.foxall.window(X, Y, W) :
  Trimming the window of X to be a subset of the Frame of Y
[retrying]
... and so on.

I cannot figure out what is causing the issue.我无法弄清楚是什么导致了这个问题。

Reproducible example:可重现的例子:

Datafiles can be found here:数据文件可以在这里找到:

https://www.dropbox.com/sh/fzucl5f6u4s2igx/AAAzgf2Fn-L9cfwzSCwj1RbPa?dl=0 https://www.dropbox.com/sh/fzucl5f6u4s2igx/AAAzgf2Fn-L9cfwzSCwj1RbPa?dl=0

please adapt the code for importing the data according to where you store the files.请根据您存储文件的位置调整用于导入数据的代码。


library(tidyverse)
{ # load these two together because spatstat rely on them but I don't know exactely for what.
library(sp)
library(maptools)  # needed for method such as as.ppp
}
library(spatstat)
library(sf)
library(xlsx)

# load transect polygon giving the Window of ppp, and make it a owin object
tr_poly_win<-st_read('transect.shp') %>%
             select(geometry) %>% as(., 'Spatial') %>% as(.,'SpatialPolygons') %>%
             as.owin(tr_poly_sp)

# load points and make them a ppp with correct window

options(digits=15) # this to allow enough decimals
points<-read.table('points.txt', head=T,sep='\t',dec='.') %>%
        mutate(geometry=as.character(geometry)) %>%
        mutate(lon=as.numeric(sapply(strsplit(geometry, '[(,)]'), "[[", 2)), 
               lat=as.numeric(sapply(strsplit(geometry, '[(,)]'), "[[", 3))) %>%
        st_as_sf(coords=c('lon','lat'),crs= 32619) %>%
        as(.,'Spatial') %>%
        as.ppp(.)

Window(points)<-tr_poly_win

# load polygons
win<-st_read('polygons.shp') %>% as(.,'Spatial') %>% as(.,'owin')

# create an hyperframe

hyp<-hyperframe(points=points,win=win)

# visualize data:
# points as open circles; points' window as black contour; polygons in red; 
# Frame of the polygons as red rectangle; Frame of points as green rectangle
plot(hyp, quote({plot(points,which.marks='pos',type='n')
                 plot(win,col=2,add=TRUE)
                 plot(points,which.marks='pos',type='p', add=T)
                 plot(Frame(win),border=2, add=T) 
                 plot(Frame(points),border=3, add=T)}) )

在此处输入图片说明

points as open circles;点为空心圆; points' window as black contour;点的窗口为黑色轮廓; polygons in red;红色多边形; Frame of the polygons as red rectangle;多边形的框架为红色矩形; Frame of points as green rectangle点的框架为绿色矩形

# computing the Jfox function works
with(hyp,Jfox(points,win))

# try to compute the envelope for the Jfox and you'll get the error
with(hyp,envelope(Y=points,  fun=Jfox, funargs=list(Y=win) , nsim=99, fix.n=T))

Is there any underlying reason why I get this error or it is a bug (eg see the links in the PS )?是否有任何潜在原因导致我收到此错误或它是一个错误(例如,请参阅PS 中的链接)?

My session info is as follow:我的会话信息如下:

R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252    LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C                   LC_TIME=Italian_Italy.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] xlsx_0.6.1          sf_0.7-4            spatstat_1.63-0     rpart_4.1-15        nlme_3.1-140        spatstat.data_1.4-3 maptools_0.9-5      sp_1.3-1            forcats_0.4.0      
[10] stringr_1.4.0       dplyr_0.8.3         purrr_0.3.3         readr_1.3.1         tidyr_1.0.0         tibble_2.1.3        ggplot2_3.2.1       tidyverse_1.2.1    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1            lubridate_1.7.4       lattice_0.20-38       deldir_0.1-16         xlsxjars_0.6.1        class_7.3-15          assertthat_0.2.1      zeallot_0.1.0        
 [9] R6_2.4.0              cellranger_1.1.0      backports_1.1.4       e1071_1.7-1           httr_1.4.1            tensor_1.5            pillar_1.4.0          rlang_0.4.1          
[17] lazyeval_0.2.2        readxl_1.3.1          rstudioapi_0.10       Matrix_1.2-18         goftest_1.2-2         splines_3.6.2         rgdal_1.4-3           foreign_0.8-72       
[25] polyclip_1.10-0       munsell_0.5.0         broom_0.5.2           compiler_3.6.2        modelr_0.1.5          pkgconfig_2.0.2       mgcv_1.8-31           tidyselect_0.2.5     
[33] crayon_1.3.4          withr_2.1.2           grid_3.6.2            jsonlite_1.6          gtable_0.3.0          lifecycle_0.1.0       DBI_1.0.0             magrittr_1.5         
[41] units_0.6-3           scales_1.0.0          KernSmooth_2.23-16    cli_1.1.0             stringi_1.4.3         xml2_1.2.2            spatstat.utils_1.17-0 generics_0.0.2       
[49] vctrs_0.2.0           tools_3.6.2           glue_1.3.1            hms_0.5.2             abind_1.4-5           colorspace_1.4-1      classInt_0.3-3        rvest_0.3.5          
[57] rJava_0.9-11          haven_2.2.0          

Ps: My search for an explanation lead to similar problems that resulted from a bug in previous version of the spatstat code. Ps:我对解释的搜索导致了类似的问题,这些问题是由先前版本的 spatstat 代码中的错误引起的。 here the links:这里的链接:

http://r-sig-geo.2731867.n2.nabble.com/Error-in-random-labelling-using-the-J-function-td7593210.html http://r-sig-geo.2731867.n2.nabble.com/Error-in-random-labelling-using-the-J-function-td7593210.html

http://r-sig-geo.2731867.n2.nabble.com/Complete-spatial-randomness-testing-td7590425.html http://r-sig-geo.2731867.n2.nabble.com/Complete-spatial-randomness-testing-td7590425.html

As you can see, though, my statspat and my R versions should be current.但是,正如您所看到的,我的 statspat 和 R 版本应该是最新的。

This is a bug.这是一个错误。

It is now fixed in the development version of spatstat (version 1.63-0.020 and later) available from the repository on GitHub .它现在已在 GitHub 上存储库中提供的spatstat开发版本(版本1.63-0.020及更高版本)中得到1.63-0.020

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM