我不明白如何解决这个问题。G
是一组值,我知道其范围是[0, 1e+12]
.
> G = c(500,10000, 5001, 103, 10, 10000)
> H = density(G)
> sum(diff(H$x)*H$y) # Area under the curve should be 1
[1] 0.999989
但是,为了能够比较两个数据集,我想提供from
和to
到density
函数,以便比较这些分布是有意义的。因此,我这样做了:
> H = density(G, from=0, to=1e+12)
> sum(diff(H$x)*H$y)
[1] 2576.354
Warning message:
In diff(H$x) * H$y :
longer object length is not a multiple of shorter object length
当我打印出估计的密度时,原因就很明显了:
[1] 1.315415e-04 1.102126e-07 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 9.471181e-26
[8] 1.565915e-22 2.563577e-26 4.272754e-23 0.000000e+00 0.000000e+00 8.951887e-26 1.516549e-22
[15] 3.870985e-25 6.612221e-22 0.000000e+00 0.000000e+00 1.275922e-25 2.216194e-22 0.000000e+00
[22] 0.000000e+00 5.567175e-26 9.835567e-23 0.000000e+00 0.000000e+00 1.866999e-25 3.355962e-22
[29] 1.544394e-25 2.800493e-22 6.026824e-26 1.102559e-22 0.000000e+00 0.000000e+00 0.000000e+00
....
....
[484] 2.430850e-22 1.346442e-25 0.000000e+00 0.000000e+00 1.135491e-22 6.399622e-26 0.000000e+00
[491] 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
[498] 8.914726e-23 5.240562e-26 2.189813e-22 1.297914e-25 4.773404e-22 2.852380e-25 3.289275e-22
[505] 1.981486e-25 1.382136e-23 8.393153e-27 8.090789e-24 4.952458e-27 3.042214e-24 1.876931e-27
[512] 1.809917e-22
虽然 R 正确估计极端点的密度为 0,但有些非零。这是我面临的浮点错误还是我做错了什么?有什么建议么?