什么是核密度估计器?本质上,它在数据的每个点(正态密度的中心是该点)上拟合一条小正态密度曲线,然后将所有小正态密度加到核密度估计器中。
For the sake of illustration I will add an image of a 1 dimensional kernel density estimator from one of your links http://www.mvstat.net/tduong/research/seminars/seminar-2001-05/. ![enter image description here](https://i.stack.imgur.com/uLmwB.png)
二维核密度怎么样?
# library(MASS)
b <- log10(rgamma(1000, 6, 3))
a <- log10((rweibull(1000, 8, 2)))
# a and b contain 1000 values each.
density <- kde2d(a,b,n=100)
该函数创建一个网格min(a)
to max(a)
和来自min(b)
to max(b)
。而不是在每个值上拟合一个微小的一维正态密度a
or b
, kde2d
现在在网格中的每个点上都拟合一个微小的二维法线密度。就像一维情况下的核密度一样,它将所有密度值相加。
颜色代表什么意思?正如 @cel 在评论中指出的:估计概率取决于两个变量,所以我们现在有三个轴(a
, b
and estimated probability
)。可视化 3 轴的一种方法是使用等概率等值线。这听起来很奇特,但它与我们从天气预报中获知的高/低压图像基本相同。
您正在使用
filled.contour(density,
color.palette = colorRampPalette(c('white', 'blue', 'yellow', 'red', 'darkred')))))
So from low to high, the plot will be coloured white
, blue
, yellow
, red
and eventually darkred
for the highest values of estimated probability. This results in the following plot: ![](https://i.stack.imgur.com/JJll0.png)