如何在R中的一个图中绘制两个不同的分布?

发布于 2025-02-01 04:07:06 字数 266 浏览 4 评论 0原文

我想在一个图中绘制两个经验分布,以解释我的论文中的Kolmogorov-Smirnov测试。
一个具有样本步骤和一个连续分布的ECDF。
因此样本可能是:
x = c(12.4,11.8,12.9,12.6,13,12.5,12,12,12,13.2,12.8)
可以测试N〜(12,1)。 结果应该看起来像这样“

提前致谢 :)

I want to plot two empirical distributions in one Graph to explain the kolmogorov-smirnov Test in my paper.
One ecdf with steps from a sample and one continuous distribution.
So the sample could be:
x = c(12.4,11.8,12.9,12.6,13,12.5,12,11.5,13.2,12.8)
which could be tested for N~(12,1).
The result should look something like this plot.

Thanks in advance :)

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

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

发布评论

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

评论(2

也许您想要这样的东西:

library(stats)

x1 = c(12.4,11.8,12.9,12.6,13,12.5,12,11.5,13.2,12.8)
x2 = rnorm(12, 12, 1)

plot(ecdf(x1),pch = 1, xlim=c(10,15), main=NULL)
par(new=TRUE)        
plot(ecdf(x2),pch = 2, xlim=c(10,15), main=NULL)

输出:

”在此处输入图像描述”

Maybe you want something like this:

library(stats)

x1 = c(12.4,11.8,12.9,12.6,13,12.5,12,11.5,13.2,12.8)
x2 = rnorm(12, 12, 1)

plot(ecdf(x1),pch = 1, xlim=c(10,15), main=NULL)
par(new=TRUE)        
plot(ecdf(x2),pch = 2, xlim=c(10,15), main=NULL)

Output:

enter image description here

追风人 2025-02-08 04:07:06

另一种极简主义的方式:

my_observations = c(12.4,11.8,12.9,12.6,13,12.5,12,11.5,13.2,12.8)
my_ecdf <- ecdf(my_observations)

curve(my_ecdf(x),
      from = 10, to = 14,
      frame = FALSE ## don't plot border
      )

curve(pnorm(x, mean = 12),
      from = 10, to = 14,
      add = TRUE ## add to existing plot
      )

another minimalist way:

my_observations = c(12.4,11.8,12.9,12.6,13,12.5,12,11.5,13.2,12.8)
my_ecdf <- ecdf(my_observations)

curve(my_ecdf(x),
      from = 10, to = 14,
      frame = FALSE ## don't plot border
      )

curve(pnorm(x, mean = 12),
      from = 10, to = 14,
      add = TRUE ## add to existing plot
      )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文