How can I estimate the shape and scale of a gamma dist. with a particular mean and a 95% quantile?

倾然丶 夕夏残阳落幕 提交于 2019-12-23 12:26:50

问题


Is there any way, in R, to calculate the scale and shape of a gamma distribution, given a particular value of mean (or median) and a particular quantile (the 95% quantile)?

So for example I have a mean = 130

and a 95% quantile = 300

with an offset of the distribution at 80

is there any way to obtain the scale and shape of a gamma that meet these criteria?


回答1:


Here is one approach:

myfun <- function(shape) {
    scale <- 130/shape
    pgamma(300, shape, scale=scale) - 0.95
}

tmp <- uniroot( myfun, lower=2, upper=10 )

myshape <- tmp$root
myscale <- 130/tmp$root

qgamma(0.95, shape=myshape, scale=myscale)
integrate( function(x) x*dgamma(x,shape=myshape,scale=myscale), 
    lower=0, upper=Inf )

I am not sure what you mean by offset of 80, if that is just where the gamma becomes non-zero then subtract 80 from 130 and 300 and do the same as above.



来源:https://stackoverflow.com/questions/14266354/how-can-i-estimate-the-shape-and-scale-of-a-gamma-dist-with-a-particular-mean-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!