我正在尝试绘制R中的伽马概率密度函数,其中对于(k = 1,μ= 1),(k = 2,μ= 1),(k = 2,y∈(0,10) μ= 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
这是我第一次绘制伽玛分布图,希望对此有所帮助。
答案 0 :(得分:1)
以下使用基本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)