【发布时间】:2022-02-08 10:57:23
【问题描述】:
我正在尝试使用内核密度平滑来绘制可能害虫从车辆交通中逃逸的强度。每条路线都被分解成直线,每条线都有一个整数属性,表示路段经过的次数。但是,当我将此属性用作核密度平滑中的权重时,似乎没有使用权重。
我在下面用两条相邻的直线创建了一个简化的代表。谁能向我解释我如何使 density.psp() 说明一个片段的属性是另一个片段的 2 倍?
非常感谢您的帮助,
乔什
# Load packages
library(spatstat)
# Create the data frame. Note that coordinates are projected to the
# North America Lambert Conformal Conic system. https://epsg.io/102009
my_lines <- data.frame(
fx = c(1252365.22479882, 1233600.0015391),
fy = c(510853.438463705, 626675.859171899),
tx = c(1233600.0015391, 1218256.03484937),
ty = c(626675.859171899, 721347.256108354),
attrib = c(100, 50)
)
# Creat the observation window
my_owin <- owin(
xrange = c(1200000, 1270000),
yrange = c(500000, 730000)
)
# Create the psp object with 'attrib' as the mark.
my_psp <- psp(
x0 = my_lines$fx, y0 = my_lines$fy,
x1 = my_lines$tx, y1 = my_lines$ty,
window = my_owin, marks = my_lines$attrib
)
# Create the KDS image with 'attrib' as the weights
kdi_image_weighted <-
density.psp(
my_psp,
kernel = "gaussian",
sigma = 4000,
weights = my_psp$attrib,
edge = FALSE
)
# Create the KDS image without weights
kdi_image_unweighted <-
density.psp(
my_psp,
kernel = "gaussian",
sigma = 4000,
edge = FALSE
)
# Plot the weighted and unweighted KDS images. Note that they are the same
# despite one being weighted.
plot(kdi_image_weighted)
plot(kdi_image_unweighted)
【问题讨论】:
-
嗨 Josh Persi,
kdi_image_weighted <- density.psp(...)代码中的weights = my_psp$num_trips似乎没有引用任何内容。也许,试试weights = my_psp$marks。干杯 -
嗨@lovalery,感谢您接听!在我重命名
num_trips列以使此表示更通用之后,我的代码应该阅读weights = my_psp$attrib。但是,切换weights = my_psp$marks可以工作并提供预期的输出!非常感谢!