为什么在R函数kde2d H中除以4?

我正试图复制kde2d函数,该函数执行双变量内核密度估计,只是为了了解其实际工作原理,但我无法弄清楚bandwith是如何在代码中实现的。这是原始功能代码:

```
function (x,y,h,n = 25,lims = c(range(x),range(y))){ 
nx <- length(x)
if (length(y) != nx) 
    stop("data vectors must be the same length")
if (any(!is.finite(x)) || any(!is.finite(y))) 
    stop("missing or infinite values in the data are not allowed")
if (any(!is.finite(lims))) 
    stop("only finite values are allowed in 'lims'")
n <- rep(n,length.out = 2L)
gx <- seq.int(lims[1L],lims[2L],length.out = n[1L])
gy <- seq.int(lims[3L],lims[4L],length.out = n[2L])
h <- if (missing(h)) 
    c(bandwidth.nrd(x),bandwidth.nrd(y))
else rep(h,length.out = 2L)
if (any(h <= 0)) 
    stop("bandwidths must be strictly positive")
h <- h/4
ax <- outer(gx,x,"-")/h[1L]
ay <- outer(gy,"-")/h[2L]
z <- tcrossprod(matrix(dnorm(ax),nx),matrix(dnorm(ay),nx))/(nx * h[1L] * h[2L])
list(x = gx,y = gy,z = z)}
```

我不明白为什么通常的带宽除以4 ?以下是应从中估算双变量内核密度的方程式: https://i.stack.imgur.com/Npyw8.png

我真的很感谢能帮助您理解它。

hao0303hao 回答:为什么在R函数kde2d H中除以4?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2521956.html

大家都在问