我正在尝试使用
在绘图中放置 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")
我得到了
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。我认为您这样做没有任何问题。出于我自己的目的,我所做的唯一更改是使用值初始化绘图窗口,以便所有密度都在绘图窗口的范围内。
此外,关于之前的答案(我还不能发表评论),请注意 ylim
是 plot()
的参数,而不是 density()
--- 它没有告诉 density()
做任何事情。
关于r - 在 R 中叠加内核分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7327658/