问题
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