在R中模拟泊松过程

问题描述 投票:0回答:1

我如何去模拟一个泊松过程,每单位时间内的到达率为lambda=0.5。模拟需要运行,直到有8个到达,从这一点,我想创建一个图,表示这一点。非常感谢。

r plot simulation exponential poisson
1个回答
2
投票

泊松过程的到达间时间是独立的,且呈指数分布,平均值为 1/lambda. 这里是一个参考.

因此,模拟泊松过程的前8个到达的简单方法是使用独立的指数随机变量的累积和(结果可能会有所不同,因为它们是随机的)。

X <- cumsum(rexp(8, rate = 0.5))
# [1] 1.640417 1.855639 1.988687 2.936651 6.192125 7.682924 8.159302 8.963526

至于如何绘制,要看你需要什么类型的图谱, 一个非常简单的选择,用x轴作为时间,y轴作为出现的次数,直到那个时间点。使用 ggplot2:

library(ggplot2)
ggplot(data.frame(t = X, count = seq_along(X)), aes(x = t, y = count)) +
  geom_step()

结果:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.