简体   繁体   English

spatstat的K,F和G功能不均匀的异常行为

[英]Unexpected behavior in spatstat inhomogeneous K-, F- and G-functions

I have a point pattern with about 84,000 points. 我有大约84,000点的点模式。 Quadrat tests suggested inhomogeneous intensity to I tried different Kernel bandwidths and got very odd behavior in the inhomogeneous implementations of the K-, F- and G-functions. Quadrat测试表明我尝试了不同的内核带宽时强度不均匀,并且在K函数,F函数和G函数的不均匀实现中得到了非常奇怪的行为。 Here is an example of the inhomogeneous F-function plot . 这是非均匀F函数图的示例。 Clearly, the estimated F-function does not reach 1 within the distance range while the Poisson process just flatlines. 显然,在距离范围内,估计的F函数不会达到1,而泊松过程只是趋于平坦。 The F-function should also be increasing so the dips are odd. F函数也应该增加,因此下垂是奇数。 When manually specifying a longer range of r in the Finhom() function, the function still does not evaluate beyond the suggested range of 2000. 当在Finhom()函数中手动指定Finhom()范围的r时,该函数的求值范围仍然不超过建议的2000。

Unfortunately, I cannot share my data. 不幸的是,我无法共享我的数据。 However, I managed to reproduce some of the errors with an admittedly very simple example of a point pattern on the unit square: 但是,我设法通过一个非常简单的单位正方形上的点图案示例重现了一些错误:

library(spatstat) # version 1.57-1
# define point pattern
ex <- as.ppp(data.frame(x = c(.9, .25, .29, .7, .72, .8, .72, .85), 
                        y = c(.1, .25, .29, .5, .5, .1, .45, .08)), 
                        W = owin(c(0,1), c(0,1)))

plot(ex) 
# testing inhomogeneity
quadrat.test(ex, 3, 3, method = "M", nsim = 500) # p around 0.05
# set bandwidth
diggle <- bw.diggle(ex)
# suggested bandwidth of 0.028

# estimate inhomogeneous F-function
Fi <- Finhom(ex, sigma = diggle)
plot(Fi, main ="Finhom for ex pattern")

The plot is attached here . 情节附在这里 Similar to my real data, the plot stops evaluating at r = 0.5 , flatlines and does not go up all the way to 1. Interestingly, when supplying the intensity directly via the lambda argument in the Finhom() function, the behavior changes: 与我的真实数据类似,该图在r = 0.5处停止求平,并且不会一直上升到1。有趣的是,当通过Finhom()函数中的lambda参数直接提供强度时,行为会发生变化:

lambda_ex <- density(ex, sigma = diggle, at = "points")
Fi_lambda <- Finhom(ex, lambda = lambda_ex)
plot(Fi_lambda, main ="Finhom w/ lambda directly")

Here, the functions behave as expected . 在这里,这些功能的行为符合预期

