1

I'm trying to draw samples from Gamma distribution but I'm considering the 'scale' argument of rgamma as a vector because each sample unit has different scale parameters. I'd like to know what is the rule of this function to choose the values of the argument. For example, if I run this:

rgamma(10,shape=1,scale=1:10)

Is it generating rgamma(1,shape=1, scale=10),$\ldots$,rgamma(1,shape=1, scale=10)? Besides that, what if I run this:

rgamma(1,shape=1,scale=1:10)
rgamma(2,shape=1,scale=1:10)
rgamma(11,shape=1,scale=1:3)

Which scale parameter is it choosing for each draw? Could someone help me? Thanks

plb
  • 43
  • 1
  • 7
  • @Pedro: Use `sapply`: `sapply(1:10, FUN=rgamma, shape=1, n=10)`. In this case, `1:10` are the scale values and the shape is 1 and $n$ is 10. This produces a 10x10 matrix with each column corresponding to one `scale` value. – COOLSerdash Jun 12 '13 at 15:07

1 Answers1

2

R has built-in vectorization. What this means for your first questions is that rgamma(10, shape=1, scale=c(1:10)) will generate 10 values, one for each scale parameter.

When the number of rgamma calls is not the same as the length of the vector, like in rgamma(11, shape=1, scale=c(1:3)), R will recycle the scale values in order until it has 11 scale values of the form c(1,2,3,1,2,3,1,2,3,1,2).

Sycorax
  • 1,298
  • 13
  • 26