复合泊松过程

时间:2017-07-13 15:04:33

标签: r statistics poisson

我的任务是模拟定义为的复合泊松过程:

enter image description here

,其中

enter image description here

是泊松过程,Y_i是Gamma(形状,比例)分布。这是我的R代码:

ListB

计算X(10)的随机样本并比较均值和方差。

ListA

输出:

# parameter for Poisson distribution.
lambda = 1
# parameters for Gamma distribution.
shape = 7.5
scale = 1

comp.pois = function(t.max, lambda) {
  stopifnot(t.max >= 0 && t.max %% 1 == 0)
  # offset ns by 1 because first y is 0.
  # generate N(t), that is number of arrivals until time t.
  ns = cumsum(rpois(n = t.max, lambda = lambda)) + 1
  # generate gamma distributed random variables Y_i.
  ys = c(0, rgamma(n = max(ns), shape = shape, scale = scale))
  # generate all X(t) for t <= t.max.
  return(c(0, cumsum(x = ys[ns])))
}

这种差异是巨大的,但我无法发现我的错误。请帮忙。谢谢。

修改

我使用以下算法生成N(t)。我不知道为什么它会更好。我从 Rizzo,Maria L.统计计算中获取了它与R. CRC Press,2007。平均值很好,但方差更差。我尝试从Gamma分布中仅对整个模拟进行一次采样(虽然我很确定这并不能很好地反映问题)并且对于t = 10,平均值大约为10-40。当重新采样每个X时( t)(这是以下代码所做的),平均值非常精确。正如所指出的,差异是可怕的。这可能不是一个好的解决方案,但我认为它一样好。

# sample size.
size = 1000
t = 10
# ts is a vector of sample values for X(10).
ts = sapply(1:size, function(i) comp.pois(t, lambda)[t])

# sample mean and variance:
(mean.s = mean(ts))
(var.s = var(ts))

# theoretical mean and variance:
(mean.t = lambda * t * shape * scale)
(var.t = (shape + 1) * shape * scale^2)
在这种情况下

输出(t = 10):

> # sample:
> (mean.s = mean(ts))
[1] 63.38403

> (var.s = var(ts))
[1] 184.3264

> # theoretical:
> (mean.t = lambda * t * shape * scale)
[1] 75

> (var.t = (shape + 1) * shape * scale^2)
[1] 63.75

0 个答案:

没有答案