0

我们如何估计对应于轮廓内点百分比的水平轮廓?

这篇文章描述了如何在 R 中向散点图添加等高线:
https ://stats.stackexchange.com/questions/31726/scatterplot-with-contour-heat-overlay

例如:

    x <- rnorm(1000, 0, 1.3)
    y <- rnorm(1000, 0, 1);
    dens <- kde2d(x, y, n=200); ## estimate the z counts
    plot(x, y);
    contour(dens, nlevels = 5, add=T)


因此,不是上面示例中绘制的 5 个级别,我希望对应于 99%、95%、50% 等点的级别位于等高线内。



谢谢...

4

1 回答 1

2

像这样的东西(HPDregionplot来自@benbolker 的片段)?:

library(MASS)
x <- rnorm(1000, 0, 1.3)
y <- rnorm(1000, 0, 1);
dens <- kde2d(x, y, n=200); ## estimate the z counts

prob <- c(.98, .95, .90, .8, .5, .1)
dx <- diff(dens$x[1:2])
dy <- diff(dens$y[1:2])
sz <- sort(dens$z)
c1 <- cumsum(sz) * dx * dy
levels <- sapply(prob, function(x) {
    approx(c1, sz, xout = 1 - x)$y
})

plot(x,y)
contour(dens, levels=levels, labels=prob, add=T)
于 2013-04-26T04:46:00.017 回答