2

This may be a very stupid question but Does anyone know why i am not getting the second bit equals to the mean (100)?

#beta=4, alpha=5, mean=20
qgamma(0.5, 5, 1/4)
# 18.68364

#beta=2500, alpha=0.04, mean=100
qgamma(0.5,0.04,1/2500)
# 0.00004320412
Melissa Key
  • 4,476
  • 12
  • 21
syys
  • 63
  • 7

1 Answers1

1

It is because you are using the quantile function, and qgamma(0.5, shape, scale) corresponds to the median - not the mean as you are expecting.

See the example below;

x <- rgamma(50000, shape = 0.04, scale = 2500)
mean(x)
# [1] 98.82911

median(x)
# [1] 3.700012e-05 
kangaroo_cliff
  • 6,067
  • 3
  • 29
  • 42
  • Do you know how can i use the gamma distribution with the same parameter (alpha=0.04, beta=2500) to - generate a 10k sims - duplicate the sims n times (randomly reorder each simulation without repeating) ? thanks in advance :) – syys May 17 '18 at 21:45
  • @yang you can use this `matrix(rgamma(n * k, shape = 0.04, scale = 2500), nrow = k, ncol = n)`. Since one draw from the `rgamma` is independent from the other, you can simply generate all at once and then put them in a matrix. – kangaroo_cliff May 17 '18 at 23:18