代码之家  ›  专栏  ›  技术社区  ›  Maxxx

绘制伽马概率密度函数

  •  0
  • Maxxx  · 技术社区  · 6 年前

    我试图用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
    

    这是我第一次绘制伽马分布图,希望能得到一些帮助。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Rui Barradas    6 年前

    下面用R基图形绘制三种密度。

    首先,您需要的参数值。我假设您的 mu是在gamma分发的 wikipedia页面中定义的。

    k<-c(1,2,2)
    MU<-C(1、1、2)
    Theta<-亩/克
    < /代码> 
    
    

    现在,绘图。

    plot(0,0,xlim=c(0,10),ylim=c(0,1),type=“n”)
    用于(i in seq_along(k))。
    曲线(dgamma(x,shape=k[i],scale=theta[i]),从=0到=10,col=i,add=true)
    < /代码> 
    
    

    定义在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)
    

    enter image description here