【问题标题】:error of ploting pdf, cdf and quantile functions of truncated gamma distribution in R在 R 中绘制截断伽马分布的 pdf、cdf 和分位数函数的误差
【发布时间】:2014-04-18 19:00:40
【问题描述】:

在论坛搜索后,我没有找到类似的问题。如果我错过了,请告诉我。我真的很感激。

我需要为 R 中的任何给定形状和比例值绘制截断伽马的 pdf 、 cdf 和分位数函数。但是,我得到了一些形状和比例值的错误。

我的代码:

 library(distr) 
 library(distrEx) 
 library(truncdist)
 scale8 <- 750000
 shape8 <- 0.0016     
 G0 <- Gammad(scale = scale8, shape = shape8) 
 plot(G0)
 TG <- Truncate(G0, lower=0, upper=1000000) #  Error in if (.isEqual(gaps[jj, 2], gaps[j + 1,   
                                            #  1])) gaps[jj, 2] <- gaps[j +  : 
                                            #    missing value where TRUE/FALSE needed

 plot(TG) 

我的理解是,对于某些 gamma pdf,其截断的 gamma 分布不存在?

任何帮助将不胜感激!

【问题讨论】:

    标签: r distribution probability probability-density gamma-distribution


    【解决方案1】:

    像这样??

    scale8 <- 750000
    shape8 <- 0.0016 
    library(truncdist)
    par(mfrow=c(1,3))
    q <- seq(0,100,1)
    p <- seq(0,1,.01)
    plot(q,dtrunc(q,"gamma",a=20,b=50,scale=scale8,shape=shape8),type="l",main="PDF")
    plot(q,ptrunc(q,"gamma",a=20,b=50,scale=scale8,shape=shape8),type="l",main="CDF")
    plot(p,qtrunc(p,"gamma",a=20,b=50,scale=scale8,shape=shape8),type="l",main="Quantile")
    

    将下限和上限设置为 [0,1000000] 几乎不会截断,因此我为了示例而对其进行了更改。

    编辑(回应 OP 的评论)

    在对dtrunc(...)ptrunc(...)qtrunc(...) 的调用中,使用a=...b=... 设置截断范围的下限和上限。在本例中,它设置为 [20,50]。

    【讨论】:

    • 欣赏您的工作。但是,如果截断范围必须是 [0,1000000] 或 simlair [10000, 990000] 怎么办?谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    • 2021-12-23
    相关资源
    最近更新 更多