绘制伽玛概率密度函数

Plotting gamma probability density function

我正在尝试绘制 R 中的伽玛概率密度函数,其中 y∈(0,10) for (k = 1,μ = 1), (k = 2, μ = 1), (k = 2, μ = 2).在 R 中,

在 R 中,pgamma 函数接受:

pgamma(q, shape, rate = 1, scale = 1/rate, alpha = shape, beta = scale, lower.tail = TRUE, log.p = FALSE)

在 R 中,我试过:

pgamma(1,1,rate=1,scale = 1/rate, alpha = shape, beta = scale, lower.tail = True, log.p = False)

但是我收到消息

Error in pgamma(1, 1, rate = 1, scale = 1/rate, lower.tail = TRUE, log.p = FALSE) : 
object 'rate' not found

这是我第一次绘制 gamma 分布,希望能提供一些帮助。

下面使用基本 R 图形绘制了三个密度。

首先,你想要的参数值。我假设您的 mu 是在 Wikipedia page of the Gamma distribution.

中定义的
k <- c(1, 2, 2)
mu <- c(1, 1, 2)
theta <- mu/k

现在,情节。

plot(0, 0, xlim = c(0, 10), ylim = c(0, 1), type = "n")
for(i in seq_along(k))
  curve(dgamma(x, shape = k[i], scale = theta[i]), from = 0, to = 10, col = i, add = TRUE)