[英]R - spatstat: Calculate density for a new point
Is it possible to use spatstat
to estimate the intensity function for a give ppp
object and calculate its value considering a new point?是否可以使用
spatstat
来估计给定ppp
object 的强度 function 并考虑新点计算其值? For example, can I evaluate D
at new_point
:例如,我可以在
new_point
评估D
吗:
# packages
library(spatstat)
# define a random point within Window(swedishpines)
new_point <- ppp(x = 45, y = 45, window = Window(swedishpines))
# estimate density
(D <- density(swedishpines))
#> real-valued pixel image
#> 128 x 128 pixel array (ny, nx)
#> enclosing rectangle: [0, 96] x [0, 100] units (one unit = 0.1 metres)
Created on 2021-03-30 by the reprex package (v1.0.0)由代表 package (v1.0.0) 于 2021 年 3 月 30 日创建
I was thinking that maybe I can superimpose()
the two ppp
objects (ie swedishpines
and new_point
) and then run density
setting at = "points"
and weights = c(rep(1, points(swedishpines)), 0)
but I'm not sure if that's the suggested approach (and I'm not sure if the appended point is ignored during the estimation process).我在想也许我可以
superimpose()
两个ppp
对象(即swedishpines
和new_point
),然后at = "points"
和weights = c(rep(1, points(swedishpines)), 0)
处运行density
设置,但我'我不确定这是否是建议的方法(我不确定在估计过程中是否忽略了附加点)。
I know that it may sound like a trivial question, but I read some docs and didn't find an answer or a solution.我知道这听起来像是一个微不足道的问题,但我阅读了一些文档并没有找到答案或解决方案。
There are two ways to do this.有两种方法可以做到这一点。
The first is simply to take the pixel image of intensity, and extract the pixel values at the desired locations using [
:第一种是简单地获取强度的像素图像,并使用
[
提取所需位置的像素值:
D <- density(swedishpines)
v <- D[new_points]
See the help for density.ppp
and [.im
.请参阅
density.ppp
和[.im
的帮助。
The other way is to use densityfun
:另一种方法是使用
densityfun
:
f <- densityfun(swedishpines)
v <- f(new_points)
See the help for densityfun.ppp
请参阅
densityfun.ppp
的帮助
The first route is more efficient and the second way is more accurate.第一种方式效率更高,第二种方式更准确。
Technical issue : if some of the new_points
could lie outside the window of swedishpines
then the value at these points is (mathematically) undefined.技术问题:如果一些新点可能位于瑞典
swedishpines
的new_points
之外,那么这些点的值(数学上)是未定义的。 Both of the methods described above will simply ignore such points, and the resulting vector v
will be shorter than the number of new points.上述两种方法都将简单地忽略这些点,结果向量
v
将比新点的数量短。 If you need to handle this continengcy, the easiest way is to use D[new_points, drop=FALSE]
which returns NA
values for such locations.如果您需要处理这种偶然性,最简单的方法是使用
D[new_points, drop=FALSE]
它返回此类位置的NA
值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.