简体   繁体   English

绘制伽玛概率密度函数

[英]Plotting gamma probability density function

I'm trying to plot the gamma probability density function in R where y∈(0,10) for (k = 1,μ = 1), (k = 2, μ = 1), (k = 2, μ = 2). 我正在尝试绘制R中的伽马概率密度函数,其中对于(k = 1,μ= 1),(k = 2,μ= 1),(k = 2,μ= 2,y∈(0,10) )。 In R, 在R中

In R, the pgamma function accepts: 在R中,pgamma函数接受:

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

In R, i tried: 在R中,我尝试过:

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

But i get the message 但是我得到消息

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

It's my first time plotting a gamma distribution and would appreciate some help on this. 这是我第一次绘制伽马分布,并希望对此有所帮助。

The following plots the three densities using base R graphics. 下图使用基本R图形绘制了三种密度。

First, the parameter values you want. 首先,需要的参数值。 I am assuming your mu is as defined in the Wikipedia page of the Gamma distribution . 我假设您的muGamma发行版Wikipedia页面中定义的。

k <- c(1, 2, 2)
mu <- c(1, 1, 2)
theta <- mu/k

Now, the plots. 现在,情节。

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)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM