在 R 中生成概率分布函数 (PDF) 的问题

发布于 2024-12-09 03:09:07 字数 381 浏览 0 评论 0原文

您好,我正在使用 R 来分析模拟输出的数据。我正在使用 hist 函数生成 pdf,我给出的确切命令是

hist(data_delay$delay,freq=F)

根据我的理解,图表 y 轴的值应小于 1,Y 轴上的所有计数应加起来为 1。但不幸的是,我没有得到Y 轴的随机范围,有时值为 1000。

我附上我的示例输入文件。在此,Y 轴值的范围为 0 到 100。

感谢您提供的所有帮助。

我的数据如下 http://www.mediafire.com/?twyoseg8bai0dr7

Hi I am using R to analyze data from output of my simulation. I am using hist function to generate pdf's the exact command i give is

hist(data_delay$delay,freq=F)

In my understanding the values the y axis of the chart should be less then 1, all the counts on Y-Axis should add up to 1. But unfortunately I am not getting random range at Y-Axis, sometimes values in 1000's.

I am attaching my sample input file. In this the Y-Axis values are in the range of 0 to 100.

Thank you for all the help you can provide.

My data is as follows
http://www.mediafire.com/?twyoseg8bai0dr7

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与君绝 2024-12-16 03:09:07

根据 hist 文档,当 freq=FALSE 时,“直方图的总面积为 1”。它并没有说每个条形的高度应该小于一。使用命令和数据创建的直方图的总面积确实为 1。

> data_delay <- read.csv("PATH_TO_DATA_FILE")
> h <- hist(data_delay$delay, plot=F)
> h
$breaks
 [1] 0.000 0.005 0.010 0.015 0.020 0.025 0.030 0.035 0.040 0.045 0.050 0.055
[13] 0.060 0.065 0.070

[SNIP]

$density
 [1] 112.47892074  13.36706015   3.91231029   5.98088814  10.35413153
 [6]  11.21978640  11.80438449   6.55424396  14.14277684   2.63069140
[11]   5.53119730   1.31534570   0.69702080   0.01124227

[SNIP]

断点的间距相等为 0.005,因此我们可以通过执行以下操作来查看直方图中的总面积。

> sum(h$density * 0.005)
[1] 1

According to the hist documentation, when freq=FALSE, "the histogram has a total area of one". It does not say that the height of every bar should be less than one. The histogram created with your command and data does have a total area of 1.

> data_delay <- read.csv("PATH_TO_DATA_FILE")
> h <- hist(data_delay$delay, plot=F)
> h
$breaks
 [1] 0.000 0.005 0.010 0.015 0.020 0.025 0.030 0.035 0.040 0.045 0.050 0.055
[13] 0.060 0.065 0.070

[SNIP]

$density
 [1] 112.47892074  13.36706015   3.91231029   5.98088814  10.35413153
 [6]  11.21978640  11.80438449   6.55424396  14.14277684   2.63069140
[11]   5.53119730   1.31534570   0.69702080   0.01124227

[SNIP]

The breaks are equally spaced 0.005 apart, so we can see the total area in the histogram by doing the following.

> sum(h$density * 0.005)
[1] 1
焚却相思 2024-12-16 03:09:07

您可能更喜欢 ?密度


foo<-密度(rnorm(1000));绘图(foo)

You might prefer ?density

as in
foo<-density(rnorm(1000)) ; plot(foo)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文