My questions are: 我的问题是:

  1. why is there a difference between directly supplied intensity vs. intensity internally estimated in the Finhom() function? 为什么直接提供的强度与Finhom()函数内部估计的强度之间存在差异?

  2. what could be the reason for the odd behavior of the F-function here? F函数在此处异常行为的原因可能是什么? A code issue or user error? 代码问题或用户错误? (Sidenote, the G- and K-functions also return odd behavior, to keep this question short-ish, I've focused on the F-function) (旁注,G函数和K函数也返回奇怪的行为,为了使这个问题简短,我将重点放在F函数上)

Thank you! 谢谢!

As pointed out by Adrian Baddeley in the other answer this is not a bug in Finhom per se. 正如阿德里安·巴德利(Adrian Baddeley)在其他答案中指出的那样,这本身并不是Finhom的错误。 You would expect that 您会期望

Fi <- Finhom(ex, sigma = diggle)

should be equivalent to 应该等于

lambda_ex <- density(ex, sigma = diggle, at = "points")
Fi_lambda <- Finhom(ex, lambda = lambda_ex)

However, different values of the argument lmin are implied by these commands. 但是,这些命令隐含了参数lmin不同值。 In the first case lambda is estimated everywhere in the window and the minimum value used. 在第一种情况下,在窗口中的任何地方都估计了λ,并使用了最小值。 In the second case only the given values of lambda are used to find the minimum. 在第二种情况下,仅使用给定的lambda值来找到最小值。 That can of course be quite different. 那当然可以大不相同。 The importance of lmin is illustrated in the code below (note that discrepancy between data and inhomogeneous Poisson is of the same type in all cases). 在下面的代码中说明了lmin的重要性(请注意,在所有情况下,数据与不均匀泊松之间的差异都是同一类型)。

The other part about the estimate stopping at r=0.5 is not surprising since border correction is used and the window is the unit square. 估计的另一部分停在r = 0.5并不奇怪,因为使用了边界校正,并且窗口是单位平方。 When r=0.5 the entire window is "shaved off", so there is no data left. 当r = 0.5时,整个窗口被“刮掉”,因此没有剩余数据。

library(spatstat)
#> spatstat 1.56-1.031       (nickname: 'Psycho chicken') 
X <- swedishpines
lam <- density(X, at = "points", sigma = 10)
lam_min <- min(lam)
plot(Finhom(X, lmin = lam_min), legend = FALSE, col = 1, main = "Finhom for different values of lmin")
s <- 2^(1:3)
for(i in seq_along(s)){
  plot(Finhom(X, lmin = lam_min/s[i]), col = i+1, add = TRUE)
}
s <- c(1,s)
legend("topleft", legend = paste0("min(lam)/", s), lty = 1, col = 1:length(s))

Created on 2018-11-24 by the reprex package (v0.2.1) reprex软件包 (v0.2.1)创建于2018-11-24

The "inhomogeneous" functions Kinhom , Ginhom , Finhom involve making adjustments for the spatially varying intensity of the point process. “不均匀”功能KinhomGinhomFinhom涉及对点过程的空间变化强度进行调整。 They only work if (a) the intensity has been accurately estimated, and (b) the point process satisfies certain technical assumptions which justify the adjustment calculation (see the references in the help files, or the relevant section of the spatstat book). 它们仅在以下情况下起作用:(a)已准确估算强度,并且(b)积分过程满足某些技术假设,这些合理的假设证明调整计算是正确的(请参阅帮助文件中的参考,或spatstat书的相关部分)。

The plot of density(ex, sigma=bw.diggle) shows very high peaks and very low troughs in the estimated intensity, suggesting that the data are under-smoothed, so that (a) is not satisfied. density(ex, sigma=bw.diggle)在估计强度中显示出非常高的峰和非常低的波谷,这表明数据不够平滑,因此无法满足(a)。 The results obtained with bw.scott or bw.CvL are much better behaved. bw.scottbw.CvL获得的结果表现得更好。 (Remember that bw.diggle is designed for clustered patterns.) For example, I get a reasonably nice plot with (请记住, bw.diggle是为集群模式设计的。)例如,我得到了一个相当不错的图

plot(Finhom(ex, sigma=bw.CvL))

Yes, it does seem a bit disconcerting that the results are different when 'lambda' is given as a pixel image and as a numeric vector. 是的,当将“ lambda”作为像素图像和数字矢量给出时,结果确实有所不同似乎有些令人不安。 This occurs, as Ege explains, because of the different rules for calculating the default value of the important argument lmin . 正如Ege所解释的,这是由于计算重要参数lmin的默认值的规则不同而发生的。 It's not really a bug -- the original authors of the code for Ginhom and Finhom designed it this way; 这并不是真正的错误GinhomFinhom的原始代码作者是用这种方式设计的; I will consult them for advice about whether we should change it. 我将咨询他们有关是否应该更改它的建议。 In the meantime, you can make the two calculations agree if you specify the value of lmin . 同时,如果指定lmin的值,则可以使两个计算一致。

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

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