假设我有一个数组A:
array([ 0.0019879 , -0.00172861, -0.00527226, 0.00639585, -0.00242005,
-0.00717373, 0.00371651, 0.00164218, 0.00034572, -0.00864304,
-0.00639585, 0.006828 , 0.00354365, 0.00043215, -0.00440795,
0.00544512, 0.00319793, 0.00164218, 0.00025929, -0.00155575,
0.00129646, 0.00259291, -0.0039758 , 0.00328436, 0.00207433,
0.0011236 , 0.00440795, 0.00164218, -0.00319793, 0.00233362,
0.00025929, 0.00017286, 0.0008643 , 0.00363008])
如果我跑:
^{pr2}$据我所知:
array([ 34.21952021, 34.21952021, 34.21952021, 34.21952021,
34.21952021, 188.20736116, 102.65856063, 68.43904042,
51.32928032])
手册上说:
"If True, the result is the value of the probability density function at the bin, normalized such that the integral over the range is 1. Note that the sum of the histogram values will not be equal to 1 unless bins of unity width are chosen; it is not a probability mass function."
我认为我对直方图和密度函数有很好的理解,但我真的不明白这些值代表什么,也不知道它们是如何计算的。在
我需要用R重新生成这些值,因为我要在两种语言之间移植一些代码。在
在R中,可以使用
hist()
函数来绘制直方图。另外,hist
是一个生成列表的S3
函数。在这是R用向量
^{pr2}$A
生成的默认直方图。在这是一个柱状图,它是密度曲线的附加层。在
让我们将列表
hist(A)
存储到p
。在我们现在可以看到列表
p
的内容。在density
表示理论密度函数值。这可以超过1,但密度曲线下的面积应等于1。每个条的宽度很容易由柱状图中条的断点(breaks
)之间的差异来确定。因此,如果我们将直方图的每个条的宽度乘以p$density
,并将结果相加,则得到的和应该是1。在相关问题 更多 >
编程相关推荐