[英]Elongated kde2d from MASS R library
When I use kde2d function for two points on square (in my case 1000 x 1000 px) from MASS package I get elongated gaussians when x difference of points is very different from y difference of points: 当我使用kde2d函数从MASS包中在正方形上的两个点(在我的情况下为1000 x 1000 px)中使用两个点时,当x的点差与y的点差非常不同时,我得到的是细长的高斯:
library(MASS)
library(tibble)
par(mfrow = c(2, 1))
points_1 <- tribble(
~x, ~y,
100, 800,
150, 500
) # x2-x1 = 50; y2-y1 = -300
kde_1 <- kde2d(points_1$x, points_1$y, n = 50, lims = c(1, 1000, 1, 1000))
image(kde_1)
points_2 <- tribble(
~x, ~y,
100, 800,
650, 700
) # x2-x1 = 550; y2-y1 = -100
kde_2 <- kde2d(points_2$x, points_2$y, n = 50, lims = c(1, 1000, 1, 1000))
image(kde_2)
How to obtain round kde2d for two pints? 如何获得两个品脱的圆形kde2d? I need something like this:
我需要这样的东西:
As the help page for kde2d
says, it will use the function bandwidth.nrd
to compute the bandwidth in each coordinate. 至于帮助页面
kde2d
说,它将使用功能bandwidth.nrd
来计算每个坐标的带宽。 You want those to be the same, so specify the h
value as a scalar: 您希望它们相同,因此将
h
值指定为标量:
h <- mean(bandwidth.nrd(points_1$x), bandwidth.nrd(points_1$y))
kde_3 <- kde2d(points_1$x, points_1$y, h = h, n = 50, lims = c(1, 1000, 1, 1000))
image(kde_3)
which gives me 这给了我
You might want a larger value for h
, eg using max
instead of mean
: 您可能想要更大的
h
值,例如使用max
而不是mean
:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.