1

I am simulating some gamma random numbers

plot(density(rgamma(10000,8.1,rate=0.00510)),lwd=2,las=1,cex.axis=0.75,
main=expression(paste("Gamma Distribution with",' scale ',alpha," and  rate 
",beta)))

plot(density(rgamma(10000,2.1,rate=0.00110)),lwd=2,las=1,cex.axis=0.75,
 main=expression(paste("Gamma Distribution with",' scale ',alpha," and  rate 
",beta)))


plot(density(rgamma(10000,2.1,rate=110)),lwd=2,las=1,cex.axis=0.75,
 main=expression(paste("Gamma Distribution with",' scale ',alpha," and  rate 
",beta)))

The first plot

The second plot

enter image description here

I need to simulate this kind of gamma with some tail, the mean around 1200. I have been selecting random numbers in order to get that values considering the definition of expectation and variance for gamma distribution, but in the first case I get negative numbers, I don't want that. In the second case the same but also in both plots the probability in the y axis is so low, I would like to increase this probability but I don't know how to select the adequate parameters to get that.

On the other hand the parameters given in the third plot gives a density strange, because the probability in the y axis is greater than one I can get values greater than 1. I don't understand this.

4

1 回答 1

2

在第一种情况下,您没有得到负数。

sum(rgamma(10000,8.1,rate=0.00510)<0)

# [1] 0

至于密度超过1,那也没什么不好。曲线下的面积应该正好是 1。

为了绘制分布,您也可以使用dgamma而不是rgamma 像这样:

x <- seq(0,.12, length = 10000)
y <- dgamma(x,2.1,rate=110)
plot(x,y, type = "l")

在此处输入图像描述

这是使用ggplot2.

ggplot(data.frame(x,y), aes(x,y)) + 
  geom_line()

在此处输入图像描述

于 2018-03-10T12:11:53.290 回答