我试图在R中绘制伽马概率密度函数,其中y∈(0,10)为(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
这是我第一次绘制伽玛分布,并希望得到一些帮助。
下面使用基础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)