r - 在 R 中叠加内核分布

标签 r plot kernel distribution

我正在尝试使用

在绘图中放置 3 个密度函数
plot(density(all_noise),xlim=c(-1,1),ylim=c(0,10))
lines(density(max_nearby),col="blue")
lines(density(max_repeats),col="red")

我得到了 enter image description here

y 轴上的密度值不应该 < 1 吗?有没有更好的叠加方法 内核分布?

str(density(all_noise))
List of 7
$ x        : num [1:512] -0.629 -0.626 -0.624 -0.622 -0.62 ...
$ y        : num [1:512] 1.41e-06 8.22e-06 3.16e-05 7.85e-05 1.24e-04 ...
$ bw       : num 0.003
$ n        : int 1924150
$ call     : language density.default(x = all_noise)
$ data.name: chr "all_noise"
$ has.na   : logi FALSE
- attr(*, "class")= chr "density"

str(density(max_nearby))
List of 7
$ x        : num [1:512] 0.154 0.156 0.158 0.16 0.162 ...
$ y        : num [1:512] 0.00111 0.00125 0.0014 0.00157 0.00175 ...
$ bw       : num 0.0543
$ n        : int 250
$ call     : language density.default(x = max_nearby)
$ data.name: chr "max_nearby"
$ has.na   : logi FALSE
- attr(*, "class")= chr "density"

str(density(max_repeats ))
List of 7
$ x        : num [1:512] 0.272 0.274 0.275 0.277 0.279 ...
$ y        : num [1:512] 0.00507 0.00607 0.00722 0.00854 0.01011 ...
$ bw       : num 0.0261
$ n        : int 34
$ call     : language density.default(x = max_repeats)
$ data.name: chr "max_repeats"
$ has.na   : logi FALSE
- attr(*, "class")= chr "density"

最佳答案

密度曲线下的面积为 1,但它们可以超过 1。我认为您这样做没有任何问题。出于我自己的目的,我所做的唯一更改是使用值初始化绘图窗口,以便所有密度都在绘图窗口的范围内。

此外,关于之前的答案(我还不能发表评论),请注意 ylimplot() 的参数,而不是 density() --- 它没有告诉 density() 做任何事情。

关于r - 在 R 中叠加内核分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7327658/

相关文章:

linux - Linux 驱动程序中已知的互斥方案

r - dplyr rowwise + replace_NA : replacing NAs in multiple columns with value from other column

r - 如何使用 gg密度 叠加总密度和组密度

用于文本 3D 散点图的 Java 库

MATLAB:动态热图

linux - 您如何诊断内核 oops?

python - 带注释的水平条形图

css - 如何在四开本演示文稿中更改代码块的高度和宽度

regex - 向量化模式匹配返回 R 中的模式

r - 用旁边其他地 block 的图例绘制多个地 block